samples: net: Remove net-app based sample applications
As net-app API is removed, remove also all the sample applications that use it. Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This commit is contained in:
parent
2ece89f523
commit
48abdc2cb9
|
@ -7,7 +7,6 @@ CONFIG_TEST_RANDOM_GENERATOR=y
|
|||
CONFIG_COAP=y
|
||||
CONFIG_COAP_NET_PKT=y
|
||||
|
||||
CONFIG_NET_APP_CLIENT=y
|
||||
CONFIG_NET_CONFIG_SETTINGS=y
|
||||
CONFIG_NET_CONFIG_NEED_IPV6=y
|
||||
CONFIG_NET_CONFIG_MY_IPV6_ADDR="2001:db8::2"
|
||||
|
|
|
@ -6,7 +6,6 @@ CONFIG_TEST_RANDOM_GENERATOR=y
|
|||
CONFIG_COAP=y
|
||||
CONFIG_COAP_NET_PKT=y
|
||||
|
||||
CONFIG_NET_APP_SERVER=y
|
||||
CONFIG_NET_CONFIG_SETTINGS=y
|
||||
CONFIG_NET_CONFIG_NEED_IPV6=y
|
||||
CONFIG_NET_CONFIG_MY_IPV6_ADDR="2001:db8::1"
|
||||
|
|
|
@ -1,22 +0,0 @@
|
|||
cmake_minimum_required(VERSION 3.13.1)
|
||||
|
||||
macro(set_conf_file)
|
||||
if(EXISTS ${APPLICATION_SOURCE_DIR}/prj_${BOARD}.conf)
|
||||
set(CONF_FILE "${APPLICATION_SOURCE_DIR}/prj_${BOARD}.conf")
|
||||
elseif(EXISTS ${APPLICATION_SOURCE_DIR}/boards/${BOARD}.conf)
|
||||
set(CONF_FILE
|
||||
"prj.conf ${APPLICATION_SOURCE_DIR}/boards/${BOARD}.conf")
|
||||
else()
|
||||
set(CONF_FILE "prj.conf")
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
|
||||
project(echo_client)
|
||||
|
||||
target_sources( app PRIVATE src/echo-client.c)
|
||||
target_sources_ifdef(CONFIG_NET_UDP app PRIVATE src/udp.c)
|
||||
target_sources_ifdef(CONFIG_NET_TCP app PRIVATE src/tcp.c)
|
||||
target_sources_ifdef(CONFIG_NET_VLAN app PRIVATE src/vlan.c)
|
||||
|
||||
include($ENV{ZEPHYR_BASE}/samples/net/common/common.cmake)
|
|
@ -1,49 +0,0 @@
|
|||
# Kconfig - Private config options for echo-client sample app
|
||||
|
||||
#
|
||||
# Copyright (c) 2018 Intel Corporation
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
|
||||
mainmenu "Networking echo-client sample application"
|
||||
|
||||
config NET_SAMPLE_IFACE2_MY_IPV6_ADDR
|
||||
string "My IPv6 address for second interface"
|
||||
help
|
||||
The value depends on your network setup.
|
||||
|
||||
config NET_SAMPLE_IFACE2_MY_IPV4_ADDR
|
||||
string "My IPv4 address for second interface"
|
||||
help
|
||||
The value depends on your network setup.
|
||||
|
||||
config NET_SAMPLE_IFACE2_VLAN_TAG
|
||||
int "VLAN tag for second interface"
|
||||
default 100
|
||||
range 0 4094
|
||||
depends on NET_VLAN
|
||||
help
|
||||
Set VLAN (virtual LAN) tag (id) that is used in the sample
|
||||
application.
|
||||
|
||||
config NET_SAMPLE_IFACE3_MY_IPV6_ADDR
|
||||
string "My IPv6 address for third interface"
|
||||
help
|
||||
The value depends on your network setup.
|
||||
|
||||
config NET_SAMPLE_IFACE3_MY_IPV4_ADDR
|
||||
string "My IPv4 address for third interface"
|
||||
help
|
||||
The value depends on your network setup.
|
||||
|
||||
config NET_SAMPLE_IFACE3_VLAN_TAG
|
||||
int "VLAN tag for third interface"
|
||||
default 200
|
||||
range 0 4094
|
||||
depends on NET_VLAN
|
||||
help
|
||||
Set VLAN (virtual LAN) tag (id) that is used in the sample
|
||||
application.
|
||||
|
||||
source "Kconfig.zephyr"
|
|
@ -1,106 +0,0 @@
|
|||
.. _echo-client-sample:
|
||||
|
||||
Echo Client
|
||||
###########
|
||||
|
||||
Overview
|
||||
********
|
||||
|
||||
The echo-client sample application for Zephyr implements a UDP/TCP client
|
||||
that will send IPv4 or IPv6 packets, wait for the data to be sent back,
|
||||
and then verify it matches the data that was sent.
|
||||
|
||||
The source code for this sample application can be found at:
|
||||
:file:`samples/net/echo_client`.
|
||||
|
||||
Requirements
|
||||
************
|
||||
|
||||
- :ref:`networking_with_qemu`
|
||||
|
||||
Building and Running
|
||||
********************
|
||||
|
||||
There are multiple ways to use this application. One of the most common
|
||||
usage scenario is to run echo-client application inside QEMU. This is
|
||||
described in :ref:`networking_with_qemu`.
|
||||
|
||||
There are configuration files for different boards and setups in the
|
||||
echo-client directory:
|
||||
|
||||
- :file:`prj.conf`
|
||||
Generic config file, normally you should use this.
|
||||
|
||||
- :file:`overlay-frdm_k64f_mcr20a.conf`
|
||||
This overlay config enables support for IEEE 802.15.4 mcr20a and frdm_k64f
|
||||
|
||||
- :file:`overlay-ot.conf`
|
||||
This overlay config enables support for OpenThread.
|
||||
|
||||
- :file:`overlay-802154.conf`
|
||||
This overlay config enables support for native IEEE 802.15.4 connectivity.
|
||||
Note, that by default IEEE 802.15.4 L2 uses unacknowledged communication. To
|
||||
improve connection reliability, acknowledgments can be enabled with shell
|
||||
command: ``ieee802154 ack set``.
|
||||
|
||||
- :file:`overlay-enc28j60.conf`
|
||||
This overlay config enables support for enc28j60 ethernet board. This
|
||||
add-on board can be used for example with Arduino 101 board.
|
||||
|
||||
- :file:`overlay-cc2520.conf`
|
||||
This overlay config enables support for IEEE 802.15.4 cc2520 chip.
|
||||
|
||||
- :file:`overlay-bt.conf`
|
||||
This overlay config enables support for Bluetooth IPSP connectivity.
|
||||
|
||||
- :file:`overlay-qemu_802154.conf`
|
||||
This overlay config enables support for two QEMU's when simulating
|
||||
IEEE 802.15.4 network that are connected together.
|
||||
|
||||
- :file:`overlay-tls.conf`
|
||||
This overlay config enables support for TLS.
|
||||
|
||||
Build echo-client sample application like this:
|
||||
|
||||
.. zephyr-app-commands::
|
||||
:zephyr-app: samples/net/echo_client
|
||||
:board: <board to use>
|
||||
:conf: <config file to use>
|
||||
:goals: build
|
||||
:compact:
|
||||
|
||||
Example building for the FRDM-K64F with TI CC2520 support:
|
||||
|
||||
.. zephyr-app-commands::
|
||||
:zephyr-app: samples/net/echo_client
|
||||
:host-os: unix
|
||||
:board: frdm_k64f
|
||||
:conf: "prj.conf overlay-frdm_k64f_cc2520.conf"
|
||||
:goals: run
|
||||
:compact:
|
||||
|
||||
Cmake can select the default configuration file based on the BOARD you've
|
||||
specified automatically so you might not always need to mention it.
|
||||
|
||||
Running echo-server in Linux Host
|
||||
=================================
|
||||
|
||||
There is one useful testing scenario that can be used with Linux host.
|
||||
Here echo-client is run in QEMU and echo-server is run in Linux host.
|
||||
|
||||
To use QEMU for testing, follow the :ref:`networking_with_qemu` guide.
|
||||
|
||||
In a terminal window:
|
||||
|
||||
.. code-block:: console
|
||||
|
||||
$ sudo ./echo-server -i tap0
|
||||
|
||||
Run echo-client application in QEMU:
|
||||
|
||||
.. zephyr-app-commands::
|
||||
:zephyr-app: samples/net/echo_client
|
||||
:host-os: unix
|
||||
:board: qemu_x86
|
||||
:goals: run
|
||||
:compact:
|
|
@ -1,21 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2019 Linaro Limited
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
&spi1 {
|
||||
status = "ok";
|
||||
cs-gpios = <&gpio0 0 0>;
|
||||
|
||||
enc28j60@0 {
|
||||
compatible = "microchip,enc28j60";
|
||||
spi-port-name = "SPI_1";
|
||||
local-mac-address = [00 00 00 00 00 00];
|
||||
spi-max-frequency = <128000>;
|
||||
int-gpios = <&gpio0 19 1>;
|
||||
status = "ok";
|
||||
label = "ETH_0";
|
||||
reg = <0>;
|
||||
};
|
||||
};
|
|
@ -1,24 +0,0 @@
|
|||
CONFIG_NET_TCP=n
|
||||
CONFIG_NET_IPV4=n
|
||||
CONFIG_NET_CONFIG_NEED_IPV4=n
|
||||
CONFIG_NET_6LO=y
|
||||
|
||||
CONFIG_NET_L2_IEEE802154=y
|
||||
CONFIG_NET_L2_IEEE802154_FRAGMENT=y
|
||||
CONFIG_NET_L2_IEEE802154_FRAGMENT_REASS_CACHE_SIZE=4
|
||||
|
||||
# For Wireshark filtering in a busy environment it is useful to set a unique
|
||||
# PAN ID
|
||||
#CONFIG_NET_CONFIG_IEEE802154_PAN_ID=0xbeef
|
||||
|
||||
CONFIG_NET_L2_IEEE802154_SECURITY=n
|
||||
CONFIG_NET_L2_IEEE802154_SHELL=y
|
||||
|
||||
CONFIG_IEEE802154_KW41Z=y
|
||||
|
||||
CONFIG_NET_CONFIG_IEEE802154_DEV_NAME="KW41Z"
|
||||
|
||||
CONFIG_FLASH=y
|
||||
CONFIG_FLASH_PAGE_LAYOUT=y
|
||||
CONFIG_CPLUSPLUS=y
|
||||
CONFIG_REBOOT=y
|
|
@ -1,7 +0,0 @@
|
|||
# The addresses are selected so that qemu<->qemu connectivity works ok.
|
||||
# For linux<->qemu connectivity, create a new conf file and swap the
|
||||
# addresses (so that peer address is ending to 2).
|
||||
CONFIG_NET_CONFIG_MY_IPV6_ADDR="2001:db8::2"
|
||||
CONFIG_NET_CONFIG_PEER_IPV6_ADDR="2001:db8::1"
|
||||
CONFIG_NET_CONFIG_MY_IPV4_ADDR="192.0.2.2"
|
||||
CONFIG_NET_CONFIG_PEER_IPV4_ADDR="192.0.2.1"
|
|
@ -1,7 +0,0 @@
|
|||
# The addresses are selected so that qemu<->qemu connectivity works ok.
|
||||
# For linux<->qemu connectivity, create a new conf file and swap the
|
||||
# addresses (so that peer address is ending to 2).
|
||||
CONFIG_NET_CONFIG_MY_IPV6_ADDR="2001:db8::2"
|
||||
CONFIG_NET_CONFIG_PEER_IPV6_ADDR="2001:db8::1"
|
||||
CONFIG_NET_CONFIG_MY_IPV4_ADDR="192.0.2.2"
|
||||
CONFIG_NET_CONFIG_PEER_IPV4_ADDR="192.0.2.1"
|
|
@ -1,18 +0,0 @@
|
|||
CONFIG_BT=n
|
||||
|
||||
# Disable TCP and IPv4 (TCP disabled to avoid heavy traffic)
|
||||
CONFIG_NET_TCP=n
|
||||
CONFIG_NET_IPV4=n
|
||||
|
||||
CONFIG_NET_CONFIG_NEED_IPV6=y
|
||||
CONFIG_NET_CONFIG_NEED_IPV4=n
|
||||
CONFIG_NET_CONFIG_MY_IPV4_ADDR=""
|
||||
CONFIG_NET_CONFIG_PEER_IPV4_ADDR=""
|
||||
CONFIG_NET_CONFIG_MY_IPV6_ADDR="2001:db8::2"
|
||||
CONFIG_NET_CONFIG_PEER_IPV6_ADDR="2001:db8::1"
|
||||
|
||||
CONFIG_NET_L2_IEEE802154=y
|
||||
CONFIG_NET_L2_IEEE802154_SHELL=y
|
||||
CONFIG_NET_L2_IEEE802154_LOG_LEVEL_INF=y
|
||||
|
||||
CONFIG_NET_CONFIG_IEEE802154_CHANNEL=26
|
|
@ -1,14 +0,0 @@
|
|||
CONFIG_BT=y
|
||||
CONFIG_BT_DEVICE_NAME="Zephyr Echo Client"
|
||||
CONFIG_BT_DEBUG_LOG=y
|
||||
CONFIG_BT_DEBUG_L2CAP=y
|
||||
CONFIG_BT_SMP=y
|
||||
CONFIG_BT_SIGNING=y
|
||||
CONFIG_BT_PERIPHERAL=y
|
||||
CONFIG_BT_L2CAP_DYNAMIC_CHANNEL=y
|
||||
CONFIG_NET_L2_BT=y
|
||||
CONFIG_NET_L2_BT_SHELL=y
|
||||
CONFIG_NET_IPV4=n
|
||||
CONFIG_NET_CONFIG_NEED_IPV4=n
|
||||
CONFIG_NET_CONFIG_MY_IPV4_ADDR=""
|
||||
CONFIG_NET_CONFIG_PEER_IPV4_ADDR=""
|
|
@ -1,11 +0,0 @@
|
|||
CONFIG_NET_L2_IEEE802154=y
|
||||
|
||||
CONFIG_IEEE802154_CC2520=y
|
||||
CONFIG_IEEE802154_CC2520_AUTO_ACK=y
|
||||
|
||||
CONFIG_NET_CONFIG_IEEE802154_DEV_NAME="cc2520"
|
||||
|
||||
CONFIG_NET_IPV4=n
|
||||
CONFIG_NET_CONFIG_NEED_IPV4=n
|
||||
CONFIG_NET_CONFIG_MY_IPV4_ADDR=""
|
||||
CONFIG_NET_CONFIG_PEER_IPV4_ADDR=""
|
|
@ -1,7 +0,0 @@
|
|||
# ENC28J60 is L2 chip slave on SPI
|
||||
CONFIG_SPI=y
|
||||
CONFIG_NET_L2_ETHERNET=y
|
||||
|
||||
# ENC28J60 Ethernet Device
|
||||
CONFIG_ETH_ENC28J60=y
|
||||
CONFIG_ETH_ENC28J60_0=y
|
|
@ -1,12 +0,0 @@
|
|||
CONFIG_NET_L2_IEEE802154=y
|
||||
|
||||
CONFIG_GPIO=y
|
||||
CONFIG_SPI=y
|
||||
CONFIG_SPI_0=y
|
||||
|
||||
CONFIG_IEEE802154_MCR20A=y
|
||||
|
||||
CONFIG_NET_IPV4=n
|
||||
CONFIG_NET_CONFIG_NEED_IPV4=n
|
||||
CONFIG_NET_CONFIG_MY_IPV4_ADDR=""
|
||||
CONFIG_NET_CONFIG_PEER_IPV4_ADDR=""
|
|
@ -1,46 +0,0 @@
|
|||
CONFIG_CPLUSPLUS=y
|
||||
|
||||
CONFIG_BT=n
|
||||
|
||||
# Disable TCP and IPv4 (TCP disabled to avoid heavy traffic)
|
||||
CONFIG_NET_TCP=n
|
||||
CONFIG_NET_IPV4=n
|
||||
|
||||
CONFIG_NET_IPV6_NBR_CACHE=n
|
||||
CONFIG_NET_IPV6_MLD=n
|
||||
CONFIG_NET_CONFIG_NEED_IPV6=y
|
||||
CONFIG_NET_CONFIG_NEED_IPV4=n
|
||||
CONFIG_NET_CONFIG_MY_IPV4_ADDR=""
|
||||
CONFIG_NET_CONFIG_PEER_IPV4_ADDR=""
|
||||
|
||||
CONFIG_MAIN_STACK_SIZE=2048
|
||||
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048
|
||||
CONFIG_NET_TX_STACK_SIZE=2048
|
||||
CONFIG_NET_RX_STACK_SIZE=5120
|
||||
CONFIG_SHELL_STACK_SIZE=3072
|
||||
|
||||
# Disable conflicting IEEE802154 L2
|
||||
CONFIG_NET_L2_IEEE802154=n
|
||||
CONFIG_NET_L2_IEEE802154_SHELL=n
|
||||
|
||||
CONFIG_NET_L2_OPENTHREAD=y
|
||||
|
||||
CONFIG_OPENTHREAD_DEBUG=y
|
||||
CONFIG_OPENTHREAD_L2_DEBUG=y
|
||||
CONFIG_OPENTHREAD_L2_LOG_LEVEL_INF=y
|
||||
|
||||
CONFIG_OPENTHREAD_CHANNEL=26
|
||||
|
||||
CONFIG_NET_CONFIG_MY_IPV6_ADDR="fdde:ad00:beef::1"
|
||||
CONFIG_NET_CONFIG_PEER_IPV6_ADDR="fdde:ad00:beef::2"
|
||||
|
||||
# Thread by default registers quite a lot addresses.
|
||||
CONFIG_NET_IF_UNICAST_IPV6_ADDR_COUNT=6
|
||||
CONFIG_NET_IF_MCAST_IPV6_ADDR_COUNT=8
|
||||
|
||||
# Other OpenThread dependencies (flash for OT persistent storage)
|
||||
CONFIG_FLASH=y
|
||||
CONFIG_FLASH_PAGE_LAYOUT=y
|
||||
CONFIG_MPU_ALLOW_FLASH_WRITE=y
|
||||
|
||||
CONFIG_REBOOT=y
|
|
@ -1,19 +0,0 @@
|
|||
CONFIG_NET_IPV4=n
|
||||
CONFIG_NET_CONFIG_NEED_IPV4=n
|
||||
CONFIG_NET_CONFIG_MY_IPV4_ADDR=""
|
||||
CONFIG_NET_CONFIG_PEER_IPV4_ADDR=""
|
||||
|
||||
CONFIG_NET_L2_IEEE802154=y
|
||||
|
||||
CONFIG_IEEE802154_UPIPE=y
|
||||
CONFIG_NET_DEBUG_L2_IEEE802154_DISPLAY_PACKET=n
|
||||
|
||||
CONFIG_NET_L2_IEEE802154_SHELL=y
|
||||
|
||||
# This prevents automatic creation of ethernet interface as we
|
||||
# do not have SLIP in use in this test.
|
||||
CONFIG_NET_TEST=y
|
||||
|
||||
# This sample uses more stack so update the values
|
||||
CONFIG_MAIN_STACK_SIZE=2000
|
||||
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2000
|
|
@ -1,11 +0,0 @@
|
|||
# Select Stellaris Ethernet
|
||||
CONFIG_NET_SLIP_TAP=n
|
||||
CONFIG_SLIP=n
|
||||
CONFIG_NET_L2_ETHERNET=y
|
||||
CONFIG_ETH_STELLARIS=y
|
||||
|
||||
# Network Application Options
|
||||
CONFIG_NET_CONFIG_MY_IPV6_ADDR="2001:db8::2"
|
||||
CONFIG_NET_CONFIG_PEER_IPV6_ADDR="2001:db8::1"
|
||||
CONFIG_NET_CONFIG_MY_IPV4_ADDR="192.0.2.2"
|
||||
CONFIG_NET_CONFIG_PEER_IPV4_ADDR="192.0.2.1"
|
|
@ -1,4 +0,0 @@
|
|||
CONFIG_MBEDTLS=y
|
||||
CONFIG_MBEDTLS_BUILTIN=y
|
||||
CONFIG_MBEDTLS_ENABLE_HEAP=y
|
||||
CONFIG_MBEDTLS_HEAP_SIZE=30000
|
|
@ -1,26 +0,0 @@
|
|||
CONFIG_NET_VLAN=y
|
||||
|
||||
# We have one non-vlan interface and two VLAN interfaces
|
||||
CONFIG_NET_VLAN_COUNT=3
|
||||
|
||||
# There will be three network interfaces.
|
||||
|
||||
# First ethernet interface will use these settings
|
||||
CONFIG_NET_CONFIG_MY_IPV6_ADDR="2001:db8::1"
|
||||
CONFIG_NET_CONFIG_PEER_IPV6_ADDR="2001:db8::2"
|
||||
CONFIG_NET_CONFIG_MY_IPV4_ADDR="192.0.2.1"
|
||||
CONFIG_NET_CONFIG_PEER_IPV4_ADDR="192.0.2.2"
|
||||
|
||||
# Second ethernet interface will have these settings
|
||||
CONFIG_NET_SAMPLE_IFACE2_MY_IPV6_ADDR="2001:db8:100::1"
|
||||
# TEST-NET-2 from RFC 5737
|
||||
CONFIG_NET_SAMPLE_IFACE2_MY_IPV4_ADDR="198.51.100.1"
|
||||
# VLAN tag for the second interface
|
||||
CONFIG_NET_SAMPLE_IFACE2_VLAN_TAG=100
|
||||
|
||||
# Settings for the third network interface
|
||||
CONFIG_NET_SAMPLE_IFACE3_MY_IPV6_ADDR="2001:db8:200::1"
|
||||
# TEST-NET-3 from RFC 5737
|
||||
CONFIG_NET_SAMPLE_IFACE3_MY_IPV4_ADDR="203.0.113.1"
|
||||
# VLAN tag for the second interface
|
||||
CONFIG_NET_SAMPLE_IFACE3_VLAN_TAG=200
|
|
@ -1,31 +0,0 @@
|
|||
CONFIG_MAIN_STACK_SIZE=2048
|
||||
CONFIG_NETWORKING=y
|
||||
CONFIG_NET_IPV6=y
|
||||
CONFIG_NET_IPV4=y
|
||||
CONFIG_NET_UDP=y
|
||||
CONFIG_NET_TCP=y
|
||||
CONFIG_TEST_RANDOM_GENERATOR=y
|
||||
CONFIG_NET_LOG=y
|
||||
CONFIG_INIT_STACKS=y
|
||||
CONFIG_PRINTK=y
|
||||
CONFIG_NET_STATISTICS=y
|
||||
CONFIG_NET_PKT_RX_COUNT=50
|
||||
CONFIG_NET_PKT_TX_COUNT=50
|
||||
CONFIG_NET_BUF_RX_COUNT=50
|
||||
CONFIG_NET_BUF_TX_COUNT=50
|
||||
CONFIG_NET_IF_UNICAST_IPV6_ADDR_COUNT=3
|
||||
CONFIG_NET_IF_MCAST_IPV6_ADDR_COUNT=2
|
||||
CONFIG_NET_MAX_CONTEXTS=10
|
||||
|
||||
CONFIG_NET_SHELL=y
|
||||
|
||||
CONFIG_NET_APP=y
|
||||
CONFIG_NET_APP_CLIENT=y
|
||||
|
||||
CONFIG_NET_CONFIG_SETTINGS=y
|
||||
CONFIG_NET_CONFIG_NEED_IPV6=y
|
||||
CONFIG_NET_CONFIG_NEED_IPV4=y
|
||||
CONFIG_NET_CONFIG_MY_IPV6_ADDR="2001:db8::1"
|
||||
CONFIG_NET_CONFIG_PEER_IPV6_ADDR="2001:db8::2"
|
||||
CONFIG_NET_CONFIG_MY_IPV4_ADDR="192.0.2.1"
|
||||
CONFIG_NET_CONFIG_PEER_IPV4_ADDR="192.0.2.2"
|
|
@ -1,35 +0,0 @@
|
|||
common:
|
||||
harness: net
|
||||
tags: net
|
||||
sample:
|
||||
description: Test core network features using a client/server
|
||||
sample
|
||||
name: Echo Client
|
||||
tests:
|
||||
test:
|
||||
platform_whitelist: qemu_x86 frdm_k64f sam_e70_xplained
|
||||
qemu_cortex_m3 frdm_kw41z
|
||||
test_802154:
|
||||
extra_args: OVERLAY_CONFIG="overlay-qemu_802154.conf"
|
||||
platform_whitelist: qemu_x86
|
||||
test_bt:
|
||||
extra_args: OVERLAY_CONFIG="overlay-bt.conf"
|
||||
platform_whitelist: qemu_x86
|
||||
tags: bluetooth
|
||||
test_nrf_802154:
|
||||
extra_args: OVERLAY_CONFIG="overlay-802154.conf"
|
||||
platform_whitelist: nrf52840_pca10056
|
||||
test_nrf_openthread:
|
||||
extra_args: OVERLAY_CONFIG="overlay-ot.conf"
|
||||
slow: true
|
||||
tags: net openthread
|
||||
platform_whitelist: nrf52840_pca10056
|
||||
test_kw41z_openthread:
|
||||
extra_args: OVERLAY_CONFIG="overlay-ot.conf"
|
||||
slow: true
|
||||
tags: net openthread
|
||||
platform_whitelist: frdm_kw41z
|
||||
test_enc28j60:
|
||||
extra_args: OVERLAY_CONFIG="overlay-enc28j60.conf"
|
||||
tags: net enc28j60
|
||||
platform_whitelist: arduino_101
|
|
@ -1,62 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2017 Intel Corporation.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/* Value of 0 will cause the IP stack to select next free port */
|
||||
#define MY_PORT 0
|
||||
|
||||
#define PEER_PORT 4242
|
||||
|
||||
#define WAIT_TIME K_SECONDS(10)
|
||||
#define CONNECT_TIME K_SECONDS(10)
|
||||
|
||||
struct data {
|
||||
/* Work controlling udp data sending */
|
||||
struct k_delayed_work recv;
|
||||
struct net_app_ctx *udp;
|
||||
|
||||
const char *proto;
|
||||
u32_t expecting_udp;
|
||||
u32_t expecting_tcp;
|
||||
u32_t received_tcp;
|
||||
};
|
||||
|
||||
struct configs {
|
||||
struct data ipv4;
|
||||
struct data ipv6;
|
||||
};
|
||||
|
||||
#if !defined(CONFIG_NET_CONFIG_PEER_IPV4_ADDR)
|
||||
#define CONFIG_NET_CONFIG_PEER_IPV4_ADDR ""
|
||||
#endif
|
||||
|
||||
#if !defined(CONFIG_NET_CONFIG_PEER_IPV6_ADDR)
|
||||
#define CONFIG_NET_CONFIG_PEER_IPV6_ADDR ""
|
||||
#endif
|
||||
|
||||
extern const char lorem_ipsum[];
|
||||
extern int ipsum_len;
|
||||
extern struct configs conf;
|
||||
extern struct k_sem tcp_ready;
|
||||
|
||||
void start_udp(void);
|
||||
void stop_udp(void);
|
||||
|
||||
int start_tcp(void);
|
||||
void stop_tcp(void);
|
||||
|
||||
struct net_pkt *prepare_send_pkt(struct net_app_ctx *ctx,
|
||||
const char *name,
|
||||
int *expecting_len);
|
||||
void panic(const char *msg);
|
||||
|
||||
#if defined(CONFIG_NET_VLAN)
|
||||
int init_vlan(void);
|
||||
#else
|
||||
static inline int init_vlan(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#endif /* CONFIG_NET_VLAN */
|
|
@ -1,164 +0,0 @@
|
|||
/* echo-client.c - Networking echo client */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2017 Intel Corporation.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/*
|
||||
* The echo-client application is acting as a client that is run in Zephyr OS,
|
||||
* and echo-server is run in the host acting as a server. The client will send
|
||||
* either unicast or multicast packets to the server which will reply the packet
|
||||
* back to the originator.
|
||||
*
|
||||
* In this sample application we create four threads that start to send data.
|
||||
* This might not be what you want to do in your app so caveat emptor.
|
||||
*/
|
||||
|
||||
#include <logging/log.h>
|
||||
LOG_MODULE_REGISTER(net_echo_client_sample, LOG_LEVEL_DBG);
|
||||
|
||||
#include <zephyr.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <net/net_pkt.h>
|
||||
#include <net/net_core.h>
|
||||
#include <net/net_context.h>
|
||||
|
||||
#include <net/net_app.h>
|
||||
|
||||
#include "common.h"
|
||||
|
||||
#define APP_BANNER "Run echo client"
|
||||
|
||||
#define BUF_TIMEOUT K_MSEC(100)
|
||||
|
||||
/* Generated by http://www.lipsum.com/
|
||||
* 3 paragraphs, 176 words, 1230 bytes of Lorem Ipsum
|
||||
*/
|
||||
const char lorem_ipsum[] =
|
||||
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. "
|
||||
"Vestibulum id cursus felis, sit amet suscipit velit. Integer "
|
||||
"facilisis malesuada porta. Nunc at accumsan mauris. Etiam vehicula, "
|
||||
"arcu consequat feugiat venenatis, tellus velit gravida ligula, quis "
|
||||
"posuere sem leo eget urna. Curabitur condimentum leo nec orci "
|
||||
"mattis, nec faucibus dui rutrum. Ut mollis orci in iaculis "
|
||||
"consequat. Nulla volutpat nibh eu velit sagittis, a iaculis dui "
|
||||
"aliquam."
|
||||
"\n"
|
||||
"Quisque interdum consequat eros a eleifend. Fusce dapibus nisl "
|
||||
"sit amet velit posuere imperdiet. Quisque accumsan tempor massa "
|
||||
"sit amet tincidunt. Integer sollicitudin vehicula tristique. Nulla "
|
||||
"sagittis massa turpis, ac ultricies neque posuere eu. Nulla et "
|
||||
"imperdiet ex. Etiam venenatis sed lacus tincidunt hendrerit. In "
|
||||
"libero nisl, congue id tellus vitae, tincidunt tristique mauris. "
|
||||
"Nullam sed porta massa. Sed condimentum sem eu convallis euismod. "
|
||||
"Suspendisse lobortis purus faucibus, gravida turpis id, mattis "
|
||||
"velit. Maecenas eleifend sapien eu tincidunt lobortis. Sed elementum "
|
||||
"sapien id enim laoreet consequat."
|
||||
"\n"
|
||||
"Aenean et neque aliquam, lobortis lectus in, consequat leo. Sed "
|
||||
"quis egestas nulla. Quisque ac risus quis elit mollis finibus. "
|
||||
"Phasellus efficitur imperdiet metus."
|
||||
"\n";
|
||||
|
||||
int ipsum_len = sizeof(lorem_ipsum) - 1;
|
||||
|
||||
struct configs conf = {
|
||||
.ipv4 = {
|
||||
.proto = "IPv4",
|
||||
},
|
||||
.ipv6 = {
|
||||
.proto = "IPv6",
|
||||
},
|
||||
};
|
||||
|
||||
static struct k_sem quit_lock;
|
||||
struct k_sem tcp_ready;
|
||||
|
||||
void panic(const char *msg)
|
||||
{
|
||||
if (msg) {
|
||||
LOG_ERR("%s", msg);
|
||||
}
|
||||
|
||||
k_sem_give(&quit_lock);
|
||||
|
||||
for (;;) {
|
||||
k_sleep(K_FOREVER);
|
||||
}
|
||||
}
|
||||
|
||||
static inline int init_app(void)
|
||||
{
|
||||
LOG_INF(APP_BANNER);
|
||||
|
||||
k_sem_init(&quit_lock, 0, UINT_MAX);
|
||||
|
||||
init_vlan();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct net_pkt *prepare_send_pkt(struct net_app_ctx *ctx,
|
||||
const char *name,
|
||||
int *expecting_len)
|
||||
{
|
||||
struct net_pkt *send_pkt;
|
||||
|
||||
send_pkt = net_app_get_net_pkt(ctx, AF_UNSPEC, BUF_TIMEOUT);
|
||||
if (!send_pkt) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
*expecting_len = net_pkt_append(send_pkt, *expecting_len, lorem_ipsum,
|
||||
K_FOREVER);
|
||||
|
||||
return send_pkt;
|
||||
}
|
||||
|
||||
void main(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
init_app();
|
||||
|
||||
if (IS_ENABLED(CONFIG_NET_TCP)) {
|
||||
if (IS_ENABLED(CONFIG_NET_UDP)) {
|
||||
k_sem_init(&tcp_ready, 0, 1);
|
||||
}
|
||||
|
||||
ret = start_tcp();
|
||||
if (ret < 0) {
|
||||
goto quit;
|
||||
}
|
||||
|
||||
/* We start the UDP after the TCP is connected properly.
|
||||
* This is done like this so that UDP does not use all the
|
||||
* buffers as it is basically flooding the link with UDP
|
||||
* data.
|
||||
*/
|
||||
if (IS_ENABLED(CONFIG_NET_UDP)) {
|
||||
k_sem_take(&tcp_ready, K_FOREVER);
|
||||
}
|
||||
}
|
||||
|
||||
if (IS_ENABLED(CONFIG_NET_UDP)) {
|
||||
start_udp();
|
||||
}
|
||||
|
||||
k_sem_take(&quit_lock, K_FOREVER);
|
||||
|
||||
quit:
|
||||
LOG_INF("Stopping...");
|
||||
|
||||
if (IS_ENABLED(CONFIG_NET_UDP)) {
|
||||
stop_udp();
|
||||
}
|
||||
|
||||
if (IS_ENABLED(CONFIG_NET_TCP)) {
|
||||
stop_tcp();
|
||||
}
|
||||
}
|
|
@ -1,373 +0,0 @@
|
|||
/* tcp.c - TCP specific code for echo client */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2017 Intel Corporation.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <logging/log.h>
|
||||
LOG_MODULE_DECLARE(net_echo_client_sample, LOG_LEVEL_DBG);
|
||||
|
||||
#include <zephyr.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <net/net_pkt.h>
|
||||
#include <net/net_core.h>
|
||||
#include <net/net_context.h>
|
||||
|
||||
#include <net/net_app.h>
|
||||
|
||||
#include "common.h"
|
||||
|
||||
static struct net_app_ctx tcp6;
|
||||
static struct net_app_ctx tcp4;
|
||||
|
||||
static int connected_count;
|
||||
|
||||
/* Note that both tcp and udp can share the same pool but in this
|
||||
* example the UDP context and TCP context have separate pools.
|
||||
*/
|
||||
#if defined(CONFIG_NET_CONTEXT_NET_PKT_POOL)
|
||||
NET_PKT_TX_SLAB_DEFINE(echo_tx_tcp, 15);
|
||||
NET_PKT_DATA_POOL_DEFINE(echo_data_tcp, 30);
|
||||
|
||||
static struct k_mem_slab *tx_tcp_slab(void)
|
||||
{
|
||||
return &echo_tx_tcp;
|
||||
}
|
||||
|
||||
static struct net_buf_pool *data_tcp_pool(void)
|
||||
{
|
||||
return &echo_data_tcp;
|
||||
}
|
||||
#else
|
||||
#define tx_tcp_slab NULL
|
||||
#define data_tcp_pool NULL
|
||||
#endif /* CONFIG_NET_CONTEXT_NET_PKT_POOL */
|
||||
|
||||
#if defined(CONFIG_NET_APP_TLS)
|
||||
#define HOSTNAME "localhost" /* for cert verification if that is enabled */
|
||||
|
||||
/* The result buf size is set to large enough so that we can receive max size
|
||||
* buf back. Note that mbedtls needs also be configured to have equal size
|
||||
* value for its buffer size. See MBEDTLS_SSL_MAX_CONTENT_LEN option in TLS
|
||||
* config file.
|
||||
*/
|
||||
#define RESULT_BUF_SIZE 1500
|
||||
static u8_t tls_result_ipv6[RESULT_BUF_SIZE];
|
||||
static u8_t tls_result_ipv4[RESULT_BUF_SIZE];
|
||||
|
||||
#if !defined(CONFIG_NET_APP_TLS_STACK_SIZE)
|
||||
#define CONFIG_NET_APP_TLS_STACK_SIZE 6144
|
||||
#endif /* CONFIG_NET_APP_TLS_STACK_SIZE */
|
||||
|
||||
#define INSTANCE_INFO "Zephyr TLS echo-client #1"
|
||||
|
||||
/* Note that each net_app context needs its own stack as there will be
|
||||
* a separate thread needed.
|
||||
*/
|
||||
NET_STACK_DEFINE(NET_APP_TLS_IPv4, net_app_tls_stack_ipv4,
|
||||
CONFIG_NET_APP_TLS_STACK_SIZE, CONFIG_NET_APP_TLS_STACK_SIZE);
|
||||
|
||||
NET_STACK_DEFINE(NET_APP_TLS_IPv6, net_app_tls_stack_ipv6,
|
||||
CONFIG_NET_APP_TLS_STACK_SIZE, CONFIG_NET_APP_TLS_STACK_SIZE);
|
||||
|
||||
NET_APP_TLS_POOL_DEFINE(ssl_pool, 10);
|
||||
#else
|
||||
#define tls_result_ipv6 NULL
|
||||
#define tls_result_ipv4 NULL
|
||||
#define net_app_tls_stack_ipv4 NULL
|
||||
#define net_app_tls_stack_ipv6 NULL
|
||||
#endif /* CONFIG_NET_APP_TLS */
|
||||
|
||||
#if defined(CONFIG_NET_APP_TLS)
|
||||
/* Load the certificates and private RSA key. */
|
||||
|
||||
#include "test_certs.h"
|
||||
|
||||
static int setup_cert(struct net_app_ctx *ctx, void *cert)
|
||||
{
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED)
|
||||
mbedtls_ssl_conf_psk(&ctx->tls.mbedtls.conf,
|
||||
client_psk, sizeof(client_psk),
|
||||
(const unsigned char *)client_psk_id,
|
||||
sizeof(client_psk_id) - 1);
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_X509_CRT_PARSE_C)
|
||||
{
|
||||
mbedtls_x509_crt *ca_cert = cert;
|
||||
int ret;
|
||||
|
||||
ret = mbedtls_x509_crt_parse_der(ca_cert,
|
||||
ca_certificate,
|
||||
sizeof(ca_certificate));
|
||||
if (ret != 0) {
|
||||
LOG_ERR("mbedtls_x509_crt_parse_der failed "
|
||||
"(-0x%x)", -ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
mbedtls_ssl_conf_ca_chain(&ctx->tls.mbedtls.conf,
|
||||
ca_cert, NULL);
|
||||
|
||||
/* In this example, we skip the certificate checks. In real
|
||||
* life scenarios, one should always verify the certificates.
|
||||
*/
|
||||
mbedtls_ssl_conf_authmode(&ctx->tls.mbedtls.conf,
|
||||
MBEDTLS_SSL_VERIFY_REQUIRED);
|
||||
|
||||
mbedtls_ssl_conf_cert_profile(&ctx->tls.mbedtls.conf,
|
||||
&mbedtls_x509_crt_profile_default);
|
||||
#define VERIFY_CERTS 0
|
||||
#if VERIFY_CERTS
|
||||
mbedtls_ssl_conf_authmode(&ctx->tls.mbedtls.conf,
|
||||
MBEDTLS_SSL_VERIFY_OPTIONAL);
|
||||
#else
|
||||
;
|
||||
#endif /* VERIFY_CERTS */
|
||||
}
|
||||
#endif /* MBEDTLS_X509_CRT_PARSE_C */
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* CONFIG_NET_APP_TLS */
|
||||
|
||||
static void send_tcp_data(struct net_app_ctx *ctx,
|
||||
struct data *data)
|
||||
{
|
||||
struct net_pkt *pkt;
|
||||
size_t len;
|
||||
int ret;
|
||||
|
||||
do {
|
||||
data->expecting_tcp = sys_rand32_get() % ipsum_len;
|
||||
} while (data->expecting_tcp == 0);
|
||||
|
||||
data->received_tcp = 0U;
|
||||
|
||||
pkt = prepare_send_pkt(ctx, data->proto, &data->expecting_tcp);
|
||||
if (!pkt) {
|
||||
return;
|
||||
}
|
||||
|
||||
len = net_pkt_get_len(pkt);
|
||||
|
||||
NET_ASSERT_INFO(data->expecting_tcp == len,
|
||||
"%s data to send %d bytes, real len %zu",
|
||||
data->proto, data->expecting_tcp, len);
|
||||
|
||||
ret = net_app_send_pkt(ctx, pkt, NULL, 0, K_FOREVER,
|
||||
UINT_TO_POINTER(len));
|
||||
if (ret < 0) {
|
||||
LOG_ERR("Cannot send %s data to peer (%d)", data->proto, ret);
|
||||
net_pkt_unref(pkt);
|
||||
}
|
||||
}
|
||||
|
||||
static bool compare_tcp_data(struct net_pkt *pkt, int expecting_len,
|
||||
int received_len)
|
||||
{
|
||||
u8_t *ptr = net_pkt_appdata(pkt);
|
||||
const char *start;
|
||||
int pos = 0;
|
||||
struct net_buf *frag;
|
||||
int len;
|
||||
|
||||
/* frag will point to first fragment with IP header in it.
|
||||
*/
|
||||
frag = pkt->frags;
|
||||
|
||||
/* Do not include the protocol headers for the first fragment.
|
||||
* The remaining fragments contain only data so the user data
|
||||
* length is directly the fragment len.
|
||||
*/
|
||||
len = frag->len - (ptr - frag->data);
|
||||
|
||||
start = lorem_ipsum + received_len;
|
||||
|
||||
while (frag) {
|
||||
if (memcmp(ptr, start + pos, len)) {
|
||||
LOG_DBG("Invalid data received");
|
||||
return false;
|
||||
}
|
||||
|
||||
pos += len;
|
||||
|
||||
frag = frag->frags;
|
||||
if (!frag) {
|
||||
break;
|
||||
}
|
||||
|
||||
ptr = frag->data;
|
||||
len = frag->len;
|
||||
}
|
||||
|
||||
LOG_DBG("Compared %d bytes, all ok", net_pkt_appdatalen(pkt));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void tcp_received(struct net_app_ctx *ctx,
|
||||
struct net_pkt *pkt,
|
||||
int status,
|
||||
void *user_data)
|
||||
{
|
||||
struct data *data = ctx->user_data;
|
||||
|
||||
ARG_UNUSED(user_data);
|
||||
ARG_UNUSED(status);
|
||||
|
||||
if (!pkt || net_pkt_appdatalen(pkt) == 0) {
|
||||
if (pkt) {
|
||||
net_pkt_unref(pkt);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
LOG_DBG("%s: Sent %d bytes, received %u bytes",
|
||||
data->proto, data->expecting_tcp, net_pkt_appdatalen(pkt));
|
||||
|
||||
if (!compare_tcp_data(pkt, data->expecting_tcp, data->received_tcp)) {
|
||||
LOG_DBG("Data mismatch");
|
||||
} else {
|
||||
data->received_tcp += net_pkt_appdatalen(pkt);
|
||||
}
|
||||
|
||||
if (data->expecting_tcp <= data->received_tcp) {
|
||||
/* Send more data */
|
||||
send_tcp_data(ctx, data);
|
||||
}
|
||||
|
||||
net_pkt_unref(pkt);
|
||||
}
|
||||
|
||||
static void tcp_connected(struct net_app_ctx *ctx,
|
||||
int status,
|
||||
void *user_data)
|
||||
{
|
||||
if (status < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
connected_count++;
|
||||
|
||||
if (IS_ENABLED(CONFIG_NET_UDP)) {
|
||||
if (IS_ENABLED(CONFIG_NET_IPV6) &&
|
||||
IS_ENABLED(CONFIG_NET_IPV4)) {
|
||||
if (connected_count > 1) {
|
||||
k_sem_give(&tcp_ready);
|
||||
}
|
||||
} else {
|
||||
k_sem_give(&tcp_ready);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int connect_tcp(struct net_app_ctx *ctx, const char *peer,
|
||||
void *user_data, u8_t *result_buf,
|
||||
size_t result_buf_len,
|
||||
k_thread_stack_t *stack, size_t stack_size)
|
||||
{
|
||||
struct data *data = user_data;
|
||||
int ret;
|
||||
|
||||
ret = net_app_init_tcp_client(ctx, NULL, NULL, peer, PEER_PORT,
|
||||
WAIT_TIME, user_data);
|
||||
if (ret < 0) {
|
||||
LOG_ERR("Cannot init %s TCP client (%d)", data->proto, ret);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
#if defined(CONFIG_NET_CONTEXT_NET_PKT_POOL)
|
||||
net_app_set_net_pkt_pool(ctx, tx_tcp_slab, data_tcp_pool);
|
||||
#endif
|
||||
|
||||
ret = net_app_set_cb(ctx, tcp_connected, tcp_received, NULL, NULL);
|
||||
if (ret < 0) {
|
||||
LOG_ERR("Cannot set callbacks (%d)", ret);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
#if defined(CONFIG_NET_APP_TLS)
|
||||
ret = net_app_client_tls(ctx,
|
||||
result_buf,
|
||||
result_buf_len,
|
||||
INSTANCE_INFO,
|
||||
strlen(INSTANCE_INFO),
|
||||
setup_cert,
|
||||
HOSTNAME,
|
||||
NULL,
|
||||
&ssl_pool,
|
||||
stack,
|
||||
stack_size);
|
||||
if (ret < 0) {
|
||||
LOG_ERR("Cannot init TLS");
|
||||
goto fail;
|
||||
}
|
||||
#endif
|
||||
|
||||
ret = net_app_connect(ctx, CONNECT_TIME);
|
||||
if (ret < 0) {
|
||||
LOG_ERR("Cannot connect TCP (%d)", ret);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
fail:
|
||||
return ret;
|
||||
}
|
||||
|
||||
int start_tcp(void)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
if (IS_ENABLED(CONFIG_NET_IPV6)) {
|
||||
ret = connect_tcp(&tcp6, CONFIG_NET_CONFIG_PEER_IPV6_ADDR,
|
||||
&conf.ipv6, tls_result_ipv6,
|
||||
sizeof(tls_result_ipv6),
|
||||
net_app_tls_stack_ipv6,
|
||||
K_THREAD_STACK_SIZEOF(
|
||||
net_app_tls_stack_ipv6));
|
||||
if (ret < 0) {
|
||||
LOG_ERR("Cannot init IPv6 TCP client (%d)", ret);
|
||||
}
|
||||
}
|
||||
|
||||
if (IS_ENABLED(CONFIG_NET_IPV4)) {
|
||||
ret = connect_tcp(&tcp4, CONFIG_NET_CONFIG_PEER_IPV4_ADDR,
|
||||
&conf.ipv4, tls_result_ipv4,
|
||||
sizeof(tls_result_ipv4),
|
||||
net_app_tls_stack_ipv4,
|
||||
K_THREAD_STACK_SIZEOF(
|
||||
net_app_tls_stack_ipv4));
|
||||
if (ret < 0) {
|
||||
LOG_ERR("Cannot init IPv4 TCP client (%d)", ret);
|
||||
}
|
||||
}
|
||||
|
||||
if (IS_ENABLED(CONFIG_NET_IPV6)) {
|
||||
send_tcp_data(&tcp6, &conf.ipv6);
|
||||
}
|
||||
|
||||
if (IS_ENABLED(CONFIG_NET_IPV4)) {
|
||||
send_tcp_data(&tcp4, &conf.ipv4);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void stop_tcp(void)
|
||||
{
|
||||
if (IS_ENABLED(CONFIG_NET_IPV6)) {
|
||||
net_app_close(&tcp6);
|
||||
net_app_release(&tcp6);
|
||||
}
|
||||
|
||||
if (IS_ENABLED(CONFIG_NET_IPV4)) {
|
||||
net_app_close(&tcp4);
|
||||
net_app_release(&tcp4);
|
||||
}
|
||||
}
|
|
@ -1,122 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2016 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#ifndef __TEST_CERTS_H__
|
||||
#define __TEST_CERTS_H__
|
||||
|
||||
#if defined(MBEDTLS_X509_CRT_PARSE_C)
|
||||
/* This is the same cert as what is found in net-tools/echo-apps-cert.pem file
|
||||
*/
|
||||
static const unsigned char ca_certificate[] = {
|
||||
0x30, 0x82, 0x02, 0xfb, 0x30, 0x82, 0x01, 0xe3,
|
||||
0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x09, 0x00,
|
||||
0xee, 0x10, 0x1f, 0xc1, 0xf2, 0x30, 0xe9, 0x11,
|
||||
0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86,
|
||||
0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30,
|
||||
0x14, 0x31, 0x12, 0x30, 0x10, 0x06, 0x03, 0x55,
|
||||
0x04, 0x03, 0x0c, 0x09, 0x6c, 0x6f, 0x63, 0x61,
|
||||
0x6c, 0x68, 0x6f, 0x73, 0x74, 0x30, 0x1e, 0x17,
|
||||
0x0d, 0x31, 0x37, 0x30, 0x36, 0x32, 0x36, 0x31,
|
||||
0x30, 0x35, 0x36, 0x31, 0x30, 0x5a, 0x17, 0x0d,
|
||||
0x34, 0x34, 0x31, 0x31, 0x31, 0x31, 0x31, 0x30,
|
||||
0x35, 0x36, 0x31, 0x30, 0x5a, 0x30, 0x14, 0x31,
|
||||
0x12, 0x30, 0x10, 0x06, 0x03, 0x55, 0x04, 0x03,
|
||||
0x0c, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x68,
|
||||
0x6f, 0x73, 0x74, 0x30, 0x82, 0x01, 0x22, 0x30,
|
||||
0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7,
|
||||
0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82,
|
||||
0x01, 0x0f, 0x00, 0x30, 0x82, 0x01, 0x0a, 0x02,
|
||||
0x82, 0x01, 0x01, 0x00, 0xc6, 0x00, 0x7b, 0x0d,
|
||||
0xd1, 0x17, 0x43, 0x6b, 0xa9, 0xa7, 0x79, 0x9c,
|
||||
0x0f, 0x8d, 0x77, 0x91, 0xd2, 0xf7, 0x47, 0x35,
|
||||
0xb3, 0x17, 0xe2, 0xdd, 0xed, 0x6d, 0x01, 0xf9,
|
||||
0xb1, 0x92, 0xc9, 0x48, 0x80, 0xe0, 0x1f, 0xcf,
|
||||
0xb7, 0xa4, 0x5f, 0xf0, 0x36, 0xea, 0xbf, 0xe1,
|
||||
0x33, 0xf8, 0xa9, 0xc5, 0xe6, 0xd4, 0x19, 0x8b,
|
||||
0x82, 0x25, 0xd9, 0x19, 0x74, 0x70, 0x79, 0xec,
|
||||
0xc6, 0x68, 0xc9, 0xef, 0xce, 0x1a, 0xa9, 0xf0,
|
||||
0xb7, 0x01, 0x35, 0x91, 0xff, 0xd3, 0x75, 0x6e,
|
||||
0x02, 0xba, 0x06, 0x9a, 0x2a, 0xac, 0xcf, 0x22,
|
||||
0xbf, 0x2b, 0x1f, 0xc1, 0x72, 0x38, 0x22, 0x35,
|
||||
0xea, 0xda, 0x6f, 0xdd, 0x67, 0xa2, 0x2b, 0x19,
|
||||
0x38, 0x19, 0x0e, 0x44, 0xd1, 0x71, 0x38, 0xb4,
|
||||
0x6d, 0x26, 0x85, 0xd6, 0xc6, 0xbe, 0xc1, 0x6f,
|
||||
0x3c, 0xee, 0xaf, 0x94, 0x3c, 0x05, 0x56, 0x4e,
|
||||
0xad, 0x53, 0x81, 0x8b, 0xd4, 0x23, 0x31, 0x69,
|
||||
0x72, 0x27, 0x93, 0xb4, 0x3a, 0xac, 0x23, 0xe8,
|
||||
0x10, 0xae, 0xf5, 0x9f, 0x0b, 0xa6, 0x6e, 0xd3,
|
||||
0x73, 0xca, 0x18, 0x11, 0xca, 0xbe, 0x71, 0x00,
|
||||
0x56, 0x29, 0x34, 0x54, 0xcc, 0xda, 0x29, 0x5b,
|
||||
0x26, 0x29, 0x99, 0x4d, 0x5f, 0xa1, 0xa6, 0xb9,
|
||||
0xcb, 0x2b, 0xb2, 0x0f, 0x10, 0x00, 0x04, 0xa9,
|
||||
0x11, 0x2c, 0x48, 0xb1, 0x99, 0xa5, 0xca, 0x7c,
|
||||
0x67, 0xa5, 0xbe, 0x14, 0x20, 0x12, 0xb7, 0x3b,
|
||||
0x7a, 0x4f, 0xdc, 0xc7, 0xd5, 0x2d, 0x04, 0x66,
|
||||
0xbb, 0xf5, 0x0c, 0xcd, 0xf1, 0x32, 0x39, 0xd7,
|
||||
0x51, 0x9b, 0xba, 0xdb, 0xf1, 0xa7, 0xfe, 0x2d,
|
||||
0x9a, 0xe6, 0x9c, 0x6b, 0x54, 0xda, 0xf1, 0xdd,
|
||||
0x48, 0xf9, 0xd7, 0xf0, 0x35, 0x7c, 0x8e, 0x24,
|
||||
0x7e, 0x44, 0x2f, 0xf3, 0xbf, 0x39, 0x0e, 0x96,
|
||||
0xab, 0xe1, 0x45, 0x03, 0x8b, 0x54, 0xdc, 0xe1,
|
||||
0xb6, 0x11, 0x81, 0x21, 0x02, 0x03, 0x01, 0x00,
|
||||
0x01, 0xa3, 0x50, 0x30, 0x4e, 0x30, 0x1d, 0x06,
|
||||
0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14,
|
||||
0xa4, 0xef, 0x6d, 0xdc, 0x9b, 0x23, 0xc5, 0x3a,
|
||||
0xdd, 0x34, 0xd9, 0x01, 0x1c, 0x68, 0x03, 0x53,
|
||||
0xae, 0x92, 0xc2, 0xc9, 0x30, 0x1f, 0x06, 0x03,
|
||||
0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, 0x80,
|
||||
0x14, 0xa4, 0xef, 0x6d, 0xdc, 0x9b, 0x23, 0xc5,
|
||||
0x3a, 0xdd, 0x34, 0xd9, 0x01, 0x1c, 0x68, 0x03,
|
||||
0x53, 0xae, 0x92, 0xc2, 0xc9, 0x30, 0x0c, 0x06,
|
||||
0x03, 0x55, 0x1d, 0x13, 0x04, 0x05, 0x30, 0x03,
|
||||
0x01, 0x01, 0xff, 0x30, 0x0d, 0x06, 0x09, 0x2a,
|
||||
0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b,
|
||||
0x05, 0x00, 0x03, 0x82, 0x01, 0x01, 0x00, 0x67,
|
||||
0x65, 0xbf, 0x93, 0x89, 0xde, 0x4f, 0x71, 0xff,
|
||||
0x1c, 0x93, 0x68, 0xa0, 0x64, 0x09, 0x5e, 0x95,
|
||||
0x94, 0xf5, 0xd5, 0xf4, 0x6b, 0x20, 0x32, 0xd8,
|
||||
0x04, 0x80, 0xac, 0xf8, 0x52, 0x36, 0x7a, 0x38,
|
||||
0x83, 0xae, 0xab, 0x29, 0x22, 0x42, 0x71, 0x7e,
|
||||
0xea, 0xe5, 0x4f, 0x71, 0xac, 0x44, 0x3f, 0x9e,
|
||||
0x5e, 0x49, 0x22, 0x05, 0xee, 0xa6, 0x7b, 0xab,
|
||||
0x56, 0x2e, 0xb3, 0x9a, 0x35, 0x1a, 0x88, 0xc3,
|
||||
0x54, 0x9b, 0xfd, 0xac, 0x65, 0x54, 0xaf, 0x21,
|
||||
0xa7, 0xe0, 0xdd, 0x62, 0x29, 0x8c, 0xae, 0x26,
|
||||
0x0b, 0x84, 0x1f, 0x69, 0x78, 0x84, 0xc6, 0x7e,
|
||||
0xcf, 0xc8, 0xf5, 0x92, 0x8c, 0x05, 0xa8, 0x13,
|
||||
0x38, 0xcd, 0x0b, 0x98, 0x53, 0xfb, 0xdd, 0x8d,
|
||||
0x51, 0x90, 0xa8, 0x51, 0xfa, 0x52, 0xbe, 0x28,
|
||||
0xd4, 0x71, 0x50, 0x73, 0x1f, 0xb0, 0xb6, 0x0e,
|
||||
0x45, 0xb1, 0x47, 0x41, 0x06, 0xd9, 0x1d, 0x7a,
|
||||
0x34, 0xe7, 0x80, 0x2e, 0x0c, 0x02, 0x50, 0x97,
|
||||
0xde, 0xa8, 0x7a, 0x84, 0x2c, 0x1d, 0xf4, 0x51,
|
||||
0x56, 0xa5, 0x52, 0xb5, 0x04, 0x2e, 0xcb, 0xdd,
|
||||
0x8b, 0x2e, 0x16, 0xc6, 0xde, 0xc8, 0xe9, 0x8d,
|
||||
0xee, 0x5e, 0xb6, 0xa0, 0xe0, 0x2b, 0x85, 0x2a,
|
||||
0x89, 0x7b, 0xba, 0x68, 0x80, 0x2b, 0xfb, 0x6e,
|
||||
0x2e, 0x80, 0xe7, 0x7a, 0x97, 0x09, 0xb5, 0x2f,
|
||||
0x20, 0x8e, 0xed, 0xbc, 0x98, 0x6f, 0x95, 0xd5,
|
||||
0x5b, 0x3d, 0x26, 0x19, 0x26, 0x14, 0x39, 0x82,
|
||||
0xa8, 0xa8, 0x42, 0x46, 0xab, 0x59, 0x93, 0x47,
|
||||
0x83, 0xf7, 0x79, 0xbf, 0x73, 0xb5, 0x5d, 0x5d,
|
||||
0x78, 0xfe, 0x62, 0xac, 0xed, 0xb7, 0x1e, 0x4a,
|
||||
0xad, 0xc3, 0x99, 0x39, 0x7d, 0x3e, 0x30, 0x21,
|
||||
0x26, 0x1d, 0x66, 0xdb, 0x0d, 0xf3, 0xba, 0x87,
|
||||
0x46, 0xf0, 0x04, 0xfc, 0xc3, 0xbe, 0x84, 0x85,
|
||||
0x3c, 0x01, 0xef, 0xe0, 0x68, 0x65, 0xee,
|
||||
};
|
||||
#endif /* MBEDTLS_X509_CRT_PARSE_C */
|
||||
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED)
|
||||
static const unsigned char client_psk[] = {
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
|
||||
};
|
||||
|
||||
static const char client_psk_id[] = "Client_identity";
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -1,365 +0,0 @@
|
|||
/* udp.c - UDP specific code for echo client */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2017 Intel Corporation.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <logging/log.h>
|
||||
LOG_MODULE_DECLARE(net_echo_client_sample, LOG_LEVEL_DBG);
|
||||
|
||||
#include <zephyr.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <net/net_pkt.h>
|
||||
#include <net/net_core.h>
|
||||
#include <net/net_context.h>
|
||||
|
||||
#include <net/net_app.h>
|
||||
|
||||
#include "common.h"
|
||||
|
||||
static struct net_app_ctx udp6;
|
||||
static struct net_app_ctx udp4;
|
||||
|
||||
#define UDP_SLEEP K_MSEC(150)
|
||||
|
||||
/* Note that both tcp and udp can share the same pool but in this
|
||||
* example the UDP context and TCP context have separate pools.
|
||||
*/
|
||||
#if defined(CONFIG_NET_CONTEXT_NET_PKT_POOL)
|
||||
NET_PKT_TX_SLAB_DEFINE(echo_tx_udp, 5);
|
||||
NET_PKT_DATA_POOL_DEFINE(echo_data_udp, 20);
|
||||
|
||||
static struct k_mem_slab *tx_udp_slab(void)
|
||||
{
|
||||
return &echo_tx_udp;
|
||||
}
|
||||
|
||||
static struct net_buf_pool *data_udp_pool(void)
|
||||
{
|
||||
return &echo_data_udp;
|
||||
}
|
||||
#else
|
||||
#define tx_udp_slab NULL
|
||||
#define data_udp_pool NULL
|
||||
#endif /* CONFIG_NET_CONTEXT_NET_PKT_POOL */
|
||||
|
||||
#if defined(CONFIG_NET_APP_DTLS)
|
||||
#define HOSTNAME "localhost" /* for cert verification if that is enabled */
|
||||
|
||||
/* The result buf size is set to large enough so that we can receive max size
|
||||
* buf back. Note that mbedtls needs also be configured to have equal size
|
||||
* value for its buffer size. See MBEDTLS_SSL_MAX_CONTENT_LEN option in DTLS
|
||||
* config file.
|
||||
*/
|
||||
#define RESULT_BUF_SIZE 1500
|
||||
static u8_t dtls_result_ipv6[RESULT_BUF_SIZE];
|
||||
static u8_t dtls_result_ipv4[RESULT_BUF_SIZE];
|
||||
|
||||
#if !defined(CONFIG_NET_APP_TLS_STACK_SIZE)
|
||||
#define CONFIG_NET_APP_TLS_STACK_SIZE 6144
|
||||
#endif /* CONFIG_NET_APP_TLS_STACK_SIZE */
|
||||
|
||||
#define INSTANCE_INFO "Zephyr DTLS echo-client #1"
|
||||
|
||||
/* Note that each net_app context needs its own stack as there will be
|
||||
* a separate thread needed.
|
||||
*/
|
||||
NET_STACK_DEFINE(NET_APP_DTLS_IPv4, net_app_dtls_stack_ipv4,
|
||||
CONFIG_NET_APP_TLS_STACK_SIZE, CONFIG_NET_APP_TLS_STACK_SIZE);
|
||||
|
||||
NET_STACK_DEFINE(NET_APP_DTLS_IPv6, net_app_dtls_stack_ipv6,
|
||||
CONFIG_NET_APP_TLS_STACK_SIZE, CONFIG_NET_APP_TLS_STACK_SIZE);
|
||||
|
||||
NET_APP_TLS_POOL_DEFINE(dtls_pool, 10);
|
||||
#else
|
||||
#define dtls_result_ipv6 NULL
|
||||
#define dtls_result_ipv4 NULL
|
||||
#define net_app_dtls_stack_ipv4 NULL
|
||||
#define net_app_dtls_stack_ipv6 NULL
|
||||
#endif /* CONFIG_NET_APP_TLS */
|
||||
|
||||
#if defined(CONFIG_NET_APP_TLS) || defined(CONFIG_NET_APP_DTLS)
|
||||
/* Load the certificates and private RSA key. */
|
||||
|
||||
#include "test_certs.h"
|
||||
|
||||
static int setup_cert(struct net_app_ctx *ctx, void *cert)
|
||||
{
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED)
|
||||
mbedtls_ssl_conf_psk(&ctx->tls.mbedtls.conf,
|
||||
client_psk, sizeof(client_psk),
|
||||
(const unsigned char *)client_psk_id,
|
||||
sizeof(client_psk_id) - 1);
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_X509_CRT_PARSE_C)
|
||||
{
|
||||
mbedtls_x509_crt *ca_cert = cert;
|
||||
int ret;
|
||||
|
||||
ret = mbedtls_x509_crt_parse_der(ca_cert,
|
||||
ca_certificate,
|
||||
sizeof(ca_certificate));
|
||||
if (ret != 0) {
|
||||
NET_ERR("mbedtls_x509_crt_parse_der failed "
|
||||
"(-0x%x)", -ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
mbedtls_ssl_conf_ca_chain(&ctx->tls.mbedtls.conf,
|
||||
ca_cert, NULL);
|
||||
|
||||
/* In this example, we skip the certificate checks. In real
|
||||
* life scenarios, one should always verify the certificates.
|
||||
*/
|
||||
mbedtls_ssl_conf_authmode(&ctx->tls.mbedtls.conf,
|
||||
MBEDTLS_SSL_VERIFY_REQUIRED);
|
||||
|
||||
mbedtls_ssl_conf_cert_profile(&ctx->tls.mbedtls.conf,
|
||||
&mbedtls_x509_crt_profile_default);
|
||||
#define VERIFY_CERTS 0
|
||||
#if VERIFY_CERTS
|
||||
mbedtls_ssl_conf_authmode(&ctx->tls.mbedtls.conf,
|
||||
MBEDTLS_SSL_VERIFY_OPTIONAL);
|
||||
#else
|
||||
;
|
||||
#endif /* VERIFY_CERTS */
|
||||
}
|
||||
#endif /* MBEDTLS_X509_CRT_PARSE_C */
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* CONFIG_NET_APP_TLS */
|
||||
|
||||
static void send_udp_data(struct net_app_ctx *ctx, struct data *data)
|
||||
{
|
||||
struct net_pkt *pkt;
|
||||
size_t len;
|
||||
int ret;
|
||||
|
||||
data->expecting_udp = sys_rand32_get() % ipsum_len;
|
||||
|
||||
pkt = prepare_send_pkt(ctx, data->proto, &data->expecting_udp);
|
||||
if (!pkt) {
|
||||
return;
|
||||
}
|
||||
|
||||
len = net_pkt_get_len(pkt);
|
||||
|
||||
NET_ASSERT_INFO(data->expecting_udp == len,
|
||||
"Data to send %d bytes, real len %zu",
|
||||
data->expecting_udp, len);
|
||||
|
||||
ret = net_app_send_pkt(ctx, pkt, NULL, 0, K_FOREVER,
|
||||
UINT_TO_POINTER(len));
|
||||
if (ret < 0) {
|
||||
LOG_ERR("Cannot send %s data to peer (%d)", data->proto, ret);
|
||||
|
||||
net_pkt_unref(pkt);
|
||||
}
|
||||
|
||||
k_delayed_work_submit(&data->recv, WAIT_TIME);
|
||||
}
|
||||
|
||||
static bool compare_udp_data(struct net_pkt *pkt, int expecting_len)
|
||||
{
|
||||
u8_t *ptr = net_pkt_appdata(pkt);
|
||||
struct net_buf *frag;
|
||||
int pos = 0;
|
||||
int len;
|
||||
|
||||
/* frag will now point to first fragment with IP header
|
||||
* in it.
|
||||
*/
|
||||
frag = pkt->frags;
|
||||
|
||||
/* Do not include the protocol headers in the first fragment.
|
||||
* The remaining fragments contain only data so the user data
|
||||
* length is directly the fragment len.
|
||||
*/
|
||||
len = frag->len - (ptr - frag->data);
|
||||
|
||||
while (frag) {
|
||||
if (memcmp(ptr, lorem_ipsum + pos, len)) {
|
||||
LOG_DBG("Invalid data received");
|
||||
return false;
|
||||
} else {
|
||||
pos += len;
|
||||
|
||||
frag = frag->frags;
|
||||
if (!frag) {
|
||||
break;
|
||||
}
|
||||
|
||||
ptr = frag->data;
|
||||
len = frag->len;
|
||||
}
|
||||
}
|
||||
|
||||
LOG_DBG("Compared %d bytes, all ok", expecting_len);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void udp_received(struct net_app_ctx *ctx,
|
||||
struct net_pkt *pkt,
|
||||
int status,
|
||||
void *user_data)
|
||||
{
|
||||
struct data *data = ctx->user_data;
|
||||
|
||||
ARG_UNUSED(user_data);
|
||||
ARG_UNUSED(status);
|
||||
|
||||
if (data->expecting_udp != net_pkt_appdatalen(pkt)) {
|
||||
LOG_DBG("Sent %d bytes, received %u bytes",
|
||||
data->expecting_udp, net_pkt_appdatalen(pkt));
|
||||
}
|
||||
|
||||
if (!compare_udp_data(pkt, data->expecting_udp)) {
|
||||
LOG_DBG("Data mismatch");
|
||||
}
|
||||
|
||||
net_pkt_unref(pkt);
|
||||
|
||||
k_delayed_work_cancel(&data->recv);
|
||||
|
||||
/* Do not flood the link if we have also TCP configured */
|
||||
if (IS_ENABLED(CONFIG_NET_TCP)) {
|
||||
k_sleep(UDP_SLEEP);
|
||||
}
|
||||
|
||||
send_udp_data(ctx, data);
|
||||
}
|
||||
|
||||
/* We can start to send data when UDP is "connected" */
|
||||
static void udp_connected(struct net_app_ctx *ctx,
|
||||
int status,
|
||||
void *user_data)
|
||||
{
|
||||
struct data *data = user_data;
|
||||
|
||||
data->udp = ctx;
|
||||
|
||||
send_udp_data(ctx, data);
|
||||
}
|
||||
|
||||
static int connect_udp(struct net_app_ctx *ctx, const char *peer,
|
||||
void *user_data, u8_t *dtls_result_buf,
|
||||
size_t dtls_result_buf_len,
|
||||
k_thread_stack_t *stack, size_t stack_size)
|
||||
{
|
||||
struct data *data = user_data;
|
||||
int ret;
|
||||
|
||||
ret = net_app_init_udp_client(ctx, NULL, NULL, peer, PEER_PORT,
|
||||
WAIT_TIME, user_data);
|
||||
if (ret < 0) {
|
||||
LOG_ERR("Cannot init %s UDP client (%d)", data->proto, ret);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
#if defined(CONFIG_NET_CONTEXT_NET_PKT_POOL)
|
||||
net_app_set_net_pkt_pool(ctx, tx_udp_slab, data_udp_pool);
|
||||
#endif
|
||||
|
||||
ret = net_app_set_cb(ctx, udp_connected, udp_received, NULL, NULL);
|
||||
if (ret < 0) {
|
||||
LOG_ERR("Cannot set callbacks (%d)", ret);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
#if defined(CONFIG_NET_APP_DTLS)
|
||||
ret = net_app_client_tls(ctx,
|
||||
dtls_result_buf,
|
||||
dtls_result_buf_len,
|
||||
INSTANCE_INFO,
|
||||
strlen(INSTANCE_INFO),
|
||||
setup_cert,
|
||||
HOSTNAME,
|
||||
NULL,
|
||||
&dtls_pool,
|
||||
stack,
|
||||
stack_size);
|
||||
if (ret < 0) {
|
||||
LOG_ERR("Cannot init DTLS");
|
||||
goto fail;
|
||||
}
|
||||
#else
|
||||
ARG_UNUSED(dtls_result_buf);
|
||||
ARG_UNUSED(dtls_result_buf_len);
|
||||
ARG_UNUSED(stack);
|
||||
ARG_UNUSED(stack_size);
|
||||
#endif
|
||||
|
||||
ret = net_app_connect(ctx, CONNECT_TIME);
|
||||
if (ret < 0) {
|
||||
LOG_ERR("Cannot connect UDP (%d)", ret);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
fail:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void wait_reply(struct k_work *work)
|
||||
{
|
||||
/* This means that we did not receive response in time. */
|
||||
struct data *data = CONTAINER_OF(work, struct data, recv);
|
||||
|
||||
LOG_ERR("Data packet not received");
|
||||
|
||||
/* Send a new packet at this point */
|
||||
send_udp_data(data->udp, data);
|
||||
}
|
||||
|
||||
void start_udp(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (IS_ENABLED(CONFIG_NET_IPV6)) {
|
||||
k_delayed_work_init(&conf.ipv6.recv, wait_reply);
|
||||
|
||||
ret = connect_udp(&udp6, CONFIG_NET_CONFIG_PEER_IPV6_ADDR,
|
||||
&conf.ipv6, dtls_result_ipv6,
|
||||
sizeof(dtls_result_ipv6),
|
||||
net_app_dtls_stack_ipv6,
|
||||
K_THREAD_STACK_SIZEOF(
|
||||
net_app_dtls_stack_ipv6));
|
||||
if (ret < 0) {
|
||||
LOG_ERR("Cannot init IPv6 UDP client (%d)", ret);
|
||||
}
|
||||
}
|
||||
|
||||
if (IS_ENABLED(CONFIG_NET_IPV4)) {
|
||||
k_delayed_work_init(&conf.ipv4.recv, wait_reply);
|
||||
|
||||
ret = connect_udp(&udp4, CONFIG_NET_CONFIG_PEER_IPV4_ADDR,
|
||||
&conf.ipv4, dtls_result_ipv4,
|
||||
sizeof(dtls_result_ipv4),
|
||||
net_app_dtls_stack_ipv4,
|
||||
K_THREAD_STACK_SIZEOF(
|
||||
net_app_dtls_stack_ipv4));
|
||||
if (ret < 0) {
|
||||
LOG_ERR("Cannot init IPv4 UDP client (%d)", ret);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void stop_udp(void)
|
||||
{
|
||||
if (IS_ENABLED(CONFIG_NET_IPV6)) {
|
||||
net_app_close(&udp6);
|
||||
net_app_release(&udp6);
|
||||
}
|
||||
|
||||
if (IS_ENABLED(CONFIG_NET_IPV4)) {
|
||||
net_app_close(&udp4);
|
||||
net_app_release(&udp4);
|
||||
}
|
||||
}
|
|
@ -1,115 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2018 Intel Corporation.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <logging/log.h>
|
||||
LOG_MODULE_DECLARE(net_echo_client_sample, LOG_LEVEL_DBG);
|
||||
|
||||
#include <zephyr.h>
|
||||
|
||||
#include <net/ethernet.h>
|
||||
|
||||
/* User data for the interface callback */
|
||||
struct ud {
|
||||
struct net_if *first;
|
||||
struct net_if *second;
|
||||
struct net_if *third;
|
||||
};
|
||||
|
||||
static void iface_cb(struct net_if *iface, void *user_data)
|
||||
{
|
||||
struct ud *ud = user_data;
|
||||
|
||||
if (net_if_l2(iface) != &NET_L2_GET_NAME(ETHERNET)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!ud->first) {
|
||||
ud->first = iface;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!ud->second) {
|
||||
ud->second = iface;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!ud->third) {
|
||||
ud->third = iface;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
static int setup_iface(struct net_if *iface, const char *ipv6_addr,
|
||||
const char *ipv4_addr, u16_t vlan_tag)
|
||||
{
|
||||
struct net_if_addr *ifaddr;
|
||||
struct in_addr addr4;
|
||||
struct in6_addr addr6;
|
||||
int ret;
|
||||
|
||||
ret = net_eth_vlan_enable(iface, vlan_tag);
|
||||
if (ret < 0) {
|
||||
LOG_ERR("Cannot enable VLAN for tag %d (%d)", vlan_tag, ret);
|
||||
}
|
||||
|
||||
if (net_addr_pton(AF_INET6, ipv6_addr, &addr6)) {
|
||||
LOG_ERR("Invalid address: %s", ipv6_addr);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ifaddr = net_if_ipv6_addr_add(iface, &addr6, NET_ADDR_MANUAL, 0);
|
||||
if (!ifaddr) {
|
||||
LOG_ERR("Cannot add %s to interface %p", ipv6_addr, iface);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (net_addr_pton(AF_INET, ipv4_addr, &addr4)) {
|
||||
LOG_ERR("Invalid address: %s", ipv6_addr);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ifaddr = net_if_ipv4_addr_add(iface, &addr4, NET_ADDR_MANUAL, 0);
|
||||
if (!ifaddr) {
|
||||
LOG_ERR("Cannot add %s to interface %p", ipv4_addr, iface);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
LOG_DBG("Interface %p VLAN tag %d setup done.", iface, vlan_tag);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int init_vlan(void)
|
||||
{
|
||||
struct ud ud;
|
||||
int ret;
|
||||
|
||||
memset(&ud, 0, sizeof(ud));
|
||||
|
||||
net_if_foreach(iface_cb, &ud);
|
||||
|
||||
/* This sample has two VLANs. For the second one we need to manually
|
||||
* create IP address for this test. But first the VLAN needs to be
|
||||
* added to the interface so that IPv6 DAD can work properly.
|
||||
*/
|
||||
ret = setup_iface(ud.second,
|
||||
CONFIG_NET_SAMPLE_IFACE2_MY_IPV6_ADDR,
|
||||
CONFIG_NET_SAMPLE_IFACE2_MY_IPV4_ADDR,
|
||||
CONFIG_NET_SAMPLE_IFACE2_VLAN_TAG);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = setup_iface(ud.third,
|
||||
CONFIG_NET_SAMPLE_IFACE3_MY_IPV6_ADDR,
|
||||
CONFIG_NET_SAMPLE_IFACE3_MY_IPV4_ADDR,
|
||||
CONFIG_NET_SAMPLE_IFACE3_VLAN_TAG);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
cmake_minimum_required(VERSION 3.13.1)
|
||||
|
||||
macro(set_conf_file)
|
||||
if(EXISTS ${APPLICATION_SOURCE_DIR}/prj_${BOARD}.conf)
|
||||
set(CONF_FILE "${APPLICATION_SOURCE_DIR}/prj_${BOARD}.conf")
|
||||
elseif(EXISTS ${APPLICATION_SOURCE_DIR}/boards/${BOARD}.conf)
|
||||
set(CONF_FILE
|
||||
"prj.conf ${APPLICATION_SOURCE_DIR}/boards/${BOARD}.conf")
|
||||
else()
|
||||
set(CONF_FILE "prj.conf")
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
|
||||
project(echo_server)
|
||||
|
||||
target_sources( app PRIVATE src/echo-server.c)
|
||||
target_sources_ifdef(CONFIG_NET_UDP app PRIVATE src/udp.c)
|
||||
target_sources_ifdef(CONFIG_NET_TCP app PRIVATE src/tcp.c)
|
||||
target_sources_ifdef(CONFIG_NET_VLAN app PRIVATE src/vlan.c)
|
||||
|
||||
include($ENV{ZEPHYR_BASE}/samples/net/common/common.cmake)
|
|
@ -1,49 +0,0 @@
|
|||
# Kconfig - Private config options for echo-server sample app
|
||||
|
||||
#
|
||||
# Copyright (c) 2018 Intel Corporation
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
|
||||
mainmenu "Networking echo-server sample application"
|
||||
|
||||
config NET_SAMPLE_IFACE2_MY_IPV6_ADDR
|
||||
string "My IPv6 address for second interface"
|
||||
help
|
||||
The value depends on your network setup.
|
||||
|
||||
config NET_SAMPLE_IFACE2_MY_IPV4_ADDR
|
||||
string "My IPv4 address for second interface"
|
||||
help
|
||||
The value depends on your network setup.
|
||||
|
||||
config NET_SAMPLE_IFACE2_VLAN_TAG
|
||||
int "VLAN tag for second interface"
|
||||
default 100
|
||||
range 0 4094
|
||||
depends on NET_VLAN
|
||||
help
|
||||
Set VLAN (virtual LAN) tag (id) that is used in the sample
|
||||
application.
|
||||
|
||||
config NET_SAMPLE_IFACE3_MY_IPV6_ADDR
|
||||
string "My IPv6 address for third interface"
|
||||
help
|
||||
The value depends on your network setup.
|
||||
|
||||
config NET_SAMPLE_IFACE3_MY_IPV4_ADDR
|
||||
string "My IPv4 address for third interface"
|
||||
help
|
||||
The value depends on your network setup.
|
||||
|
||||
config NET_SAMPLE_IFACE3_VLAN_TAG
|
||||
int "VLAN tag for third interface"
|
||||
default 200
|
||||
range 0 4094
|
||||
depends on NET_VLAN
|
||||
help
|
||||
Set VLAN (virtual LAN) tag (id) that is used in the sample
|
||||
application.
|
||||
|
||||
source "Kconfig.zephyr"
|
|
@ -1,114 +0,0 @@
|
|||
.. _echo-server-sample:
|
||||
|
||||
Echo Server
|
||||
###########
|
||||
|
||||
Overview
|
||||
********
|
||||
|
||||
The echo-server sample application for Zephyr implements a UDP/TCP server
|
||||
that complements the echo-client sample application: the echo-server listens
|
||||
for incoming IPv4 or IPv6 packets (sent by the echo client) and simply sends
|
||||
them back.
|
||||
|
||||
The source code for this sample application can be found at:
|
||||
:file:`samples/net/echo_server`.
|
||||
|
||||
Requirements
|
||||
************
|
||||
|
||||
- :ref:`networking_with_qemu`
|
||||
|
||||
Building and Running
|
||||
********************
|
||||
|
||||
There are multiple ways to use this application. One of the most common
|
||||
usage scenario is to run echo-server application inside QEMU. This is
|
||||
described in :ref:`networking_with_qemu`.
|
||||
|
||||
There are configuration files for different boards and setups in the
|
||||
echo-server directory:
|
||||
|
||||
- :file:`prj.conf`
|
||||
Generic config file, normally you should use this.
|
||||
|
||||
- :file:`overlay-frdm_k64f_mcr20a.conf`
|
||||
This overlay config enables support for IEEE 802.15.4 mcr20a and frdm_k64f
|
||||
|
||||
- :file:`overlay-ot.conf`
|
||||
This overlay config enables support for OpenThread.
|
||||
|
||||
- :file:`overlay-802154.conf`
|
||||
This overlay config enables support for native IEEE 802.15.4 connectivity.
|
||||
Note, that by default IEEE 802.15.4 L2 uses unacknowledged communication. To
|
||||
improve connection reliability, acknowledgments can be enabled with shell
|
||||
command: ``ieee802154 ack set``.
|
||||
|
||||
- :file:`overlay-enc28j60.conf`
|
||||
This overlay config enables support for enc28j60 ethernet board. This
|
||||
add-on board can be used for example with Arduino 101 board.
|
||||
|
||||
- :file:`overlay-cc2520.conf`
|
||||
This overlay config enables support for IEEE 802.15.4 cc2520 chip.
|
||||
|
||||
- :file:`overlay-bt.conf`
|
||||
This overlay config enables support for Bluetooth IPSP connectivity.
|
||||
|
||||
- :file:`overlay-qemu_802154.conf`
|
||||
This overlay config enables support for two QEMU's when simulating
|
||||
IEEE 802.15.4 network that are connected together.
|
||||
|
||||
- :file:`overlay-tls.conf`
|
||||
This overlay config enables support for TLS.
|
||||
|
||||
- :file:`overlay-netusb.conf`
|
||||
This overlay config enables support for Ethernet over USB setup with
|
||||
supported boards. The setup is described in :ref:`usb_device_networking_setup`
|
||||
|
||||
Build echo-server sample application like this:
|
||||
|
||||
.. zephyr-app-commands::
|
||||
:zephyr-app: samples/net/echo_server
|
||||
:board: <board to use>
|
||||
:conf: <config file to use>
|
||||
:goals: build
|
||||
:compact:
|
||||
|
||||
Example building for the FRDM-K64F with TI CC2520 support:
|
||||
|
||||
.. zephyr-app-commands::
|
||||
:zephyr-app: samples/net/echo_server
|
||||
:host-os: unix
|
||||
:board: frdm_k64f
|
||||
:conf: "prj.conf overlay-frdm_k64f_cc2520.conf"
|
||||
:goals: run
|
||||
:compact:
|
||||
|
||||
Make can select the default configuration file based on the BOARD you've
|
||||
specified automatically so you might not always need to mention it.
|
||||
|
||||
Running echo-client in Linux Host
|
||||
=================================
|
||||
|
||||
There is one useful testing scenario that can be used with Linux host.
|
||||
Here echo-server is run in QEMU and echo-client is run in Linux host.
|
||||
|
||||
To use QEMU for testing, follow the :ref:`networking_with_qemu` guide.
|
||||
|
||||
Run echo-server application in QEMU:
|
||||
|
||||
.. zephyr-app-commands::
|
||||
:zephyr-app: samples/net/echo_server
|
||||
:host-os: unix
|
||||
:board: qemu_x86
|
||||
:goals: run
|
||||
:compact:
|
||||
|
||||
In a terminal window:
|
||||
|
||||
.. code-block:: console
|
||||
|
||||
$ sudo ./echo-client -i tap0 2001:db8::1
|
||||
|
||||
Note that echo-server must be running in QEMU before you start the
|
||||
echo-client application in host terminal window.
|
|
@ -1,21 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2019 Linaro Limited
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
&spi1 {
|
||||
status = "ok";
|
||||
cs-gpios = <&gpio0 0 0>;
|
||||
|
||||
enc28j60@0 {
|
||||
compatible = "microchip,enc28j60";
|
||||
spi-port-name = "SPI_1";
|
||||
local-mac-address = [00 00 00 00 00 00];
|
||||
spi-max-frequency = <128000>;
|
||||
int-gpios = <&gpio0 19 1>;
|
||||
status = "ok";
|
||||
label = "ETH_0";
|
||||
reg = <0>;
|
||||
};
|
||||
};
|
|
@ -1,24 +0,0 @@
|
|||
CONFIG_NET_IPV4=n
|
||||
CONFIG_NET_6LO=y
|
||||
|
||||
CONFIG_NET_L2_IEEE802154=y
|
||||
CONFIG_NET_L2_IEEE802154_FRAGMENT=y
|
||||
CONFIG_NET_L2_IEEE802154_FRAGMENT_REASS_CACHE_SIZE=2
|
||||
|
||||
# For Wireshark filtering in a busy environment it is useful to set a unique
|
||||
# PAN ID
|
||||
#CONFIG_NET_CONFIG_IEEE802154_PAN_ID=0xbeef
|
||||
|
||||
CONFIG_NET_L2_IEEE802154_SECURITY=n
|
||||
CONFIG_NET_L2_IEEE802154_SHELL=y
|
||||
|
||||
CONFIG_IEEE802154_KW41Z=y
|
||||
|
||||
CONFIG_NET_CONFIG_MY_IPV6_ADDR="2001:db8::2"
|
||||
CONFIG_NET_CONFIG_PEER_IPV6_ADDR="2001:db8::1"
|
||||
CONFIG_NET_CONFIG_IEEE802154_DEV_NAME="KW41Z"
|
||||
|
||||
CONFIG_FLASH=y
|
||||
CONFIG_FLASH_PAGE_LAYOUT=y
|
||||
CONFIG_CPLUSPLUS=y
|
||||
CONFIG_REBOOT=y
|
|
@ -1 +0,0 @@
|
|||
CONFIG_NET_STATISTICS=n
|
|
@ -1,16 +0,0 @@
|
|||
CONFIG_BT=n
|
||||
|
||||
# Disable TCP and IPv4 (TCP disabled to avoid heavy traffic)
|
||||
CONFIG_NET_TCP=n
|
||||
CONFIG_NET_IPV4=n
|
||||
|
||||
CONFIG_NET_CONFIG_NEED_IPV6=y
|
||||
CONFIG_NET_CONFIG_NEED_IPV4=n
|
||||
CONFIG_NET_CONFIG_MY_IPV4_ADDR=""
|
||||
CONFIG_NET_CONFIG_PEER_IPV4_ADDR=""
|
||||
|
||||
CONFIG_NET_L2_IEEE802154=y
|
||||
CONFIG_NET_L2_IEEE802154_SHELL=y
|
||||
CONFIG_NET_L2_IEEE802154_LOG_LEVEL_INF=y
|
||||
|
||||
CONFIG_NET_CONFIG_IEEE802154_CHANNEL=26
|
|
@ -1,10 +0,0 @@
|
|||
CONFIG_BT=y
|
||||
CONFIG_BT_DEVICE_NAME="Zephyr Echo Server"
|
||||
CONFIG_BT_DEBUG_LOG=y
|
||||
CONFIG_BT_DEBUG_L2CAP=y
|
||||
CONFIG_BT_SMP=y
|
||||
CONFIG_BT_SIGNING=y
|
||||
CONFIG_BT_PERIPHERAL=y
|
||||
CONFIG_BT_L2CAP_DYNAMIC_CHANNEL=y
|
||||
CONFIG_NET_L2_BT=y
|
||||
CONFIG_NET_CONFIG_BT_NODE=y
|
|
@ -1,7 +0,0 @@
|
|||
CONFIG_NET_L2_IEEE802154=y
|
||||
|
||||
CONFIG_IEEE802154_CC2520=y
|
||||
CONFIG_IEEE802154_CC2520_AUTO_ACK=y
|
||||
|
||||
CONFIG_NET_CONFIG_MY_IPV6_ADDR="2001:db8::2"
|
||||
CONFIG_NET_CONFIG_IEEE802154_DEV_NAME="cc2520"
|
|
@ -1,10 +0,0 @@
|
|||
CONFIG_NET_L2_ETHERNET=y
|
||||
CONFIG_NET_QEMU_ETHERNET=y
|
||||
|
||||
CONFIG_ETH_E1000=y
|
||||
|
||||
CONFIG_PCI_ENUMERATION=y
|
||||
CONFIG_PCI=y
|
||||
|
||||
#CONFIG_PCI_DEBUG=y
|
||||
#CONFIG_ETHERNET_LOG_LEVEL_DBG=y
|
|
@ -1,7 +0,0 @@
|
|||
# ENC28J60 is L2 chip slave on SPI
|
||||
CONFIG_SPI=y
|
||||
CONFIG_NET_L2_ETHERNET=y
|
||||
|
||||
# ENC28J60 Ethernet Device
|
||||
CONFIG_ETH_ENC28J60=y
|
||||
CONFIG_ETH_ENC28J60_0=y
|
|
@ -1,11 +0,0 @@
|
|||
CONFIG_NET_L2_ETHERNET=n
|
||||
|
||||
CONFIG_NET_L2_IEEE802154=y
|
||||
CONFIG_NET_L2_IEEE802154_SHELL=y
|
||||
|
||||
CONFIG_GPIO=y
|
||||
CONFIG_SPI=y
|
||||
CONFIG_SPI_0=y
|
||||
|
||||
CONFIG_IEEE802154_MCR20A=y
|
||||
CONFIG_NET_CONFIG_IEEE802154_DEV_NAME="mcr20a"
|
|
@ -1,14 +0,0 @@
|
|||
# USB Device settings
|
||||
CONFIG_USB=y
|
||||
CONFIG_USB_DEVICE_STACK=y
|
||||
|
||||
# Select USB Configurations
|
||||
CONFIG_USB_DEVICE_NETWORK_ECM=y
|
||||
|
||||
# Logging
|
||||
CONFIG_USB_DRIVER_LOG_LEVEL_INF=y
|
||||
CONFIG_USB_DEVICE_LOG_LEVEL_INF=y
|
||||
CONFIG_INIT_STACKS=n
|
||||
|
||||
# Disable shell built-in commands to reduce ROM footprint
|
||||
CONFIG_SHELL_CMDS=n
|
|
@ -1,52 +0,0 @@
|
|||
CONFIG_CPLUSPLUS=y
|
||||
|
||||
CONFIG_BT=n
|
||||
|
||||
# Disable TCP and IPv4 (TCP disabled to avoid heavy traffic)
|
||||
CONFIG_NET_TCP=n
|
||||
CONFIG_NET_IPV4=n
|
||||
|
||||
CONFIG_NET_IPV6_NBR_CACHE=n
|
||||
CONFIG_NET_IPV6_MLD=n
|
||||
CONFIG_NET_CONFIG_NEED_IPV6=y
|
||||
CONFIG_NET_CONFIG_NEED_IPV4=n
|
||||
CONFIG_NET_CONFIG_MY_IPV4_ADDR=""
|
||||
CONFIG_NET_CONFIG_PEER_IPV4_ADDR=""
|
||||
|
||||
CONFIG_MAIN_STACK_SIZE=2048
|
||||
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048
|
||||
CONFIG_NET_TX_STACK_SIZE=2048
|
||||
CONFIG_NET_RX_STACK_SIZE=5120
|
||||
CONFIG_SHELL_STACK_SIZE=3072
|
||||
|
||||
# Disable conflicting IEEE802154 L2
|
||||
CONFIG_NET_L2_IEEE802154=n
|
||||
CONFIG_NET_L2_IEEE802154_SHELL=n
|
||||
|
||||
CONFIG_NET_L2_OPENTHREAD=y
|
||||
|
||||
CONFIG_OPENTHREAD_DEBUG=y
|
||||
CONFIG_OPENTHREAD_L2_DEBUG=y
|
||||
CONFIG_OPENTHREAD_L2_LOG_LEVEL_INF=y
|
||||
|
||||
CONFIG_OPENTHREAD_CHANNEL=26
|
||||
|
||||
# We need a bit more buffers for OT
|
||||
CONFIG_NET_PKT_RX_COUNT=50
|
||||
CONFIG_NET_PKT_TX_COUNT=50
|
||||
CONFIG_NET_BUF_RX_COUNT=50
|
||||
CONFIG_NET_BUF_TX_COUNT=50
|
||||
|
||||
CONFIG_NET_CONFIG_MY_IPV6_ADDR="fdde:ad00:beef::2"
|
||||
CONFIG_NET_CONFIG_PEER_IPV6_ADDR="fdde:ad00:beef::1"
|
||||
|
||||
# Thread by default registers quite a lot addresses.
|
||||
CONFIG_NET_IF_UNICAST_IPV6_ADDR_COUNT=6
|
||||
CONFIG_NET_IF_MCAST_IPV6_ADDR_COUNT=8
|
||||
|
||||
# Other OpenThread dependencies (flash for OT persistent storage)
|
||||
CONFIG_FLASH=y
|
||||
CONFIG_FLASH_PAGE_LAYOUT=y
|
||||
CONFIG_MPU_ALLOW_FLASH_WRITE=y
|
||||
|
||||
CONFIG_REBOOT=y
|
|
@ -1,16 +0,0 @@
|
|||
CONFIG_NET_IPV4=n
|
||||
|
||||
CONFIG_NET_L2_IEEE802154=y
|
||||
|
||||
CONFIG_IEEE802154_UPIPE=y
|
||||
CONFIG_NET_DEBUG_L2_IEEE802154_DISPLAY_PACKET=n
|
||||
|
||||
CONFIG_NET_L2_IEEE802154_SHELL=y
|
||||
|
||||
# This prevents automatic creation of ethernet interface as we
|
||||
# do not have SLIP in use in this test.
|
||||
CONFIG_NET_TEST=y
|
||||
|
||||
# This sample uses more stack so update the values
|
||||
CONFIG_MAIN_STACK_SIZE=2000
|
||||
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2000
|
|
@ -1,7 +0,0 @@
|
|||
CONFIG_NET_L2_ETHERNET=y
|
||||
CONFIG_NET_QEMU_ETHERNET=y
|
||||
|
||||
CONFIG_ETH_STELLARIS=y
|
||||
|
||||
CONFIG_NET_SLIP_TAP=n
|
||||
CONFIG_SLIP=n
|
|
@ -1,6 +0,0 @@
|
|||
CONFIG_NET_L2_ETHERNET=y
|
||||
CONFIG_NET_QEMU_ETHERNET=y
|
||||
|
||||
CONFIG_ETH_SMSC911X=y
|
||||
|
||||
#CONFIG_ETHERNET_LOG_LEVEL_DBG=y
|
|
@ -1,4 +0,0 @@
|
|||
CONFIG_MBEDTLS=y
|
||||
CONFIG_MBEDTLS_BUILTIN=y
|
||||
CONFIG_MBEDTLS_ENABLE_HEAP=y
|
||||
CONFIG_MBEDTLS_HEAP_SIZE=30000
|
|
@ -1,26 +0,0 @@
|
|||
CONFIG_NET_VLAN=y
|
||||
|
||||
# We have one non-vlan interface and two VLAN interfaces
|
||||
CONFIG_NET_VLAN_COUNT=3
|
||||
|
||||
# There will be three network interfaces.
|
||||
|
||||
# First ethernet interface will use these settings
|
||||
CONFIG_NET_CONFIG_MY_IPV6_ADDR="2001:db8::1"
|
||||
CONFIG_NET_CONFIG_PEER_IPV6_ADDR="2001:db8::2"
|
||||
CONFIG_NET_CONFIG_MY_IPV4_ADDR="192.0.2.1"
|
||||
CONFIG_NET_CONFIG_PEER_IPV4_ADDR="192.0.2.2"
|
||||
|
||||
# Second ethernet interface will have these settings
|
||||
CONFIG_NET_SAMPLE_IFACE2_MY_IPV6_ADDR="2001:db8:100::1"
|
||||
# TEST-NET-2 from RFC 5737
|
||||
CONFIG_NET_SAMPLE_IFACE2_MY_IPV4_ADDR="198.51.100.1"
|
||||
# VLAN tag for the second interface
|
||||
CONFIG_NET_SAMPLE_IFACE2_VLAN_TAG=100
|
||||
|
||||
# Settings for the third network interface
|
||||
CONFIG_NET_SAMPLE_IFACE3_MY_IPV6_ADDR="2001:db8:200::1"
|
||||
# TEST-NET-3 from RFC 5737
|
||||
CONFIG_NET_SAMPLE_IFACE3_MY_IPV4_ADDR="203.0.113.1"
|
||||
# VLAN tag for the second interface
|
||||
CONFIG_NET_SAMPLE_IFACE3_VLAN_TAG=200
|
|
@ -1,43 +0,0 @@
|
|||
# Generic networking options
|
||||
CONFIG_NETWORKING=y
|
||||
CONFIG_NET_UDP=y
|
||||
CONFIG_NET_TCP=y
|
||||
CONFIG_NET_IPV6=y
|
||||
CONFIG_NET_IPV4=y
|
||||
#CONFIG_NET_DHCPV4=y
|
||||
|
||||
# Kernel options
|
||||
CONFIG_ENTROPY_GENERATOR=y
|
||||
CONFIG_TEST_RANDOM_GENERATOR=y
|
||||
CONFIG_INIT_STACKS=y
|
||||
|
||||
# Logging
|
||||
CONFIG_NET_LOG=y
|
||||
CONFIG_LOG=y
|
||||
CONFIG_NET_STATISTICS=y
|
||||
CONFIG_PRINTK=y
|
||||
|
||||
# Network buffers
|
||||
CONFIG_NET_PKT_RX_COUNT=14
|
||||
CONFIG_NET_PKT_TX_COUNT=14
|
||||
CONFIG_NET_BUF_RX_COUNT=36
|
||||
CONFIG_NET_BUF_TX_COUNT=36
|
||||
CONFIG_NET_CONTEXT_NET_PKT_POOL=y
|
||||
|
||||
# IP address options
|
||||
CONFIG_NET_IF_UNICAST_IPV6_ADDR_COUNT=3
|
||||
CONFIG_NET_IF_MCAST_IPV6_ADDR_COUNT=4
|
||||
CONFIG_NET_MAX_CONTEXTS=10
|
||||
|
||||
# Network shell
|
||||
CONFIG_NET_SHELL=y
|
||||
|
||||
# Network application options and configuration
|
||||
CONFIG_NET_APP_SERVER=y
|
||||
CONFIG_NET_CONFIG_SETTINGS=y
|
||||
CONFIG_NET_CONFIG_NEED_IPV6=y
|
||||
CONFIG_NET_CONFIG_NEED_IPV4=y
|
||||
CONFIG_NET_CONFIG_MY_IPV6_ADDR="2001:db8::1"
|
||||
CONFIG_NET_CONFIG_PEER_IPV6_ADDR="2001:db8::2"
|
||||
CONFIG_NET_CONFIG_MY_IPV4_ADDR="192.0.2.1"
|
||||
CONFIG_NET_CONFIG_PEER_IPV4_ADDR="192.0.2.2"
|
|
@ -1,64 +0,0 @@
|
|||
common:
|
||||
harness: net
|
||||
tags: net
|
||||
sample:
|
||||
description: Test core network features using a client/server
|
||||
sample
|
||||
name: Echo Server
|
||||
tests:
|
||||
test:
|
||||
platform_whitelist: qemu_x86 sam_e70_xplained frdm_k64f
|
||||
qemu_cortex_m3 frdm_kw41z
|
||||
test_802154:
|
||||
extra_args: OVERLAY_CONFIG="overlay-qemu_802154.conf"
|
||||
platform_whitelist: qemu_x86
|
||||
test_bt:
|
||||
extra_args: OVERLAY_CONFIG="overlay-bt.conf"
|
||||
platform_whitelist: qemu_x86
|
||||
tags: bluetooth
|
||||
test_mcr20a:
|
||||
extra_args: OVERLAY_CONFIG="overlay-frdm_k64f_mcr20a.conf"
|
||||
platform_whitelist: frdm_k64f
|
||||
test_nrf_802154:
|
||||
extra_args: OVERLAY_CONFIG="overlay-802154.conf"
|
||||
platform_whitelist: nrf52840_pca10056
|
||||
test_usbnet:
|
||||
harness: net
|
||||
extra_args: OVERLAY_CONFIG="overlay-netusb.conf"
|
||||
platform_whitelist: quark_se_c1000_devboard 96b_carbon
|
||||
extra_configs:
|
||||
- CONFIG_NET_SHELL=n
|
||||
tags: net usb
|
||||
test_usbnet_composite:
|
||||
harness: net
|
||||
extra_args: OVERLAY_CONFIG="overlay-netusb.conf"
|
||||
extra_configs:
|
||||
- CONFIG_USB_COMPOSITE_DEVICE=y
|
||||
platform_whitelist: quark_se_c1000_devboard 96b_carbon
|
||||
tags: net usb
|
||||
test_nrf_openthread:
|
||||
extra_args: OVERLAY_CONFIG="overlay-ot.conf"
|
||||
slow: true
|
||||
tags: net openthread
|
||||
platform_whitelist: nrf52840_pca10056
|
||||
test_kw41z_openthread:
|
||||
extra_args: OVERLAY_CONFIG="overlay-ot.conf"
|
||||
slow: true
|
||||
tags: net openthread
|
||||
platform_whitelist: frdm_kw41z
|
||||
test_enc28j60:
|
||||
extra_args: OVERLAY_CONFIG="overlay-enc28j60.conf"
|
||||
tags: net enc28j60
|
||||
platform_whitelist: arduino_101
|
||||
test_e1000:
|
||||
extra_args: OVERLAY_CONFIG="overlay-e1000.conf"
|
||||
tags: net
|
||||
platform_whitelist: qemu_x86
|
||||
test_stellaris:
|
||||
extra_args: OVERLAY_CONFIG="overlay-qemu_cortex_m3_eth.conf"
|
||||
tags: net
|
||||
platform_whitelist: qemu_cortex_m3
|
||||
test_smsc911x:
|
||||
extra_args: OVERLAY_CONFIG="overlay-smsc911x.conf"
|
||||
tags: net
|
||||
platform_whitelist: mps2_an385
|
|
@ -1,33 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2017 Intel Corporation.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#define MY_PORT 4242
|
||||
|
||||
#define MAX_DBG_PRINT 64
|
||||
|
||||
void start_udp(void);
|
||||
void stop_udp(void);
|
||||
|
||||
void start_tcp(void);
|
||||
void stop_tcp(void);
|
||||
|
||||
struct net_pkt *build_reply_pkt(const char *name,
|
||||
struct net_app_ctx *ctx,
|
||||
struct net_pkt *pkt,
|
||||
u8_t proto_len);
|
||||
void pkt_sent(struct net_app_ctx *ctx, int status,
|
||||
void *token, void *user_data);
|
||||
void panic(const char *msg);
|
||||
void quit(void);
|
||||
|
||||
#if defined(CONFIG_NET_VLAN)
|
||||
int init_vlan(void);
|
||||
#else
|
||||
static inline int init_vlan(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#endif /* CONFIG_NET_VLAN */
|
|
@ -1,148 +0,0 @@
|
|||
/* echo.c - Networking echo server */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2016 Intel Corporation.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <logging/log.h>
|
||||
LOG_MODULE_REGISTER(net_echo_server_sample, LOG_LEVEL_DBG);
|
||||
|
||||
#include <zephyr.h>
|
||||
#include <linker/sections.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <net/net_pkt.h>
|
||||
#include <net/net_core.h>
|
||||
#include <net/net_context.h>
|
||||
#include <net/net_app.h>
|
||||
|
||||
#include "common.h"
|
||||
|
||||
/* The startup time needs to be longish if DHCP is enabled as setting
|
||||
* DHCP up takes some time.
|
||||
*/
|
||||
#define APP_STARTUP_TIME K_SECONDS(20)
|
||||
|
||||
#define BUF_TIMEOUT K_MSEC(100)
|
||||
|
||||
#define APP_BANNER "Run echo server"
|
||||
|
||||
static struct k_sem quit_lock;
|
||||
|
||||
void panic(const char *msg)
|
||||
{
|
||||
if (msg) {
|
||||
LOG_ERR("%s", msg);
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
k_sleep(K_FOREVER);
|
||||
}
|
||||
}
|
||||
|
||||
void quit(void)
|
||||
{
|
||||
k_sem_give(&quit_lock);
|
||||
}
|
||||
|
||||
struct net_pkt *build_reply_pkt(const char *name,
|
||||
struct net_app_ctx *ctx,
|
||||
struct net_pkt *pkt,
|
||||
u8_t proto_len)
|
||||
{
|
||||
struct net_pkt *reply_pkt;
|
||||
struct net_buf *frag;
|
||||
int header_len = 0;
|
||||
int recv_len;
|
||||
int ret;
|
||||
|
||||
LOG_INF("%s received %d bytes", name, net_pkt_appdatalen(pkt));
|
||||
|
||||
if (net_pkt_appdatalen(pkt) == 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
reply_pkt = net_app_get_net_pkt(ctx, net_pkt_family(pkt), BUF_TIMEOUT);
|
||||
if (!reply_pkt) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
NET_ASSERT(net_pkt_family(reply_pkt) == net_pkt_family(pkt));
|
||||
|
||||
recv_len = net_pkt_get_len(pkt);
|
||||
|
||||
/* If we have link layer headers, then get rid of them here. */
|
||||
if (recv_len != net_pkt_appdatalen(pkt)) {
|
||||
/* First fragment will contain IP header so move the data
|
||||
* down in order to get rid of it.
|
||||
*/
|
||||
header_len = net_pkt_ip_hdr_len(pkt);
|
||||
header_len += net_pkt_ipv6_ext_len(pkt);
|
||||
header_len += proto_len;
|
||||
|
||||
ret = net_pkt_pull(pkt, 0, header_len);
|
||||
if (ret != 0) {
|
||||
net_pkt_unref(reply_pkt);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
net_pkt_set_appdatalen(reply_pkt, net_pkt_appdatalen(pkt));
|
||||
|
||||
frag = net_pkt_copy_all(pkt, 0, BUF_TIMEOUT);
|
||||
if (!frag) {
|
||||
LOG_ERR("Failed to copy all data");
|
||||
net_pkt_unref(reply_pkt);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
net_pkt_frag_add(reply_pkt, frag);
|
||||
|
||||
return reply_pkt;
|
||||
}
|
||||
|
||||
void pkt_sent(struct net_app_ctx *ctx,
|
||||
int status,
|
||||
void *user_data_send,
|
||||
void *user_data)
|
||||
{
|
||||
if (!status) {
|
||||
LOG_INF("Sent %d bytes", POINTER_TO_UINT(user_data_send));
|
||||
}
|
||||
}
|
||||
|
||||
static inline int init_app(void)
|
||||
{
|
||||
k_sem_init(&quit_lock, 0, UINT_MAX);
|
||||
|
||||
init_vlan();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void main(void)
|
||||
{
|
||||
init_app();
|
||||
|
||||
if (IS_ENABLED(CONFIG_NET_TCP)) {
|
||||
start_tcp();
|
||||
}
|
||||
|
||||
if (IS_ENABLED(CONFIG_NET_UDP)) {
|
||||
start_udp();
|
||||
}
|
||||
|
||||
k_sem_take(&quit_lock, K_FOREVER);
|
||||
|
||||
LOG_INF("Stopping...");
|
||||
|
||||
if (IS_ENABLED(CONFIG_NET_TCP)) {
|
||||
stop_tcp();
|
||||
}
|
||||
|
||||
if (IS_ENABLED(CONFIG_NET_UDP)) {
|
||||
stop_udp();
|
||||
}
|
||||
}
|
|
@ -1,195 +0,0 @@
|
|||
/* tcp.c - TCP specific code for echo server */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2017 Intel Corporation.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <logging/log.h>
|
||||
LOG_MODULE_DECLARE(net_echo_server_sample, LOG_LEVEL_DBG);
|
||||
|
||||
#include <zephyr.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <net/net_pkt.h>
|
||||
#include <net/net_core.h>
|
||||
#include <net/net_context.h>
|
||||
|
||||
#include <net/net_app.h>
|
||||
|
||||
#include "common.h"
|
||||
|
||||
static struct net_app_ctx tcp;
|
||||
|
||||
/* Note that both tcp and udp can share the same pool but in this
|
||||
* example the UDP context and TCP context have separate pools.
|
||||
*/
|
||||
#if defined(CONFIG_NET_CONTEXT_NET_PKT_POOL)
|
||||
NET_PKT_TX_SLAB_DEFINE(echo_tx_tcp, 15);
|
||||
NET_PKT_DATA_POOL_DEFINE(echo_data_tcp, 30);
|
||||
|
||||
static struct k_mem_slab *tx_tcp_slab(void)
|
||||
{
|
||||
return &echo_tx_tcp;
|
||||
}
|
||||
|
||||
static struct net_buf_pool *data_tcp_pool(void)
|
||||
{
|
||||
return &echo_data_tcp;
|
||||
}
|
||||
#else
|
||||
#define tx_tcp_slab NULL
|
||||
#define data_tcp_pool NULL
|
||||
#endif /* CONFIG_NET_CONTEXT_NET_PKT_POOL */
|
||||
|
||||
#if defined(CONFIG_NET_APP_TLS)
|
||||
|
||||
/* The result buf size is set to large enough so that we can receive max size
|
||||
* buf back. Note that mbedtls needs also be configured to have equal size
|
||||
* value for its buffer size. See MBEDTLS_SSL_MAX_CONTENT_LEN option in TLS
|
||||
* config file.
|
||||
*/
|
||||
#define RESULT_BUF_SIZE 1500
|
||||
static u8_t tls_result[RESULT_BUF_SIZE];
|
||||
|
||||
#if !defined(CONFIG_NET_APP_TLS_STACK_SIZE)
|
||||
#define CONFIG_NET_APP_TLS_STACK_SIZE 8192
|
||||
#endif /* CONFIG_NET_APP_TLS_STACK_SIZE */
|
||||
|
||||
#define APP_BANNER "Run TLS echo-server"
|
||||
#define INSTANCE_INFO "Zephyr TLS echo-server #1"
|
||||
|
||||
/* Note that each net_app context needs its own stack as there will be
|
||||
* a separate thread needed.
|
||||
*/
|
||||
NET_STACK_DEFINE(NET_APP_TLS, net_app_tls_stack,
|
||||
CONFIG_NET_APP_TLS_STACK_SIZE, CONFIG_NET_APP_TLS_STACK_SIZE);
|
||||
|
||||
#define RX_FIFO_DEPTH 4
|
||||
K_MEM_POOL_DEFINE(ssl_pool, 4, 64, RX_FIFO_DEPTH, 4);
|
||||
#endif /* CONFIG_NET_APP_TLS */
|
||||
|
||||
#if defined(CONFIG_NET_APP_TLS)
|
||||
/* Load the certificates and private RSA key. */
|
||||
|
||||
#include "test_certs.h"
|
||||
|
||||
static int setup_cert(struct net_app_ctx *ctx,
|
||||
mbedtls_x509_crt *cert,
|
||||
mbedtls_pk_context *pkey)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = mbedtls_x509_crt_parse(cert, rsa_example_cert_der,
|
||||
rsa_example_cert_der_len);
|
||||
if (ret != 0) {
|
||||
LOG_ERR("mbedtls_x509_crt_parse returned %d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = mbedtls_pk_parse_key(pkey, rsa_example_keypair_der,
|
||||
rsa_example_keypair_der_len, NULL, 0);
|
||||
if (ret != 0) {
|
||||
LOG_ERR("mbedtls_pk_parse_key returned %d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* CONFIG_NET_APP_TLS */
|
||||
|
||||
static void tcp_received(struct net_app_ctx *ctx,
|
||||
struct net_pkt *pkt,
|
||||
int status,
|
||||
void *user_data)
|
||||
{
|
||||
static char dbg[MAX_DBG_PRINT + 1];
|
||||
struct net_pkt *reply_pkt;
|
||||
sa_family_t family;
|
||||
int ret;
|
||||
|
||||
if (!pkt) {
|
||||
/* EOF condition */
|
||||
return;
|
||||
}
|
||||
|
||||
family = net_pkt_family(pkt);
|
||||
|
||||
snprintk(dbg, MAX_DBG_PRINT, "TCP IPv%c",
|
||||
family == AF_INET6 ? '6' : '4');
|
||||
|
||||
reply_pkt = build_reply_pkt(dbg, ctx, pkt, NET_TCPH_LEN);
|
||||
|
||||
net_pkt_unref(pkt);
|
||||
|
||||
if (!reply_pkt) {
|
||||
return;
|
||||
}
|
||||
|
||||
ret = net_app_send_pkt(ctx, reply_pkt, NULL, 0, K_NO_WAIT,
|
||||
UINT_TO_POINTER(net_pkt_get_len(reply_pkt)));
|
||||
if (ret < 0) {
|
||||
LOG_ERR("Cannot send data to peer (%d)", ret);
|
||||
net_pkt_unref(reply_pkt);
|
||||
|
||||
quit();
|
||||
}
|
||||
}
|
||||
|
||||
void start_tcp(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = net_app_init_tcp_server(&tcp, NULL, MY_PORT, NULL);
|
||||
if (ret < 0) {
|
||||
LOG_ERR("Cannot init TCP service at port %d", MY_PORT);
|
||||
return;
|
||||
}
|
||||
|
||||
#if defined(CONFIG_NET_CONTEXT_NET_PKT_POOL)
|
||||
net_app_set_net_pkt_pool(&tcp, tx_tcp_slab, data_tcp_pool);
|
||||
#endif
|
||||
|
||||
ret = net_app_set_cb(&tcp, NULL, tcp_received, NULL, NULL);
|
||||
if (ret < 0) {
|
||||
LOG_ERR("Cannot set callbacks (%d)", ret);
|
||||
net_app_release(&tcp);
|
||||
return;
|
||||
}
|
||||
|
||||
#if defined(CONFIG_NET_APP_TLS)
|
||||
ret = net_app_server_tls(&tcp,
|
||||
tls_result,
|
||||
sizeof(tls_result),
|
||||
APP_BANNER,
|
||||
INSTANCE_INFO,
|
||||
strlen(INSTANCE_INFO),
|
||||
setup_cert,
|
||||
NULL,
|
||||
&ssl_pool,
|
||||
net_app_tls_stack,
|
||||
K_THREAD_STACK_SIZEOF(net_app_tls_stack));
|
||||
if (ret < 0) {
|
||||
LOG_ERR("Cannot init TLS");
|
||||
}
|
||||
#endif
|
||||
|
||||
net_app_server_enable(&tcp);
|
||||
|
||||
ret = net_app_listen(&tcp);
|
||||
if (ret < 0) {
|
||||
LOG_ERR("Cannot wait connection (%d)", ret);
|
||||
net_app_release(&tcp);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void stop_tcp(void)
|
||||
{
|
||||
net_app_server_disable(&tcp);
|
||||
|
||||
net_app_close(&tcp);
|
||||
net_app_release(&tcp);
|
||||
}
|
|
@ -1,276 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2017 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#ifndef __TEST_CERTS_H__
|
||||
#define __TEST_CERTS_H__
|
||||
|
||||
/* Read the README file in net-tools repo how to generate
|
||||
* the key and the certificate.
|
||||
*/
|
||||
|
||||
/* This is the private key in pkcs#8 format. */
|
||||
static const unsigned char rsa_example_keypair_der[] = {
|
||||
0x30, 0x82, 0x04, 0xbe, 0x02, 0x01, 0x00, 0x30,
|
||||
0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7,
|
||||
0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x04, 0x82,
|
||||
0x04, 0xa8, 0x30, 0x82, 0x04, 0xa4, 0x02, 0x01,
|
||||
0x00, 0x02, 0x82, 0x01, 0x01, 0x00, 0xc6, 0x00,
|
||||
0x7b, 0x0d, 0xd1, 0x17, 0x43, 0x6b, 0xa9, 0xa7,
|
||||
0x79, 0x9c, 0x0f, 0x8d, 0x77, 0x91, 0xd2, 0xf7,
|
||||
0x47, 0x35, 0xb3, 0x17, 0xe2, 0xdd, 0xed, 0x6d,
|
||||
0x01, 0xf9, 0xb1, 0x92, 0xc9, 0x48, 0x80, 0xe0,
|
||||
0x1f, 0xcf, 0xb7, 0xa4, 0x5f, 0xf0, 0x36, 0xea,
|
||||
0xbf, 0xe1, 0x33, 0xf8, 0xa9, 0xc5, 0xe6, 0xd4,
|
||||
0x19, 0x8b, 0x82, 0x25, 0xd9, 0x19, 0x74, 0x70,
|
||||
0x79, 0xec, 0xc6, 0x68, 0xc9, 0xef, 0xce, 0x1a,
|
||||
0xa9, 0xf0, 0xb7, 0x01, 0x35, 0x91, 0xff, 0xd3,
|
||||
0x75, 0x6e, 0x02, 0xba, 0x06, 0x9a, 0x2a, 0xac,
|
||||
0xcf, 0x22, 0xbf, 0x2b, 0x1f, 0xc1, 0x72, 0x38,
|
||||
0x22, 0x35, 0xea, 0xda, 0x6f, 0xdd, 0x67, 0xa2,
|
||||
0x2b, 0x19, 0x38, 0x19, 0x0e, 0x44, 0xd1, 0x71,
|
||||
0x38, 0xb4, 0x6d, 0x26, 0x85, 0xd6, 0xc6, 0xbe,
|
||||
0xc1, 0x6f, 0x3c, 0xee, 0xaf, 0x94, 0x3c, 0x05,
|
||||
0x56, 0x4e, 0xad, 0x53, 0x81, 0x8b, 0xd4, 0x23,
|
||||
0x31, 0x69, 0x72, 0x27, 0x93, 0xb4, 0x3a, 0xac,
|
||||
0x23, 0xe8, 0x10, 0xae, 0xf5, 0x9f, 0x0b, 0xa6,
|
||||
0x6e, 0xd3, 0x73, 0xca, 0x18, 0x11, 0xca, 0xbe,
|
||||
0x71, 0x00, 0x56, 0x29, 0x34, 0x54, 0xcc, 0xda,
|
||||
0x29, 0x5b, 0x26, 0x29, 0x99, 0x4d, 0x5f, 0xa1,
|
||||
0xa6, 0xb9, 0xcb, 0x2b, 0xb2, 0x0f, 0x10, 0x00,
|
||||
0x04, 0xa9, 0x11, 0x2c, 0x48, 0xb1, 0x99, 0xa5,
|
||||
0xca, 0x7c, 0x67, 0xa5, 0xbe, 0x14, 0x20, 0x12,
|
||||
0xb7, 0x3b, 0x7a, 0x4f, 0xdc, 0xc7, 0xd5, 0x2d,
|
||||
0x04, 0x66, 0xbb, 0xf5, 0x0c, 0xcd, 0xf1, 0x32,
|
||||
0x39, 0xd7, 0x51, 0x9b, 0xba, 0xdb, 0xf1, 0xa7,
|
||||
0xfe, 0x2d, 0x9a, 0xe6, 0x9c, 0x6b, 0x54, 0xda,
|
||||
0xf1, 0xdd, 0x48, 0xf9, 0xd7, 0xf0, 0x35, 0x7c,
|
||||
0x8e, 0x24, 0x7e, 0x44, 0x2f, 0xf3, 0xbf, 0x39,
|
||||
0x0e, 0x96, 0xab, 0xe1, 0x45, 0x03, 0x8b, 0x54,
|
||||
0xdc, 0xe1, 0xb6, 0x11, 0x81, 0x21, 0x02, 0x03,
|
||||
0x01, 0x00, 0x01, 0x02, 0x82, 0x01, 0x01, 0x00,
|
||||
0xaf, 0x01, 0x1b, 0xc2, 0x41, 0x8d, 0xa3, 0x3c,
|
||||
0x94, 0x8d, 0xfe, 0xf1, 0x8d, 0xd9, 0x86, 0xd6,
|
||||
0x6f, 0xb5, 0xb9, 0xcd, 0xdf, 0xc6, 0x7b, 0xf1,
|
||||
0x95, 0x79, 0xa4, 0xa6, 0x52, 0x6a, 0x1f, 0xd8,
|
||||
0x22, 0x78, 0x76, 0x05, 0x7d, 0x16, 0x1e, 0xe9,
|
||||
0xcd, 0x50, 0x3d, 0x5a, 0x4a, 0x3a, 0x3d, 0xac,
|
||||
0x3a, 0x72, 0x3b, 0x45, 0xd0, 0x39, 0xad, 0xa2,
|
||||
0x4f, 0x05, 0x5e, 0xee, 0x85, 0x0b, 0x77, 0x78,
|
||||
0xaa, 0x1d, 0x6d, 0x18, 0xe2, 0x57, 0x82, 0x46,
|
||||
0xd1, 0xeb, 0xcf, 0xbd, 0xf5, 0x51, 0x00, 0xa6,
|
||||
0xe0, 0x93, 0x2e, 0xdd, 0x52, 0x44, 0x46, 0x64,
|
||||
0x0f, 0x95, 0x47, 0xbf, 0x8a, 0x1d, 0x99, 0x84,
|
||||
0x02, 0xa6, 0x16, 0x1b, 0xcb, 0x36, 0x72, 0x23,
|
||||
0x27, 0x4f, 0x40, 0x44, 0x50, 0xb9, 0x1c, 0xd0,
|
||||
0x91, 0x87, 0x66, 0xa6, 0xf0, 0x1f, 0x33, 0x36,
|
||||
0xfc, 0xb9, 0xe6, 0xe7, 0xd1, 0x50, 0x9e, 0x8d,
|
||||
0x2f, 0x66, 0xbd, 0x7b, 0x52, 0x20, 0xf8, 0x7f,
|
||||
0x51, 0x3a, 0x48, 0xac, 0x3a, 0x32, 0xde, 0x65,
|
||||
0x1a, 0xac, 0x9c, 0xa6, 0x6a, 0xec, 0x44, 0xee,
|
||||
0x06, 0x95, 0x05, 0xf2, 0x4a, 0xc5, 0x0c, 0x7d,
|
||||
0x51, 0x1f, 0xaa, 0xb4, 0xc0, 0xb9, 0x07, 0x87,
|
||||
0xff, 0x2b, 0x28, 0x12, 0x80, 0xea, 0x3c, 0x9e,
|
||||
0xb1, 0x81, 0xef, 0xfd, 0xd4, 0xe3, 0x09, 0x1f,
|
||||
0xc9, 0x9b, 0xf3, 0xea, 0xa1, 0x7d, 0x0d, 0x2a,
|
||||
0x4d, 0x6d, 0x9c, 0x06, 0xdf, 0x87, 0x51, 0xf4,
|
||||
0x7b, 0xc0, 0x7d, 0xc3, 0x6c, 0x78, 0x59, 0xe4,
|
||||
0xb7, 0x27, 0xd7, 0xf7, 0xf5, 0x6f, 0x63, 0xff,
|
||||
0x27, 0xe1, 0x57, 0x86, 0xf3, 0x08, 0xa3, 0xf9,
|
||||
0x6b, 0xef, 0xbe, 0xd0, 0x72, 0x29, 0x44, 0x3b,
|
||||
0xa9, 0x06, 0x4c, 0xde, 0xf7, 0x0e, 0x63, 0x22,
|
||||
0x90, 0x33, 0x2e, 0x14, 0x0c, 0xff, 0x83, 0x42,
|
||||
0xf0, 0x96, 0xa3, 0x4a, 0xf5, 0x5b, 0x01, 0xf1,
|
||||
0x02, 0x81, 0x81, 0x00, 0xe3, 0xa4, 0x26, 0x57,
|
||||
0x02, 0x11, 0x99, 0x42, 0xbb, 0x40, 0x10, 0x68,
|
||||
0xf4, 0xcc, 0xa1, 0x2f, 0x3c, 0x84, 0x0e, 0x7c,
|
||||
0xa5, 0xfc, 0x3c, 0x68, 0x18, 0x8e, 0xe9, 0x9c,
|
||||
0x2f, 0x1c, 0x49, 0x57, 0xe0, 0xdd, 0x89, 0xca,
|
||||
0xf9, 0x4f, 0x99, 0x22, 0xe5, 0xd4, 0x30, 0x0a,
|
||||
0x60, 0xa7, 0x02, 0x1c, 0x04, 0x2e, 0x07, 0x1c,
|
||||
0x0f, 0xb6, 0x60, 0x59, 0xeb, 0x8f, 0x38, 0x91,
|
||||
0x36, 0x0b, 0xb3, 0x6c, 0x13, 0xd8, 0xaf, 0x3a,
|
||||
0xe5, 0x70, 0x47, 0x4c, 0xeb, 0x6d, 0x29, 0xd1,
|
||||
0x66, 0xa7, 0xe7, 0x97, 0x51, 0x5c, 0x6d, 0xda,
|
||||
0xf7, 0x6c, 0xb3, 0x31, 0xd2, 0xd9, 0x5c, 0x99,
|
||||
0xaa, 0x84, 0x32, 0x2d, 0x40, 0xfb, 0xf0, 0xa8,
|
||||
0x85, 0x3b, 0x2c, 0x86, 0x87, 0x9b, 0xe7, 0xb4,
|
||||
0x9f, 0x21, 0x13, 0x50, 0xd4, 0x56, 0x6b, 0x65,
|
||||
0xda, 0x3c, 0xf6, 0x9e, 0xc1, 0xe4, 0xee, 0xde,
|
||||
0x64, 0x10, 0x29, 0x5d, 0x02, 0x81, 0x81, 0x00,
|
||||
0xde, 0xab, 0x15, 0x8b, 0xc5, 0xd1, 0x8f, 0xc1,
|
||||
0x51, 0xd7, 0x54, 0x47, 0xa2, 0xc5, 0x7f, 0xae,
|
||||
0x87, 0xcc, 0xdd, 0xc2, 0x9a, 0x1e, 0x8f, 0x15,
|
||||
0xb2, 0x9d, 0x37, 0xfe, 0x4d, 0x43, 0xb2, 0x52,
|
||||
0xe7, 0xb2, 0x0e, 0xe0, 0x1f, 0x48, 0xde, 0x07,
|
||||
0x8e, 0xff, 0x74, 0xbd, 0xfc, 0xbd, 0x27, 0x2a,
|
||||
0x7a, 0xc0, 0x66, 0x09, 0xaf, 0x5b, 0x04, 0xed,
|
||||
0xbc, 0x9c, 0x9f, 0xe6, 0x43, 0xa3, 0x9e, 0xc7,
|
||||
0x73, 0x3d, 0xcb, 0x6f, 0x69, 0x58, 0x43, 0xe8,
|
||||
0xfe, 0xd8, 0x06, 0xb9, 0xcb, 0x09, 0xbc, 0xc7,
|
||||
0xb5, 0x2e, 0xed, 0xcc, 0xdf, 0x29, 0x26, 0x6c,
|
||||
0x01, 0x33, 0xfd, 0xa3, 0xad, 0xc6, 0x82, 0x0b,
|
||||
0xb2, 0x14, 0x75, 0xb2, 0xf6, 0xba, 0xc1, 0xae,
|
||||
0xdb, 0x4c, 0x08, 0x09, 0x47, 0x09, 0xc9, 0x88,
|
||||
0x3d, 0x69, 0x72, 0xeb, 0x78, 0xd9, 0xf6, 0x5a,
|
||||
0xe7, 0xcf, 0x58, 0xf1, 0xdb, 0x22, 0x46, 0x95,
|
||||
0x02, 0x81, 0x80, 0x47, 0x0b, 0xe6, 0x43, 0x65,
|
||||
0x8b, 0xe4, 0x8f, 0x65, 0x2d, 0x9b, 0x71, 0x86,
|
||||
0x65, 0x8f, 0x30, 0xd4, 0xec, 0x4a, 0x31, 0x31,
|
||||
0x04, 0xc6, 0x3d, 0x9e, 0xdc, 0x8b, 0xa0, 0x89,
|
||||
0x3b, 0x84, 0xd0, 0x7e, 0x87, 0xe6, 0x07, 0x89,
|
||||
0x44, 0x04, 0x81, 0x55, 0xc5, 0xa1, 0xb0, 0xbb,
|
||||
0x75, 0xa4, 0x3c, 0xe6, 0x39, 0x0f, 0x52, 0xfc,
|
||||
0xbc, 0x68, 0xd9, 0xe7, 0xa0, 0xed, 0x80, 0xb4,
|
||||
0xa3, 0x76, 0x3e, 0x16, 0xfb, 0x9b, 0xc4, 0xff,
|
||||
0xf2, 0xc8, 0xee, 0x02, 0xd4, 0x31, 0x26, 0xff,
|
||||
0xa9, 0x0b, 0xa8, 0xb8, 0x65, 0xe6, 0x8b, 0x5e,
|
||||
0x89, 0x78, 0x6b, 0xe6, 0x68, 0x9c, 0x74, 0x01,
|
||||
0x39, 0xfd, 0x07, 0x0e, 0xaf, 0x12, 0xef, 0x25,
|
||||
0x95, 0xd0, 0x51, 0xb4, 0x65, 0x3e, 0x2d, 0xab,
|
||||
0x34, 0x81, 0x78, 0xca, 0xac, 0xa6, 0x1c, 0x45,
|
||||
0xbe, 0x9d, 0x21, 0xf3, 0x55, 0xe6, 0x0f, 0x56,
|
||||
0x9f, 0x8c, 0xa9, 0x02, 0x81, 0x81, 0x00, 0xd6,
|
||||
0xcf, 0x45, 0xa1, 0xe9, 0xdd, 0x19, 0x49, 0xee,
|
||||
0xa2, 0x44, 0xf4, 0x36, 0xdb, 0x41, 0x2a, 0x26,
|
||||
0x68, 0x45, 0x27, 0x8f, 0x77, 0x1b, 0xa2, 0x5b,
|
||||
0x05, 0xc1, 0x16, 0xdb, 0x83, 0x0b, 0x6d, 0x5f,
|
||||
0x88, 0x2f, 0x41, 0x97, 0xec, 0xbc, 0x05, 0x9e,
|
||||
0xb6, 0x62, 0xf1, 0x45, 0xf9, 0x54, 0xe7, 0x6e,
|
||||
0x34, 0x5e, 0x3b, 0xc9, 0xa7, 0x8d, 0x41, 0xac,
|
||||
0x4b, 0x8d, 0x16, 0x9e, 0xfa, 0x22, 0x1b, 0x57,
|
||||
0xd9, 0xad, 0x80, 0x75, 0xa8, 0x69, 0x1b, 0x45,
|
||||
0x7f, 0x32, 0x3d, 0xda, 0xda, 0x31, 0xfc, 0x97,
|
||||
0x96, 0x06, 0x63, 0x36, 0x86, 0x84, 0x42, 0x7d,
|
||||
0x86, 0xa2, 0x92, 0x5c, 0xfa, 0xbc, 0x4a, 0x7c,
|
||||
0x29, 0xb0, 0xc2, 0x4d, 0xb4, 0x2d, 0x55, 0x7a,
|
||||
0xca, 0x06, 0x96, 0xac, 0xa9, 0x8c, 0x7a, 0x9a,
|
||||
0x84, 0x38, 0x11, 0x62, 0x2d, 0x23, 0xb4, 0xdf,
|
||||
0x1c, 0xf1, 0x39, 0xa1, 0xa5, 0x97, 0x61, 0x02,
|
||||
0x81, 0x80, 0x6c, 0xfb, 0x23, 0x03, 0xa6, 0xa4,
|
||||
0x29, 0x03, 0x36, 0x84, 0x86, 0x95, 0x6d, 0x86,
|
||||
0x32, 0x98, 0xbe, 0x0a, 0xa2, 0xba, 0x47, 0xd0,
|
||||
0x29, 0x3f, 0x8c, 0xa6, 0x28, 0x93, 0x6f, 0x25,
|
||||
0x69, 0x38, 0x38, 0x03, 0xe5, 0x9b, 0xc8, 0x48,
|
||||
0x35, 0xc7, 0x26, 0xc0, 0x75, 0xd2, 0x95, 0x5b,
|
||||
0x51, 0x6d, 0x28, 0x88, 0xb1, 0x4b, 0xf0, 0x59,
|
||||
0x18, 0x15, 0x9d, 0x9e, 0x48, 0xb5, 0x67, 0x0c,
|
||||
0xb0, 0x83, 0xfa, 0x45, 0x48, 0x4d, 0xaa, 0xba,
|
||||
0xe3, 0xdf, 0x76, 0x60, 0x06, 0x09, 0x0d, 0x72,
|
||||
0x8c, 0x0c, 0xd2, 0x70, 0x39, 0xed, 0x19, 0xd8,
|
||||
0x1b, 0x64, 0x33, 0xce, 0x12, 0xa8, 0xb3, 0xa0,
|
||||
0xf5, 0x5f, 0xcc, 0xf7, 0x1a, 0x63, 0x5d, 0x44,
|
||||
0x61, 0xc6, 0xa0, 0x54, 0xe9, 0x01, 0xa6, 0x54,
|
||||
0x16, 0xa7, 0xa0, 0x9e, 0xc9, 0xd8, 0x9c, 0x19,
|
||||
0x04, 0xe1, 0x5e, 0xd5, 0x37, 0xbb, 0xfd, 0x76,
|
||||
0x77, 0x75,
|
||||
};
|
||||
|
||||
static const unsigned int rsa_example_keypair_der_len =
|
||||
sizeof(rsa_example_keypair_der);
|
||||
|
||||
static const unsigned char rsa_example_cert_der[] = {
|
||||
0x30, 0x82, 0x02, 0xfb, 0x30, 0x82, 0x01, 0xe3,
|
||||
0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x09, 0x00,
|
||||
0xee, 0x10, 0x1f, 0xc1, 0xf2, 0x30, 0xe9, 0x11,
|
||||
0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86,
|
||||
0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30,
|
||||
0x14, 0x31, 0x12, 0x30, 0x10, 0x06, 0x03, 0x55,
|
||||
0x04, 0x03, 0x0c, 0x09, 0x6c, 0x6f, 0x63, 0x61,
|
||||
0x6c, 0x68, 0x6f, 0x73, 0x74, 0x30, 0x1e, 0x17,
|
||||
0x0d, 0x31, 0x37, 0x30, 0x36, 0x32, 0x36, 0x31,
|
||||
0x30, 0x35, 0x36, 0x31, 0x30, 0x5a, 0x17, 0x0d,
|
||||
0x34, 0x34, 0x31, 0x31, 0x31, 0x31, 0x31, 0x30,
|
||||
0x35, 0x36, 0x31, 0x30, 0x5a, 0x30, 0x14, 0x31,
|
||||
0x12, 0x30, 0x10, 0x06, 0x03, 0x55, 0x04, 0x03,
|
||||
0x0c, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x68,
|
||||
0x6f, 0x73, 0x74, 0x30, 0x82, 0x01, 0x22, 0x30,
|
||||
0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7,
|
||||
0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82,
|
||||
0x01, 0x0f, 0x00, 0x30, 0x82, 0x01, 0x0a, 0x02,
|
||||
0x82, 0x01, 0x01, 0x00, 0xc6, 0x00, 0x7b, 0x0d,
|
||||
0xd1, 0x17, 0x43, 0x6b, 0xa9, 0xa7, 0x79, 0x9c,
|
||||
0x0f, 0x8d, 0x77, 0x91, 0xd2, 0xf7, 0x47, 0x35,
|
||||
0xb3, 0x17, 0xe2, 0xdd, 0xed, 0x6d, 0x01, 0xf9,
|
||||
0xb1, 0x92, 0xc9, 0x48, 0x80, 0xe0, 0x1f, 0xcf,
|
||||
0xb7, 0xa4, 0x5f, 0xf0, 0x36, 0xea, 0xbf, 0xe1,
|
||||
0x33, 0xf8, 0xa9, 0xc5, 0xe6, 0xd4, 0x19, 0x8b,
|
||||
0x82, 0x25, 0xd9, 0x19, 0x74, 0x70, 0x79, 0xec,
|
||||
0xc6, 0x68, 0xc9, 0xef, 0xce, 0x1a, 0xa9, 0xf0,
|
||||
0xb7, 0x01, 0x35, 0x91, 0xff, 0xd3, 0x75, 0x6e,
|
||||
0x02, 0xba, 0x06, 0x9a, 0x2a, 0xac, 0xcf, 0x22,
|
||||
0xbf, 0x2b, 0x1f, 0xc1, 0x72, 0x38, 0x22, 0x35,
|
||||
0xea, 0xda, 0x6f, 0xdd, 0x67, 0xa2, 0x2b, 0x19,
|
||||
0x38, 0x19, 0x0e, 0x44, 0xd1, 0x71, 0x38, 0xb4,
|
||||
0x6d, 0x26, 0x85, 0xd6, 0xc6, 0xbe, 0xc1, 0x6f,
|
||||
0x3c, 0xee, 0xaf, 0x94, 0x3c, 0x05, 0x56, 0x4e,
|
||||
0xad, 0x53, 0x81, 0x8b, 0xd4, 0x23, 0x31, 0x69,
|
||||
0x72, 0x27, 0x93, 0xb4, 0x3a, 0xac, 0x23, 0xe8,
|
||||
0x10, 0xae, 0xf5, 0x9f, 0x0b, 0xa6, 0x6e, 0xd3,
|
||||
0x73, 0xca, 0x18, 0x11, 0xca, 0xbe, 0x71, 0x00,
|
||||
0x56, 0x29, 0x34, 0x54, 0xcc, 0xda, 0x29, 0x5b,
|
||||
0x26, 0x29, 0x99, 0x4d, 0x5f, 0xa1, 0xa6, 0xb9,
|
||||
0xcb, 0x2b, 0xb2, 0x0f, 0x10, 0x00, 0x04, 0xa9,
|
||||
0x11, 0x2c, 0x48, 0xb1, 0x99, 0xa5, 0xca, 0x7c,
|
||||
0x67, 0xa5, 0xbe, 0x14, 0x20, 0x12, 0xb7, 0x3b,
|
||||
0x7a, 0x4f, 0xdc, 0xc7, 0xd5, 0x2d, 0x04, 0x66,
|
||||
0xbb, 0xf5, 0x0c, 0xcd, 0xf1, 0x32, 0x39, 0xd7,
|
||||
0x51, 0x9b, 0xba, 0xdb, 0xf1, 0xa7, 0xfe, 0x2d,
|
||||
0x9a, 0xe6, 0x9c, 0x6b, 0x54, 0xda, 0xf1, 0xdd,
|
||||
0x48, 0xf9, 0xd7, 0xf0, 0x35, 0x7c, 0x8e, 0x24,
|
||||
0x7e, 0x44, 0x2f, 0xf3, 0xbf, 0x39, 0x0e, 0x96,
|
||||
0xab, 0xe1, 0x45, 0x03, 0x8b, 0x54, 0xdc, 0xe1,
|
||||
0xb6, 0x11, 0x81, 0x21, 0x02, 0x03, 0x01, 0x00,
|
||||
0x01, 0xa3, 0x50, 0x30, 0x4e, 0x30, 0x1d, 0x06,
|
||||
0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14,
|
||||
0xa4, 0xef, 0x6d, 0xdc, 0x9b, 0x23, 0xc5, 0x3a,
|
||||
0xdd, 0x34, 0xd9, 0x01, 0x1c, 0x68, 0x03, 0x53,
|
||||
0xae, 0x92, 0xc2, 0xc9, 0x30, 0x1f, 0x06, 0x03,
|
||||
0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, 0x80,
|
||||
0x14, 0xa4, 0xef, 0x6d, 0xdc, 0x9b, 0x23, 0xc5,
|
||||
0x3a, 0xdd, 0x34, 0xd9, 0x01, 0x1c, 0x68, 0x03,
|
||||
0x53, 0xae, 0x92, 0xc2, 0xc9, 0x30, 0x0c, 0x06,
|
||||
0x03, 0x55, 0x1d, 0x13, 0x04, 0x05, 0x30, 0x03,
|
||||
0x01, 0x01, 0xff, 0x30, 0x0d, 0x06, 0x09, 0x2a,
|
||||
0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b,
|
||||
0x05, 0x00, 0x03, 0x82, 0x01, 0x01, 0x00, 0x67,
|
||||
0x65, 0xbf, 0x93, 0x89, 0xde, 0x4f, 0x71, 0xff,
|
||||
0x1c, 0x93, 0x68, 0xa0, 0x64, 0x09, 0x5e, 0x95,
|
||||
0x94, 0xf5, 0xd5, 0xf4, 0x6b, 0x20, 0x32, 0xd8,
|
||||
0x04, 0x80, 0xac, 0xf8, 0x52, 0x36, 0x7a, 0x38,
|
||||
0x83, 0xae, 0xab, 0x29, 0x22, 0x42, 0x71, 0x7e,
|
||||
0xea, 0xe5, 0x4f, 0x71, 0xac, 0x44, 0x3f, 0x9e,
|
||||
0x5e, 0x49, 0x22, 0x05, 0xee, 0xa6, 0x7b, 0xab,
|
||||
0x56, 0x2e, 0xb3, 0x9a, 0x35, 0x1a, 0x88, 0xc3,
|
||||
0x54, 0x9b, 0xfd, 0xac, 0x65, 0x54, 0xaf, 0x21,
|
||||
0xa7, 0xe0, 0xdd, 0x62, 0x29, 0x8c, 0xae, 0x26,
|
||||
0x0b, 0x84, 0x1f, 0x69, 0x78, 0x84, 0xc6, 0x7e,
|
||||
0xcf, 0xc8, 0xf5, 0x92, 0x8c, 0x05, 0xa8, 0x13,
|
||||
0x38, 0xcd, 0x0b, 0x98, 0x53, 0xfb, 0xdd, 0x8d,
|
||||
0x51, 0x90, 0xa8, 0x51, 0xfa, 0x52, 0xbe, 0x28,
|
||||
0xd4, 0x71, 0x50, 0x73, 0x1f, 0xb0, 0xb6, 0x0e,
|
||||
0x45, 0xb1, 0x47, 0x41, 0x06, 0xd9, 0x1d, 0x7a,
|
||||
0x34, 0xe7, 0x80, 0x2e, 0x0c, 0x02, 0x50, 0x97,
|
||||
0xde, 0xa8, 0x7a, 0x84, 0x2c, 0x1d, 0xf4, 0x51,
|
||||
0x56, 0xa5, 0x52, 0xb5, 0x04, 0x2e, 0xcb, 0xdd,
|
||||
0x8b, 0x2e, 0x16, 0xc6, 0xde, 0xc8, 0xe9, 0x8d,
|
||||
0xee, 0x5e, 0xb6, 0xa0, 0xe0, 0x2b, 0x85, 0x2a,
|
||||
0x89, 0x7b, 0xba, 0x68, 0x80, 0x2b, 0xfb, 0x6e,
|
||||
0x2e, 0x80, 0xe7, 0x7a, 0x97, 0x09, 0xb5, 0x2f,
|
||||
0x20, 0x8e, 0xed, 0xbc, 0x98, 0x6f, 0x95, 0xd5,
|
||||
0x5b, 0x3d, 0x26, 0x19, 0x26, 0x14, 0x39, 0x82,
|
||||
0xa8, 0xa8, 0x42, 0x46, 0xab, 0x59, 0x93, 0x47,
|
||||
0x83, 0xf7, 0x79, 0xbf, 0x73, 0xb5, 0x5d, 0x5d,
|
||||
0x78, 0xfe, 0x62, 0xac, 0xed, 0xb7, 0x1e, 0x4a,
|
||||
0xad, 0xc3, 0x99, 0x39, 0x7d, 0x3e, 0x30, 0x21,
|
||||
0x26, 0x1d, 0x66, 0xdb, 0x0d, 0xf3, 0xba, 0x87,
|
||||
0x46, 0xf0, 0x04, 0xfc, 0xc3, 0xbe, 0x84, 0x85,
|
||||
0x3c, 0x01, 0xef, 0xe0, 0x68, 0x65, 0xee,
|
||||
};
|
||||
|
||||
static const unsigned int rsa_example_cert_der_len =
|
||||
sizeof(rsa_example_cert_der);
|
||||
|
||||
#endif
|
|
@ -1,228 +0,0 @@
|
|||
/* udp.c - UDP specific code for echo server */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2017 Intel Corporation.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <logging/log.h>
|
||||
LOG_MODULE_DECLARE(net_echo_server_sample, LOG_LEVEL_DBG);
|
||||
|
||||
#include <zephyr.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <net/net_pkt.h>
|
||||
#include <net/net_core.h>
|
||||
#include <net/net_context.h>
|
||||
#include <net/udp.h>
|
||||
|
||||
#include <net/net_app.h>
|
||||
|
||||
#include "common.h"
|
||||
|
||||
static struct net_app_ctx udp;
|
||||
|
||||
/* Note that both tcp and udp can share the same pool but in this
|
||||
* example the UDP context and TCP context have separate pools.
|
||||
*/
|
||||
#if defined(CONFIG_NET_CONTEXT_NET_PKT_POOL)
|
||||
NET_PKT_TX_SLAB_DEFINE(echo_tx_udp, 5);
|
||||
NET_PKT_DATA_POOL_DEFINE(echo_data_udp, 20);
|
||||
|
||||
static struct k_mem_slab *tx_udp_slab(void)
|
||||
{
|
||||
return &echo_tx_udp;
|
||||
}
|
||||
|
||||
static struct net_buf_pool *data_udp_pool(void)
|
||||
{
|
||||
return &echo_data_udp;
|
||||
}
|
||||
#else
|
||||
#define tx_udp_slab NULL
|
||||
#define data_udp_pool NULL
|
||||
#endif /* CONFIG_NET_CONTEXT_NET_PKT_POOL */
|
||||
|
||||
#if defined(CONFIG_NET_APP_DTLS)
|
||||
|
||||
/* The result buf size is set to large enough so that we can receive max size
|
||||
* buf back. Note that mbedtls needs also be configured to have equal size
|
||||
* value for its buffer size. See MBEDTLS_SSL_MAX_CONTENT_LEN option in TLS
|
||||
* config file.
|
||||
*/
|
||||
#define RESULT_BUF_SIZE 1500
|
||||
static u8_t dtls_result[RESULT_BUF_SIZE];
|
||||
|
||||
#define APP_BANNER "Run DTLS echo-server"
|
||||
#define INSTANCE_INFO "Zephyr DTLS echo-server #1"
|
||||
|
||||
/* Note that each net_app context needs its own stack as there will be
|
||||
* a separate thread needed.
|
||||
*/
|
||||
NET_STACK_DEFINE(NET_APP_DTLS, net_app_dtls_stack,
|
||||
CONFIG_NET_APP_TLS_STACK_SIZE, CONFIG_NET_APP_TLS_STACK_SIZE);
|
||||
|
||||
#define RX_FIFO_DEPTH 4
|
||||
K_MEM_POOL_DEFINE(dtls_pool, 4, 64, RX_FIFO_DEPTH, 4);
|
||||
#endif /* CONFIG_NET_APP_TLS */
|
||||
|
||||
#if defined(CONFIG_NET_APP_DTLS)
|
||||
/* Load the certificates and private RSA key. */
|
||||
|
||||
#include "test_certs.h"
|
||||
|
||||
static int setup_cert(struct net_app_ctx *ctx,
|
||||
mbedtls_x509_crt *cert,
|
||||
mbedtls_pk_context *pkey)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = mbedtls_x509_crt_parse(cert, rsa_example_cert_der,
|
||||
rsa_example_cert_der_len);
|
||||
if (ret != 0) {
|
||||
LOG_ERR("mbedtls_x509_crt_parse returned %d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = mbedtls_pk_parse_key(pkey, rsa_example_keypair_der,
|
||||
rsa_example_keypair_der_len, NULL, 0);
|
||||
if (ret != 0) {
|
||||
LOG_ERR("mbedtls_pk_parse_key returned %d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* CONFIG_NET_APP_DTLS */
|
||||
|
||||
static inline void set_dst_addr(sa_family_t family,
|
||||
struct net_pkt *pkt,
|
||||
struct sockaddr *dst_addr)
|
||||
{
|
||||
struct net_udp_hdr hdr, *udp_hdr;
|
||||
|
||||
udp_hdr = net_udp_get_hdr(pkt, &hdr);
|
||||
if (!udp_hdr) {
|
||||
return;
|
||||
}
|
||||
|
||||
#if defined(CONFIG_NET_IPV6)
|
||||
if (family == AF_INET6) {
|
||||
net_ipaddr_copy(&net_sin6(dst_addr)->sin6_addr,
|
||||
&NET_IPV6_HDR(pkt)->src);
|
||||
net_sin6(dst_addr)->sin6_family = AF_INET6;
|
||||
net_sin6(dst_addr)->sin6_port = udp_hdr->src_port;
|
||||
}
|
||||
#endif /* CONFIG_NET_IPV6) */
|
||||
|
||||
#if defined(CONFIG_NET_IPV4)
|
||||
if (family == AF_INET) {
|
||||
net_ipaddr_copy(&net_sin(dst_addr)->sin_addr,
|
||||
&NET_IPV4_HDR(pkt)->src);
|
||||
net_sin(dst_addr)->sin_family = AF_INET;
|
||||
net_sin(dst_addr)->sin_port = udp_hdr->src_port;
|
||||
}
|
||||
#endif /* CONFIG_NET_IPV6) */
|
||||
}
|
||||
|
||||
static void udp_received(struct net_app_ctx *ctx,
|
||||
struct net_pkt *pkt,
|
||||
int status,
|
||||
void *user_data)
|
||||
{
|
||||
static char dbg[MAX_DBG_PRINT + 1];
|
||||
struct net_pkt *reply_pkt;
|
||||
struct sockaddr dst_addr;
|
||||
sa_family_t family = net_pkt_family(pkt);
|
||||
socklen_t dst_len;
|
||||
u32_t pkt_len;
|
||||
int ret;
|
||||
|
||||
snprintk(dbg, MAX_DBG_PRINT, "UDP IPv%c",
|
||||
family == AF_INET6 ? '6' : '4');
|
||||
|
||||
if (family == AF_INET6) {
|
||||
dst_len = sizeof(struct sockaddr_in6);
|
||||
} else {
|
||||
dst_len = sizeof(struct sockaddr_in);
|
||||
}
|
||||
|
||||
/* Note that for DTLS swapping the source/destination address has no
|
||||
* effect as the user data is sent in a DTLS tunnel where tunnel end
|
||||
* points are already set.
|
||||
*/
|
||||
set_dst_addr(family, pkt, &dst_addr);
|
||||
|
||||
reply_pkt = build_reply_pkt(dbg, ctx, pkt, NET_UDPH_LEN);
|
||||
|
||||
net_pkt_unref(pkt);
|
||||
|
||||
if (!reply_pkt) {
|
||||
return;
|
||||
}
|
||||
|
||||
pkt_len = net_pkt_appdatalen(reply_pkt);
|
||||
|
||||
ret = net_app_send_pkt(ctx, reply_pkt, &dst_addr, dst_len, K_NO_WAIT,
|
||||
UINT_TO_POINTER(pkt_len));
|
||||
if (ret < 0) {
|
||||
LOG_ERR("Cannot send data to peer (%d)", ret);
|
||||
net_pkt_unref(reply_pkt);
|
||||
}
|
||||
}
|
||||
|
||||
void start_udp(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = net_app_init_udp_server(&udp, NULL, MY_PORT, NULL);
|
||||
if (ret < 0) {
|
||||
LOG_ERR("Cannot init UDP service at port %d", MY_PORT);
|
||||
return;
|
||||
}
|
||||
|
||||
#if defined(CONFIG_NET_CONTEXT_NET_PKT_POOL)
|
||||
net_app_set_net_pkt_pool(&udp, tx_udp_slab, data_udp_pool);
|
||||
#endif
|
||||
|
||||
ret = net_app_set_cb(&udp, NULL, udp_received, pkt_sent, NULL);
|
||||
if (ret < 0) {
|
||||
LOG_ERR("Cannot set callbacks (%d)", ret);
|
||||
net_app_release(&udp);
|
||||
return;
|
||||
}
|
||||
|
||||
#if defined(CONFIG_NET_APP_DTLS)
|
||||
ret = net_app_server_tls(&udp,
|
||||
dtls_result,
|
||||
sizeof(dtls_result),
|
||||
APP_BANNER,
|
||||
INSTANCE_INFO,
|
||||
strlen(INSTANCE_INFO),
|
||||
setup_cert,
|
||||
NULL,
|
||||
&dtls_pool,
|
||||
net_app_dtls_stack,
|
||||
K_THREAD_STACK_SIZEOF(net_app_dtls_stack));
|
||||
if (ret < 0) {
|
||||
LOG_ERR("Cannot init DTLS");
|
||||
}
|
||||
#endif
|
||||
|
||||
net_app_server_enable(&udp);
|
||||
|
||||
ret = net_app_listen(&udp);
|
||||
if (ret < 0) {
|
||||
LOG_ERR("Cannot wait connection (%d)", ret);
|
||||
net_app_release(&udp);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void stop_udp(void)
|
||||
{
|
||||
net_app_close(&udp);
|
||||
net_app_release(&udp);
|
||||
}
|
|
@ -1,115 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2018 Intel Corporation.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <logging/log.h>
|
||||
LOG_MODULE_DECLARE(net_echo_server_sample, LOG_LEVEL_DBG);
|
||||
|
||||
#include <zephyr.h>
|
||||
|
||||
#include <net/ethernet.h>
|
||||
|
||||
/* User data for the interface callback */
|
||||
struct ud {
|
||||
struct net_if *first;
|
||||
struct net_if *second;
|
||||
struct net_if *third;
|
||||
};
|
||||
|
||||
static void iface_cb(struct net_if *iface, void *user_data)
|
||||
{
|
||||
struct ud *ud = user_data;
|
||||
|
||||
if (net_if_l2(iface) != &NET_L2_GET_NAME(ETHERNET)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!ud->first) {
|
||||
ud->first = iface;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!ud->second) {
|
||||
ud->second = iface;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!ud->third) {
|
||||
ud->third = iface;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
static int setup_iface(struct net_if *iface, const char *ipv6_addr,
|
||||
const char *ipv4_addr, u16_t vlan_tag)
|
||||
{
|
||||
struct net_if_addr *ifaddr;
|
||||
struct in_addr addr4;
|
||||
struct in6_addr addr6;
|
||||
int ret;
|
||||
|
||||
ret = net_eth_vlan_enable(iface, vlan_tag);
|
||||
if (ret < 0) {
|
||||
LOG_ERR("Cannot enable VLAN for tag %d (%d)", vlan_tag, ret);
|
||||
}
|
||||
|
||||
if (net_addr_pton(AF_INET6, ipv6_addr, &addr6)) {
|
||||
LOG_ERR("Invalid address: %s", ipv6_addr);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ifaddr = net_if_ipv6_addr_add(iface, &addr6, NET_ADDR_MANUAL, 0);
|
||||
if (!ifaddr) {
|
||||
LOG_ERR("Cannot add %s to interface %p", ipv6_addr, iface);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (net_addr_pton(AF_INET, ipv4_addr, &addr4)) {
|
||||
LOG_ERR("Invalid address: %s", ipv6_addr);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ifaddr = net_if_ipv4_addr_add(iface, &addr4, NET_ADDR_MANUAL, 0);
|
||||
if (!ifaddr) {
|
||||
LOG_ERR("Cannot add %s to interface %p", ipv4_addr, iface);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
LOG_DBG("Interface %p VLAN tag %d setup done.", iface, vlan_tag);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int init_vlan(void)
|
||||
{
|
||||
struct ud ud;
|
||||
int ret;
|
||||
|
||||
memset(&ud, 0, sizeof(ud));
|
||||
|
||||
net_if_foreach(iface_cb, &ud);
|
||||
|
||||
/* This sample has two VLANs. For the second one we need to manually
|
||||
* create IP address for this test. But first the VLAN needs to be
|
||||
* added to the interface so that IPv6 DAD can work properly.
|
||||
*/
|
||||
ret = setup_iface(ud.second,
|
||||
CONFIG_NET_SAMPLE_IFACE2_MY_IPV6_ADDR,
|
||||
CONFIG_NET_SAMPLE_IFACE2_MY_IPV4_ADDR,
|
||||
CONFIG_NET_SAMPLE_IFACE2_VLAN_TAG);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = setup_iface(ud.third,
|
||||
CONFIG_NET_SAMPLE_IFACE3_MY_IPV6_ADDR,
|
||||
CONFIG_NET_SAMPLE_IFACE3_MY_IPV4_ADDR,
|
||||
CONFIG_NET_SAMPLE_IFACE3_VLAN_TAG);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -28,7 +28,6 @@ CONFIG_NET_SHELL=y
|
|||
CONFIG_NET_CONFIG_SETTINGS=y
|
||||
CONFIG_NET_CONFIG_NEED_IPV6=y
|
||||
CONFIG_NET_CONFIG_NEED_IPV4=y
|
||||
CONFIG_NET_APP_SERVER=y
|
||||
CONFIG_NET_CONFIG_MY_IPV6_ADDR="2001:db8::1"
|
||||
CONFIG_NET_CONFIG_PEER_IPV6_ADDR="2001:db8::2"
|
||||
CONFIG_NET_CONFIG_MY_IPV4_ADDR="192.0.2.1"
|
||||
|
|
|
@ -27,7 +27,6 @@ CONFIG_NET_SHELL=y
|
|||
# Ethernet is needed for gPTP
|
||||
CONFIG_NET_L2_ETHERNET=y
|
||||
|
||||
CONFIG_NET_APP_SERVER=y
|
||||
CONFIG_NET_CONFIG_NEED_IPV6=y
|
||||
CONFIG_NET_CONFIG_NEED_IPV4=y
|
||||
CONFIG_NET_CONFIG_SETTINGS=y
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
cmake_minimum_required(VERSION 3.13.1)
|
||||
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
|
||||
project(irc_bot)
|
||||
|
||||
FILE(GLOB app_sources src/*.c)
|
||||
target_sources(app PRIVATE ${app_sources})
|
|
@ -1,40 +0,0 @@
|
|||
CONFIG_INIT_STACKS=y
|
||||
|
||||
CONFIG_NET_IPV4=y
|
||||
CONFIG_NET_DHCPV4=y
|
||||
CONFIG_NET_IF_UNICAST_IPV4_ADDR_COUNT=3
|
||||
CONFIG_NET_IPV6=n
|
||||
CONFIG_NET_IF_UNICAST_IPV6_ADDR_COUNT=3
|
||||
CONFIG_NET_LOG=y
|
||||
CONFIG_LOG=y
|
||||
CONFIG_NET_CONTEXT_NET_PKT_POOL=y
|
||||
CONFIG_NET_BUF_RX_COUNT=30
|
||||
CONFIG_NET_BUF_TX_COUNT=30
|
||||
CONFIG_NET_PKT_RX_COUNT=14
|
||||
CONFIG_NET_PKT_TX_COUNT=14
|
||||
CONFIG_NET_SHELL=y
|
||||
CONFIG_NET_STATISTICS=y
|
||||
CONFIG_NET_TCP=y
|
||||
CONFIG_NETWORKING=y
|
||||
CONFIG_DNS_RESOLVER=y
|
||||
CONFIG_DNS_RESOLVER_ADDITIONAL_BUF_CTR=2
|
||||
CONFIG_DNS_RESOLVER_ADDITIONAL_QUERIES=2
|
||||
CONFIG_DNS_RESOLVER_MAX_SERVERS=1
|
||||
CONFIG_DNS_SERVER_IP_ADDRESSES=y
|
||||
CONFIG_DNS_NUM_CONCUR_QUERIES=2
|
||||
|
||||
# Google DNS IPv4 and IPv6 servers. IPv4 is the default server.
|
||||
# For IPv6, uncomment the IPv6 specific setting and comment the
|
||||
# IPv4 specific one.
|
||||
CONFIG_DNS_SERVER1="8.8.8.8"
|
||||
# CONFIG_DNS_SERVER1="2001:4860:4860::8888"
|
||||
|
||||
CONFIG_PRINTK=y
|
||||
|
||||
CONFIG_NET_APP_CLIENT=y
|
||||
CONFIG_NET_CONFIG_NEED_IPV4=y
|
||||
CONFIG_NET_CONFIG_NEED_IPV6=n
|
||||
CONFIG_NET_CONFIG_SETTINGS=y
|
||||
|
||||
CONFIG_GPIO=y
|
||||
CONFIG_TEST_RANDOM_GENERATOR=y
|
|
@ -1,7 +0,0 @@
|
|||
sample:
|
||||
name: IRC Bot
|
||||
tests:
|
||||
test:
|
||||
harness: net
|
||||
depends_on: netif gpio
|
||||
tags: net irc
|
|
@ -1,663 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2017 Intel Corporation.
|
||||
* Copyright (c) 2017 Linaro Ltd.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <logging/log.h>
|
||||
LOG_MODULE_REGISTER(net_irc_bot_sample, LOG_LEVEL_DBG);
|
||||
|
||||
#include <random/rand32.h>
|
||||
#include <errno.h>
|
||||
#include <gpio.h>
|
||||
#include <net/net_app.h>
|
||||
#include <stdio.h>
|
||||
#include <zephyr.h>
|
||||
#include <net/dns_resolve.h>
|
||||
|
||||
#if !defined(CONFIG_NET_IPV6) && !defined(CONFIG_NET_IPV4)
|
||||
#error "CONFIG_NET_IPV6 or CONFIG_NET_IPV4 must be enabled for irc_bot"
|
||||
#endif
|
||||
|
||||
#define APP_BANNER "Zephyr IRC bot sample"
|
||||
|
||||
static void on_msg_rcvd(char *chan_name, char *umask, char *msg);
|
||||
|
||||
#define CMD_BUFFER_SIZE 256
|
||||
static u8_t cmd_buf[CMD_BUFFER_SIZE];
|
||||
static u16_t cmd_len;
|
||||
|
||||
#define NICK_BUFFER_SIZE 16
|
||||
static char nick_buf[NICK_BUFFER_SIZE];
|
||||
|
||||
/* LED */
|
||||
#ifndef LED0_GPIO_CONTROLLER
|
||||
#ifdef LED0_GPIO_PORT
|
||||
#define LED0_GPIO_CONTROLLER LED0_GPIO_PORT
|
||||
#else
|
||||
#define LED0_GPIO_CONTROLLER "(fail)"
|
||||
#define LED0_GPIO_PIN 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define LED_GPIO_NAME LED0_GPIO_CONTROLLER
|
||||
#define LED_PIN LED0_GPIO_PIN
|
||||
|
||||
|
||||
static struct device *led0;
|
||||
static bool fake_led;
|
||||
|
||||
/* Network Config */
|
||||
#define WAIT_TIMEOUT K_SECONDS(10)
|
||||
#define CONNECT_TIMEOUT K_SECONDS(10)
|
||||
#define BUF_ALLOC_TIMEOUT K_SECONDS(1)
|
||||
|
||||
/* IRC API */
|
||||
#define DEFAULT_SERVER "irc.freenode.net"
|
||||
#define DEFAULT_PORT 6667
|
||||
#define DEFAULT_CHANNEL "#zephyrbot"
|
||||
|
||||
static struct net_app_ctx app_ctx;
|
||||
|
||||
#if defined(CONFIG_NET_CONTEXT_NET_PKT_POOL)
|
||||
NET_PKT_TX_SLAB_DEFINE(tx_tcp, 15);
|
||||
NET_PKT_DATA_POOL_DEFINE(data_tcp, 30);
|
||||
|
||||
static struct k_mem_slab *tx_slab(void)
|
||||
{
|
||||
return &tx_tcp;
|
||||
}
|
||||
|
||||
static struct net_buf_pool *data_pool(void)
|
||||
{
|
||||
return &data_tcp;
|
||||
}
|
||||
#else
|
||||
#define tx_slab NULL
|
||||
#define data_pool NULL
|
||||
#endif /* CONFIG_NET_CONTEXT_NET_PKT_POOL */
|
||||
|
||||
static void
|
||||
panic(const char *msg)
|
||||
{
|
||||
LOG_ERR("Panic: %s", msg);
|
||||
for (;;) {
|
||||
k_sleep(K_FOREVER);
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
transmit(char buffer[], size_t len)
|
||||
{
|
||||
struct net_pkt *send_pkt;
|
||||
int ret;
|
||||
|
||||
send_pkt = net_app_get_net_pkt(&app_ctx, AF_UNSPEC, BUF_ALLOC_TIMEOUT);
|
||||
if (!send_pkt) {
|
||||
LOG_ERR("Unable to get TX packet, not enough memory.");
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
if (!net_pkt_append_all(send_pkt, len, (u8_t *)buffer,
|
||||
BUF_ALLOC_TIMEOUT)) {
|
||||
net_pkt_unref(send_pkt);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ret = net_app_send_pkt(&app_ctx, send_pkt,
|
||||
&app_ctx.default_ctx->remote,
|
||||
NET_SOCKADDR_MAX_SIZE, K_NO_WAIT, NULL);
|
||||
if (ret < 0) {
|
||||
net_pkt_unref(send_pkt);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void
|
||||
on_cmd_ping(char *umask, char *cmd, size_t len)
|
||||
{
|
||||
char pong[32];
|
||||
int ret;
|
||||
|
||||
LOG_INF("Got PING command from server: %s", cmd);
|
||||
|
||||
ret = snprintk(pong, 32, "PONG :%s", cmd + 1);
|
||||
if (ret < sizeof(pong)) {
|
||||
ret = transmit(pong, ret);
|
||||
if (ret < 0) {
|
||||
LOG_INF("Transmit error: %d", ret);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
on_cmd_privmsg(char *umask, char *cmd, size_t len)
|
||||
{
|
||||
char *space;
|
||||
|
||||
if (!umask) {
|
||||
/* Don't know how this got here, so ignore */
|
||||
return;
|
||||
}
|
||||
|
||||
LOG_DBG("Got message from umask %s: %s", umask, cmd);
|
||||
|
||||
space = memchr(cmd, ' ', len);
|
||||
if (!space) {
|
||||
return;
|
||||
}
|
||||
|
||||
*space = '\0';
|
||||
|
||||
if (*(space + 1) != ':') {
|
||||
/* Just ignore messages without a ':' after the space */
|
||||
LOG_DBG("Ignoring message umask: %s: %s", umask, space);
|
||||
return;
|
||||
}
|
||||
|
||||
space += 2; /* Jump over the ':', pointing to the message itself */
|
||||
|
||||
/* check for a private message from another user */
|
||||
if (!strncmp(nick_buf, cmd, NICK_BUFFER_SIZE)) {
|
||||
on_msg_rcvd(umask, umask, space);
|
||||
} else {
|
||||
on_msg_rcvd(cmd, umask, space);
|
||||
}
|
||||
}
|
||||
|
||||
#define CMD(cmd_, cb_) { \
|
||||
.cmd = cmd_ " ", \
|
||||
.cmd_len = sizeof(cmd_ " ") - 1, \
|
||||
.func = on_cmd_ ## cb_ \
|
||||
}
|
||||
static void
|
||||
process_command(char *cmd, size_t len)
|
||||
{
|
||||
static const struct {
|
||||
const char *cmd;
|
||||
size_t cmd_len;
|
||||
void (*func)(char *umask, char *cmd, size_t len);
|
||||
} commands[] = {
|
||||
CMD("PING", ping),
|
||||
CMD("PRIVMSG", privmsg),
|
||||
};
|
||||
char *umask;
|
||||
int i;
|
||||
|
||||
if (*cmd == ':') {
|
||||
char *space = memchr(cmd, ' ', len);
|
||||
|
||||
if (!space) {
|
||||
return;
|
||||
}
|
||||
|
||||
umask = cmd + 1;
|
||||
*space = '\0';
|
||||
|
||||
len -= (space - cmd) + 1;
|
||||
if (!len) {
|
||||
return;
|
||||
}
|
||||
|
||||
cmd = space + 1;
|
||||
|
||||
LOG_DBG("Received from server, umask=%s: %s", umask, cmd);
|
||||
} else {
|
||||
umask = NULL;
|
||||
|
||||
LOG_DBG("Received from server (no umask): %s", cmd);
|
||||
}
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(commands); i++) {
|
||||
if (len < commands[i].cmd_len) {
|
||||
continue;
|
||||
}
|
||||
if (!strncmp(cmd, commands[i].cmd, commands[i].cmd_len)) {
|
||||
LOG_DBG("Command has handler, executing");
|
||||
|
||||
cmd += commands[i].cmd_len;
|
||||
len -= commands[i].cmd_len;
|
||||
commands[i].func(umask, cmd, len);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* TODO: handle notices, CTCP, etc */
|
||||
LOG_DBG("Could not find handler to handle %s, ignoring", cmd);
|
||||
}
|
||||
#undef CMD
|
||||
|
||||
static void
|
||||
on_context_recv(struct net_app_ctx *ctx, struct net_pkt *pkt,
|
||||
int status, void *data)
|
||||
{
|
||||
struct net_buf *tmp;
|
||||
u16_t pos = 0U;
|
||||
|
||||
if (!pkt) {
|
||||
/* TODO: notify of disconnection, maybe reconnect? */
|
||||
LOG_ERR("Disconnected");
|
||||
return;
|
||||
}
|
||||
|
||||
if (status) {
|
||||
/* TODO: handle connection error */
|
||||
LOG_ERR("Connection error: %d", -status);
|
||||
net_pkt_unref(pkt);
|
||||
return;
|
||||
}
|
||||
|
||||
/* tmp points to fragment containing IP header */
|
||||
tmp = pkt->frags;
|
||||
/* skip pos to the first TCP payload */
|
||||
pos = net_pkt_appdata(pkt) - tmp->data;
|
||||
|
||||
while (true) {
|
||||
if (cmd_len >= CMD_BUFFER_SIZE) {
|
||||
LOG_WRN("cmd_buf overrun (>%d) Ignoring",
|
||||
CMD_BUFFER_SIZE);
|
||||
cmd_len = 0U;
|
||||
}
|
||||
|
||||
tmp = net_frag_read(tmp, pos, &pos, 1, cmd_buf + cmd_len);
|
||||
if (*(cmd_buf + cmd_len) == '\r') {
|
||||
cmd_buf[cmd_len] = '\0';
|
||||
process_command((char *)cmd_buf, cmd_len);
|
||||
/* skip the \n after \r */
|
||||
tmp = net_frag_read(tmp, pos, &pos, 1, NULL);
|
||||
cmd_len = 0U;
|
||||
} else {
|
||||
cmd_len++;
|
||||
}
|
||||
|
||||
if (!tmp || pos == 0xFFFF) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
net_pkt_unref(pkt);
|
||||
}
|
||||
|
||||
static int
|
||||
zirc_nick_set(const char *nick)
|
||||
{
|
||||
char buffer[32];
|
||||
int ret;
|
||||
|
||||
LOG_INF("Setting nickname to: %s", nick);
|
||||
|
||||
ret = snprintk(buffer, sizeof(buffer), "NICK %s\r\n", nick);
|
||||
if (ret < 0 || ret >= sizeof(buffer)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return transmit(buffer, ret);
|
||||
}
|
||||
|
||||
static int
|
||||
zirc_user_set(const char *user, const char *realname)
|
||||
{
|
||||
char buffer[64];
|
||||
int ret;
|
||||
|
||||
LOG_INF("Setting user to: %s, real name to: %s", user, realname);
|
||||
|
||||
ret = snprintk(buffer, sizeof(buffer), "USER %s * * :%s\r\n",
|
||||
user, realname);
|
||||
if (ret < 0 || ret >= sizeof(buffer)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return transmit(buffer, ret);
|
||||
}
|
||||
|
||||
static int
|
||||
zirc_chan_join(const char *channel)
|
||||
{
|
||||
char buffer[32];
|
||||
int ret;
|
||||
|
||||
LOG_INF("Joining channel: %s", channel);
|
||||
|
||||
ret = snprintk(buffer, sizeof(buffer), "JOIN %s\r\n", channel);
|
||||
if (ret < 0 || ret >= sizeof(buffer)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ret = transmit(buffer, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int
|
||||
zirc_chan_part(char *chan_name)
|
||||
{
|
||||
char buffer[32];
|
||||
int ret;
|
||||
|
||||
LOG_INF("Leaving channel: %s", chan_name);
|
||||
|
||||
ret = snprintk(buffer, sizeof(buffer), "PART %s\r\n", chan_name);
|
||||
if (ret < 0 || ret >= sizeof(buffer)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ret = transmit(buffer, ret);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
zirc_connect(const char *host, int port)
|
||||
{
|
||||
int ret;
|
||||
|
||||
LOG_INF("Connecting to %s:%d...", host, port);
|
||||
|
||||
ret = net_app_init_tcp_client(&app_ctx, NULL, NULL,
|
||||
host, port,
|
||||
WAIT_TIMEOUT, NULL);
|
||||
if (ret < 0) {
|
||||
LOG_ERR("net_app_init_tcp_client err:%d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#if defined(CONFIG_NET_CONTEXT_NET_PKT_POOL)
|
||||
net_app_set_net_pkt_pool(&app_ctx, tx_slab, data_pool);
|
||||
#endif
|
||||
|
||||
/* set net_app callbacks */
|
||||
ret = net_app_set_cb(&app_ctx, NULL, on_context_recv, NULL, NULL);
|
||||
if (ret < 0) {
|
||||
LOG_ERR("Could not set receive callback (err:%d)", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = net_app_connect(&app_ctx, CONNECT_TIMEOUT);
|
||||
if (ret < 0) {
|
||||
LOG_ERR("Cannot connect (%d)", ret);
|
||||
panic("Can't init network");
|
||||
}
|
||||
|
||||
if (zirc_nick_set(nick_buf) < 0) {
|
||||
panic("Could not set nick");
|
||||
}
|
||||
|
||||
if (zirc_user_set(nick_buf, "Zephyr IRC Bot") < 0) {
|
||||
panic("Could not set user");
|
||||
}
|
||||
|
||||
if (zirc_chan_join(DEFAULT_CHANNEL) < 0) {
|
||||
panic("Could not join channel");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int
|
||||
zirc_disconnect(void)
|
||||
{
|
||||
LOG_INF("Disconnecting");
|
||||
cmd_len = 0U;
|
||||
net_app_close(&app_ctx);
|
||||
return net_app_release(&app_ctx);
|
||||
}
|
||||
|
||||
static int
|
||||
zirc_chan_send_msg(const char *chan_name, const char *msg)
|
||||
{
|
||||
char buffer[128];
|
||||
|
||||
LOG_INF("Sending to channel/user %s: %s", chan_name, msg);
|
||||
|
||||
while (*msg) {
|
||||
int msglen, txret;
|
||||
|
||||
msglen = snprintk(buffer, sizeof(buffer), "PRIVMSG %s :%s\r\n",
|
||||
chan_name, msg);
|
||||
|
||||
if (msglen < 0) {
|
||||
return msglen;
|
||||
}
|
||||
|
||||
txret = transmit(buffer, msglen);
|
||||
if (txret < 0) {
|
||||
return txret;
|
||||
}
|
||||
|
||||
if (msglen < sizeof(buffer)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
msg += msglen - sizeof("PRIVMSG :\r\n") - 1 +
|
||||
strlen(chan_name);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
on_cmd_hello(char *chan_name, const char *nick, const char *msg)
|
||||
{
|
||||
char buf[64];
|
||||
int ret;
|
||||
|
||||
ret = snprintk(buf, sizeof(buf), "Hello, %s!", nick);
|
||||
if (ret < 0 || ret >= sizeof(buf)) {
|
||||
zirc_chan_send_msg(chan_name, "Hello, world! (Your nick is "
|
||||
"larger than my stack allows.)");
|
||||
} else {
|
||||
zirc_chan_send_msg(chan_name, buf);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
on_cmd_random(char *chan_name, const char *nick, const char *msg)
|
||||
{
|
||||
char buf[128];
|
||||
s32_t num = sys_rand32_get();
|
||||
int ret;
|
||||
|
||||
switch (num & 3) {
|
||||
case 0:
|
||||
ret = snprintk(buf, sizeof(buf), "Here's a fresh, random "
|
||||
"32-bit integer, %s: %d", nick, num);
|
||||
break;
|
||||
case 1:
|
||||
ret = snprintk(buf, sizeof(buf), "Another number, fresh off "
|
||||
"the PRNG: %d", num);
|
||||
break;
|
||||
case 2:
|
||||
ret = snprintk(buf, sizeof(buf), "Some calculations "
|
||||
"with senseless constants yielded %d", num);
|
||||
break;
|
||||
case 3:
|
||||
ret = snprintk(buf, sizeof(buf), "I rolled a fair dice and "
|
||||
"the result is... %d", num);
|
||||
break;
|
||||
default:
|
||||
/* Shut up the compiler, as this condition is impossible. */
|
||||
ret = -1;
|
||||
}
|
||||
|
||||
if (ret < 0 || ret >= sizeof(buf)) {
|
||||
zirc_chan_send_msg(chan_name, "I rolled a fair dice and the "
|
||||
"number is... 7.3");
|
||||
} else {
|
||||
zirc_chan_send_msg(chan_name, buf);
|
||||
}
|
||||
}
|
||||
|
||||
static bool
|
||||
read_led(void)
|
||||
{
|
||||
u32_t led = 0U;
|
||||
int r;
|
||||
|
||||
if (!led0) {
|
||||
return fake_led;
|
||||
}
|
||||
|
||||
r = gpio_pin_read(led0, LED_PIN, &led);
|
||||
if (r < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return !led;
|
||||
}
|
||||
|
||||
static void
|
||||
write_led(bool led)
|
||||
{
|
||||
if (!led0) {
|
||||
fake_led = led;
|
||||
} else {
|
||||
gpio_pin_write(led0, LED_PIN, !led);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
on_cmd_led_off(char *chan_name, const char *nick, const char *msg)
|
||||
{
|
||||
zirc_chan_send_msg(chan_name, "The LED should be *off* now");
|
||||
write_led(false);
|
||||
}
|
||||
|
||||
static void
|
||||
on_cmd_led_on(char *chan_name, const char *nick, const char *msg)
|
||||
{
|
||||
zirc_chan_send_msg(chan_name, "The LED should be *on* now");
|
||||
write_led(true);
|
||||
}
|
||||
|
||||
static void
|
||||
on_cmd_led_toggle(char *chan_name, const char *nick, const char *msg)
|
||||
{
|
||||
if (read_led()) {
|
||||
on_cmd_led_off(chan_name, nick, msg);
|
||||
} else {
|
||||
on_cmd_led_on(chan_name, nick, msg);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
on_cmd_rejoin(char *chan_name, const char *nick, const char *msg)
|
||||
{
|
||||
/* make sure this isn't a private message */
|
||||
if (!strncmp(nick, chan_name, NICK_BUFFER_SIZE)) {
|
||||
zirc_chan_send_msg(chan_name,
|
||||
"I can't rejoin a private message!");
|
||||
} else {
|
||||
zirc_chan_part(chan_name);
|
||||
zirc_chan_join(chan_name);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
on_cmd_disconnect(char *chan_name, const char *nick, const char *msg)
|
||||
{
|
||||
zirc_disconnect();
|
||||
}
|
||||
|
||||
#define CMD(c) { \
|
||||
.cmd = "!" #c, \
|
||||
.cmd_len = sizeof(#c) - 1, \
|
||||
.func = on_cmd_ ## c \
|
||||
}
|
||||
static void
|
||||
on_msg_rcvd(char *chan_name, char *umask, char *msg)
|
||||
{
|
||||
static const struct {
|
||||
const char *cmd;
|
||||
size_t cmd_len;
|
||||
void (*func)(char *chan_name, const char *nick,
|
||||
const char *msg);
|
||||
} commands[] = {
|
||||
CMD(hello),
|
||||
CMD(random),
|
||||
CMD(led_toggle),
|
||||
CMD(led_off),
|
||||
CMD(led_on),
|
||||
CMD(rejoin),
|
||||
CMD(disconnect),
|
||||
};
|
||||
char *nick, *end;
|
||||
int i;
|
||||
|
||||
if (!umask) {
|
||||
return;
|
||||
}
|
||||
|
||||
LOG_DBG("Received from umask %s: %s", umask, msg);
|
||||
|
||||
end = strchr(umask, '!');
|
||||
if (!end) {
|
||||
nick = NULL;
|
||||
} else {
|
||||
*end = '\0';
|
||||
nick = umask;
|
||||
}
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(commands); i++) {
|
||||
if (!strncmp(msg, commands[i].cmd, commands[i].cmd_len)) {
|
||||
msg += commands[i].cmd_len;
|
||||
commands[i].func(chan_name, nick, msg);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!strncmp(msg, "!help", 5)) {
|
||||
char msg[64];
|
||||
int ret;
|
||||
|
||||
/* TODO: loop through commands[] and create help text */
|
||||
/* TODO: add help message to command, "!help command"
|
||||
* sends it back
|
||||
*/
|
||||
|
||||
ret = snprintk(msg, sizeof(msg), "%s, you're a grown up, figure"
|
||||
" it out", nick);
|
||||
if (ret < 0 || ret >= sizeof(msg)) {
|
||||
zirc_chan_send_msg(chan_name,
|
||||
"Your nick is too long, and my"
|
||||
" stack is limited. Can't help you");
|
||||
} else {
|
||||
zirc_chan_send_msg(chan_name, msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
#undef CMD
|
||||
|
||||
void main(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
LOG_INF(APP_BANNER);
|
||||
|
||||
led0 = device_get_binding(LED_GPIO_NAME);
|
||||
if (led0) {
|
||||
gpio_pin_configure(led0, LED_PIN, GPIO_DIR_OUT);
|
||||
}
|
||||
|
||||
cmd_len = 0U;
|
||||
|
||||
/* setup IRC nick for max 16 chars */
|
||||
ret = snprintk(nick_buf, sizeof(nick_buf), "zephyrbot%05u",
|
||||
sys_rand32_get() & 0xFFFF);
|
||||
if (ret < 0 || ret >= sizeof(nick_buf)) {
|
||||
panic("Can't fill nick buffer");
|
||||
}
|
||||
|
||||
ret = zirc_connect(DEFAULT_SERVER, DEFAULT_PORT);
|
||||
if (ret < 0 && ret != -EINPROGRESS) {
|
||||
panic("Could not connect");
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
k_sleep(K_FOREVER);
|
||||
}
|
||||
}
|
|
@ -26,7 +26,6 @@ CONFIG_NET_SHELL=y
|
|||
# Ethernet is needed for LLDP
|
||||
CONFIG_NET_L2_ETHERNET=y
|
||||
|
||||
CONFIG_NET_APP_SERVER=y
|
||||
CONFIG_NET_CONFIG_NEED_IPV6=y
|
||||
CONFIG_NET_CONFIG_NEED_IPV4=y
|
||||
CONFIG_NET_CONFIG_SETTINGS=y
|
||||
|
|
|
@ -20,6 +20,8 @@
|
|||
#include <net/socket.h>
|
||||
#include <kernel.h>
|
||||
|
||||
#include <net/buf.h>
|
||||
|
||||
#endif
|
||||
|
||||
#define PORT 8080
|
||||
|
|
|
@ -35,7 +35,6 @@ CONFIG_PRINTK=y
|
|||
CONFIG_NET_SHELL=y
|
||||
|
||||
# Application configuration
|
||||
CONFIG_NET_APP_SERVER=y
|
||||
CONFIG_NET_CONFIG_NEED_IPV6=y
|
||||
CONFIG_NET_CONFIG_NEED_IPV4=y
|
||||
CONFIG_NET_CONFIG_SETTINGS=y
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
cmake_minimum_required(VERSION 3.13.1)
|
||||
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
|
||||
project(throughput_server)
|
||||
|
||||
target_sources( app PRIVATE src/server.c)
|
||||
target_sources_ifdef(CONFIG_NET_UDP app PRIVATE src/udp.c)
|
||||
|
||||
include($ENV{ZEPHYR_BASE}/samples/net/common/common.cmake)
|
|
@ -1,65 +0,0 @@
|
|||
.. _throughput-server-sample:
|
||||
|
||||
Throughput Server
|
||||
#################
|
||||
|
||||
Overview
|
||||
********
|
||||
|
||||
The throughput-server sample application for Zephyr implements a UDP server
|
||||
that complements the throughput-client tool from Zephyr `net-tools`_ repository.
|
||||
The throughput-server listens for incoming IPv4 or IPv6 packets (sent by the
|
||||
throughput-client) and optionally sends the packets back.
|
||||
Note that it makes sense to use this sample (only) with high-performance
|
||||
bearer like Ethernet.
|
||||
|
||||
The source code for this sample application can be found at:
|
||||
:file:`samples/net/throughput_server`.
|
||||
|
||||
Building and Running
|
||||
********************
|
||||
|
||||
The application can be used on multiple boards and with different bearers.
|
||||
Emulation using QEMU is not recommended because the ethernet connection in
|
||||
QEMU is done using a serial port with SLIP, so it is very slow.
|
||||
|
||||
There are configuration files for different boards and setups in the
|
||||
throughput-server directory:
|
||||
|
||||
- :file:`prj_frdm_k64f.conf`
|
||||
Use this for FRDM-K64F board with built-in ethernet.
|
||||
|
||||
Build throughput-server sample application like this:
|
||||
|
||||
.. zephyr-app-commands::
|
||||
:zephyr-app: samples/net/throughput_server
|
||||
:board: <board to use>
|
||||
:conf: <config file to use>
|
||||
:goals: build
|
||||
:compact:
|
||||
|
||||
Make will select the default configuration file based on the BOARD you
|
||||
specified to CMake.
|
||||
|
||||
Note that shell support is not activated in the throughput-server so that
|
||||
we can save some memory and have as many net_buf's configured in the system
|
||||
as possible.
|
||||
|
||||
Running throughput-client in Linux Host
|
||||
=======================================
|
||||
|
||||
In this example, the throughput-server is run on a board and throughput-client
|
||||
is run on a Linux host. The throughput-client can be found at the `net-tools`_
|
||||
project.
|
||||
|
||||
Open a terminal window and type:
|
||||
|
||||
.. code-block:: console
|
||||
|
||||
$ cd net-tools
|
||||
$ ./throughput-client -F -s 200 2001:db8::1
|
||||
|
||||
Note that throughput-server must be running on the device under test before you
|
||||
start the throughput-client application in a host terminal window.
|
||||
|
||||
.. _`net-tools`: https://github.com/zephyrproject-rtos/net-tools
|
|
@ -1,40 +0,0 @@
|
|||
CONFIG_NETWORKING=y
|
||||
CONFIG_NET_UDP=y
|
||||
CONFIG_NET_TCP=n
|
||||
CONFIG_NET_IPV6=y
|
||||
CONFIG_NET_IPV4=y
|
||||
#CONFIG_NET_DHCPV4=y
|
||||
|
||||
CONFIG_ENTROPY_GENERATOR=y
|
||||
CONFIG_TEST_RANDOM_GENERATOR=y
|
||||
CONFIG_INIT_STACKS=y
|
||||
|
||||
CONFIG_NET_LOG=y
|
||||
CONFIG_LOG=y
|
||||
CONFIG_NET_STATISTICS=y
|
||||
CONFIG_PRINTK=y
|
||||
|
||||
CONFIG_NET_PKT_RX_COUNT=500
|
||||
CONFIG_NET_PKT_TX_COUNT=5
|
||||
CONFIG_NET_BUF_RX_COUNT=710
|
||||
CONFIG_NET_BUF_TX_COUNT=9
|
||||
CONFIG_NET_CONTEXT_NET_PKT_POOL=n
|
||||
|
||||
CONFIG_NET_IF_UNICAST_IPV6_ADDR_COUNT=2
|
||||
CONFIG_NET_IF_MCAST_IPV6_ADDR_COUNT=3
|
||||
CONFIG_NET_MAX_CONTEXTS=3
|
||||
|
||||
# Do not enable shell as that will use precious ram
|
||||
CONFIG_NET_SHELL=n
|
||||
|
||||
CONFIG_NET_APP_SERVER=y
|
||||
CONFIG_NET_CONFIG_SETTINGS=y
|
||||
CONFIG_NET_CONFIG_NEED_IPV6=y
|
||||
CONFIG_NET_CONFIG_NEED_IPV4=y
|
||||
CONFIG_NET_CONFIG_MY_IPV6_ADDR="2001:db8::1"
|
||||
CONFIG_NET_CONFIG_PEER_IPV6_ADDR="2001:db8::2"
|
||||
CONFIG_NET_CONFIG_MY_IPV4_ADDR="192.0.2.1"
|
||||
CONFIG_NET_CONFIG_PEER_IPV4_ADDR="192.0.2.2"
|
||||
|
||||
CONFIG_ETH_MCUX_RX_BUFFERS=16
|
||||
CONFIG_COVERAGE=n
|
|
@ -1,10 +0,0 @@
|
|||
common:
|
||||
harness: net
|
||||
tags: net
|
||||
sample:
|
||||
description: Test packet receival throughput.
|
||||
name: Throughput Server
|
||||
tests:
|
||||
test_frdm_k64f:
|
||||
platform_whitelist: frdm_k64f
|
||||
extra_args: CONF_FILE="prj_frdm_k64f.conf"
|
|
@ -1,36 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2018 Intel Corporation.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#define MY_PORT 42042
|
||||
|
||||
#define MAX_DBG_PRINT 64
|
||||
|
||||
struct tp_stats {
|
||||
struct {
|
||||
u32_t prev_recv;
|
||||
u32_t recv;
|
||||
u32_t sent;
|
||||
u32_t dropped;
|
||||
} pkts;
|
||||
|
||||
struct {
|
||||
u32_t recv;
|
||||
u32_t sent;
|
||||
} bytes;
|
||||
};
|
||||
|
||||
extern struct tp_stats tp_stats;
|
||||
|
||||
void print_statistics(void);
|
||||
|
||||
void start_udp(void);
|
||||
void stop_udp(void);
|
||||
|
||||
struct net_pkt *build_reply_pkt(const char *name,
|
||||
struct net_app_ctx *ctx,
|
||||
struct net_pkt *pkt);
|
||||
void pkt_sent(struct net_app_ctx *ctx, int status,
|
||||
void *token, void *user_data);
|
|
@ -1,197 +0,0 @@
|
|||
/* server.c - Networking server for measuring networking throughput */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2018 Intel Corporation.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <logging/log.h>
|
||||
LOG_MODULE_REGISTER(net_tp_server_sample, LOG_LEVEL_DBG);
|
||||
|
||||
#include <zephyr.h>
|
||||
#include <linker/sections.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <net/net_pkt.h>
|
||||
#include <net/net_core.h>
|
||||
#include <net/net_context.h>
|
||||
|
||||
#include <net/net_app.h>
|
||||
|
||||
#include "common.h"
|
||||
|
||||
/* The startup time needs to be longish if DHCP is enabled as setting
|
||||
* DHCP up takes some time.
|
||||
*/
|
||||
#define APP_STARTUP_TIME K_SECONDS(20)
|
||||
|
||||
#define APP_BANNER "Running throughput server"
|
||||
|
||||
struct tp_stats tp_stats;
|
||||
|
||||
static struct k_sem quit_lock;
|
||||
|
||||
void quit(void)
|
||||
{
|
||||
k_sem_give(&quit_lock);
|
||||
}
|
||||
|
||||
struct net_pkt *build_reply_pkt(const char *name,
|
||||
struct net_app_ctx *ctx,
|
||||
struct net_pkt *pkt)
|
||||
{
|
||||
struct net_pkt *reply_pkt;
|
||||
struct net_buf *frag, *tmp;
|
||||
int header_len = 0, recv_len, reply_len;
|
||||
|
||||
LOG_DBG("%s received %d bytes", name, net_pkt_appdatalen(pkt));
|
||||
|
||||
if (net_pkt_appdatalen(pkt) == 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
reply_pkt = net_app_get_net_pkt(ctx, net_pkt_family(pkt), K_FOREVER);
|
||||
|
||||
NET_ASSERT(reply_pkt);
|
||||
NET_ASSERT(net_pkt_family(reply_pkt) == net_pkt_family(pkt));
|
||||
|
||||
recv_len = net_pkt_get_len(pkt);
|
||||
|
||||
tmp = pkt->frags;
|
||||
|
||||
/* If we have link layer headers, then get rid of them here. */
|
||||
if (recv_len != net_pkt_appdatalen(pkt)) {
|
||||
/* First fragment will contain IP header so move the data
|
||||
* down in order to get rid of it.
|
||||
*/
|
||||
header_len = net_pkt_appdata(pkt) - tmp->data;
|
||||
|
||||
NET_ASSERT(header_len < CONFIG_NET_BUF_DATA_SIZE);
|
||||
|
||||
/* After this pull, the tmp->data points directly to application
|
||||
* data.
|
||||
*/
|
||||
net_buf_pull(tmp, header_len);
|
||||
}
|
||||
|
||||
net_pkt_set_appdatalen(reply_pkt, net_pkt_appdatalen(pkt));
|
||||
|
||||
while (tmp) {
|
||||
frag = net_app_get_net_buf(ctx, reply_pkt, K_FOREVER);
|
||||
|
||||
if (net_buf_headroom(tmp) == 0) {
|
||||
/* If there is no link layer headers in the
|
||||
* received fragment, then get rid of that also
|
||||
* in the sending fragment. We end up here
|
||||
* if MTU is larger than fragment size, this
|
||||
* is typical for ethernet.
|
||||
*/
|
||||
net_buf_push(frag, net_buf_headroom(frag));
|
||||
|
||||
frag->len = 0; /* to make fragment empty */
|
||||
}
|
||||
|
||||
NET_ASSERT_INFO(net_buf_tailroom(frag) >= tmp->len,
|
||||
"tail %zd longer than len %d",
|
||||
net_buf_tailroom(frag), tmp->len);
|
||||
|
||||
memcpy(net_buf_add(frag, tmp->len), tmp->data, tmp->len);
|
||||
|
||||
tmp = net_pkt_frag_del(pkt, NULL, tmp);
|
||||
}
|
||||
|
||||
reply_len = net_pkt_get_len(reply_pkt);
|
||||
|
||||
NET_ASSERT_INFO((recv_len - header_len) == reply_len,
|
||||
"Received %d bytes, sending %d bytes",
|
||||
recv_len - header_len, reply_len);
|
||||
|
||||
return reply_pkt;
|
||||
}
|
||||
|
||||
#define PRINT_STATS_SECS 15
|
||||
#define PRINT_STATISTICS_INTERVAL K_SECONDS(PRINT_STATS_SECS)
|
||||
|
||||
static inline s64_t cmp_val(u64_t val1, u64_t val2)
|
||||
{
|
||||
return (s64_t)(val1 - val2);
|
||||
}
|
||||
|
||||
static inline void stats(void)
|
||||
{
|
||||
static u64_t next_print;
|
||||
static bool first_print;
|
||||
static u32_t count;
|
||||
u64_t curr = k_uptime_get();
|
||||
s64_t cmp = cmp_val(curr, next_print);
|
||||
|
||||
if (!next_print || (abs(cmp) > PRINT_STATISTICS_INTERVAL)) {
|
||||
if (!first_print) {
|
||||
first_print = true;
|
||||
} else {
|
||||
LOG_INF("[%u]", ++count);
|
||||
LOG_INF("Packets received %u", tp_stats.pkts.recv);
|
||||
#if defined(SEND_REPLY)
|
||||
LOG_INF("Packets sent %u", tp_stats.pkts.sent);
|
||||
#endif
|
||||
LOG_INF("Packets dropped %u", tp_stats.pkts.dropped);
|
||||
LOG_INF("Bytes received %u", tp_stats.bytes.recv);
|
||||
#if defined(SEND_REPLY)
|
||||
LOG_INF("Bytes sent %u", tp_stats.bytes.sent);
|
||||
#endif
|
||||
LOG_INF("Packets / period %u", tp_stats.pkts.recv -
|
||||
tp_stats.pkts.prev_recv);
|
||||
LOG_INF("Packets / sec %u", (tp_stats.pkts.recv -
|
||||
tp_stats.pkts.prev_recv) /
|
||||
PRINT_STATS_SECS);
|
||||
}
|
||||
|
||||
next_print = curr + PRINT_STATISTICS_INTERVAL;
|
||||
|
||||
tp_stats.pkts.prev_recv = tp_stats.pkts.recv;
|
||||
}
|
||||
}
|
||||
|
||||
void print_statistics(void)
|
||||
{
|
||||
/* In order to make the info print lines shorter, use shorter
|
||||
* function name.
|
||||
*/
|
||||
stats();
|
||||
}
|
||||
|
||||
void pkt_sent(struct net_app_ctx *ctx,
|
||||
int status,
|
||||
void *user_data_send,
|
||||
void *user_data)
|
||||
{
|
||||
if (!status) {
|
||||
LOG_DBG("Sent %d bytes", POINTER_TO_UINT(user_data_send));
|
||||
}
|
||||
}
|
||||
|
||||
static inline int init_app(void)
|
||||
{
|
||||
k_sem_init(&quit_lock, 0, UINT_MAX);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void main(void)
|
||||
{
|
||||
init_app();
|
||||
|
||||
if (IS_ENABLED(CONFIG_NET_UDP)) {
|
||||
start_udp();
|
||||
}
|
||||
|
||||
k_sem_take(&quit_lock, K_FOREVER);
|
||||
|
||||
LOG_INF("Stopping...");
|
||||
|
||||
if (IS_ENABLED(CONFIG_NET_UDP)) {
|
||||
stop_udp();
|
||||
}
|
||||
}
|
|
@ -1,205 +0,0 @@
|
|||
/* udp.c - UDP specific code for throughput server */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2018 Intel Corporation.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <logging/log.h>
|
||||
LOG_MODULE_DECLARE(net_tp_server_sample, LOG_LEVEL_DBG);
|
||||
|
||||
#include <zephyr.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <net/net_pkt.h>
|
||||
#include <net/net_core.h>
|
||||
#include <net/net_context.h>
|
||||
#include <net/udp.h>
|
||||
|
||||
#include <net/net_app.h>
|
||||
|
||||
#include "common.h"
|
||||
|
||||
#define STATS_CHECK 1000
|
||||
|
||||
#define TYPE_SEQ_NUM 42
|
||||
|
||||
struct header {
|
||||
unsigned char type;
|
||||
unsigned char len;
|
||||
unsigned char value[0];
|
||||
} __packed;
|
||||
|
||||
static struct net_app_ctx udp;
|
||||
|
||||
/* Note that both tcp and udp can share the same pool but in this
|
||||
* example the UDP context and TCP context have separate pools.
|
||||
*/
|
||||
#if defined(CONFIG_NET_CONTEXT_NET_PKT_POOL)
|
||||
NET_PKT_SLAB_DEFINE(echo_tx_udp, 100);
|
||||
NET_PKT_DATA_POOL_DEFINE(echo_data_udp, 200);
|
||||
|
||||
static struct k_mem_slab *tx_udp_slab(void)
|
||||
{
|
||||
return &echo_tx_udp;
|
||||
}
|
||||
|
||||
static struct net_buf_pool *data_udp_pool(void)
|
||||
{
|
||||
return &echo_data_udp;
|
||||
}
|
||||
#else
|
||||
#define tx_udp_slab NULL
|
||||
#define data_udp_pool NULL
|
||||
#endif /* CONFIG_NET_CONTEXT_NET_PKT_POOL */
|
||||
|
||||
static inline void set_dst_addr(sa_family_t family,
|
||||
struct net_pkt *pkt,
|
||||
struct sockaddr *dst_addr)
|
||||
{
|
||||
struct net_udp_hdr hdr, *udp_hdr;
|
||||
|
||||
udp_hdr = net_udp_get_hdr(pkt, &hdr);
|
||||
if (!udp_hdr) {
|
||||
return;
|
||||
}
|
||||
|
||||
#if defined(CONFIG_NET_IPV6)
|
||||
if (family == AF_INET6) {
|
||||
net_ipaddr_copy(&net_sin6(dst_addr)->sin6_addr,
|
||||
&NET_IPV6_HDR(pkt)->src);
|
||||
net_sin6(dst_addr)->sin6_family = AF_INET6;
|
||||
net_sin6(dst_addr)->sin6_port = udp_hdr->src_port;
|
||||
}
|
||||
#endif /* CONFIG_NET_IPV6) */
|
||||
|
||||
#if defined(CONFIG_NET_IPV4)
|
||||
if (family == AF_INET) {
|
||||
net_ipaddr_copy(&net_sin(dst_addr)->sin_addr,
|
||||
&NET_IPV4_HDR(pkt)->src);
|
||||
net_sin(dst_addr)->sin_family = AF_INET;
|
||||
net_sin(dst_addr)->sin_port = udp_hdr->src_port;
|
||||
}
|
||||
#endif /* CONFIG_NET_IPV6) */
|
||||
}
|
||||
|
||||
static void udp_received(struct net_app_ctx *ctx,
|
||||
struct net_pkt *pkt,
|
||||
int status,
|
||||
void *user_data)
|
||||
{
|
||||
static char dbg[MAX_DBG_PRINT + 1];
|
||||
static u32_t prev_seq;
|
||||
static u32_t count;
|
||||
struct sockaddr dst_addr;
|
||||
struct header *hdr;
|
||||
sa_family_t family = net_pkt_family(pkt);
|
||||
socklen_t dst_len;
|
||||
u32_t pkt_len;
|
||||
#if defined(SEND_REPLY)
|
||||
struct net_pkt *reply_pkt;
|
||||
int ret;
|
||||
#endif
|
||||
|
||||
snprintk(dbg, MAX_DBG_PRINT, "UDP IPv%c",
|
||||
family == AF_INET6 ? '6' : '4');
|
||||
|
||||
if (family == AF_INET6) {
|
||||
dst_len = sizeof(struct sockaddr_in6);
|
||||
} else {
|
||||
dst_len = sizeof(struct sockaddr_in);
|
||||
}
|
||||
|
||||
set_dst_addr(family, pkt, &dst_addr);
|
||||
|
||||
#if defined(SEND_REPLY)
|
||||
reply_pkt = build_reply_pkt(dbg, ctx, pkt);
|
||||
#endif
|
||||
|
||||
pkt_len = net_pkt_appdatalen(pkt);
|
||||
|
||||
tp_stats.bytes.recv += pkt_len;
|
||||
tp_stats.pkts.recv++;
|
||||
|
||||
hdr = (struct header *)net_pkt_appdata(pkt);
|
||||
if (hdr->type == TYPE_SEQ_NUM) {
|
||||
u32_t seq;
|
||||
|
||||
memcpy(&seq, hdr->value, sizeof(seq));
|
||||
seq = ntohl(seq);
|
||||
|
||||
if (seq && prev_seq && seq != (prev_seq + 1)) {
|
||||
tp_stats.pkts.dropped += (seq - prev_seq);
|
||||
}
|
||||
|
||||
prev_seq = seq;
|
||||
}
|
||||
|
||||
net_pkt_unref(pkt);
|
||||
|
||||
#if defined(SEND_REPLY)
|
||||
if (!reply_pkt) {
|
||||
return;
|
||||
}
|
||||
|
||||
pkt_len = net_pkt_appdatalen(reply_pkt);
|
||||
|
||||
ret = net_app_send_pkt(ctx, reply_pkt, &dst_addr, dst_len, K_NO_WAIT,
|
||||
UINT_TO_POINTER(pkt_len));
|
||||
if (ret < 0) {
|
||||
NET_ERR("Cannot send data to peer (%d)", ret);
|
||||
net_pkt_unref(reply_pkt);
|
||||
|
||||
tp_stats.pkt.dropped++;
|
||||
} else {
|
||||
tp_stats.pkt.sent++;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Print statistics only periodically */
|
||||
if (count > STATS_CHECK) {
|
||||
print_statistics();
|
||||
count = 0U;
|
||||
}
|
||||
|
||||
count++;
|
||||
}
|
||||
|
||||
void start_udp(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = net_app_init_udp_server(&udp, NULL, MY_PORT, NULL);
|
||||
if (ret < 0) {
|
||||
NET_ERR("Cannot init UDP service at port %d", MY_PORT);
|
||||
return;
|
||||
}
|
||||
|
||||
#if defined(CONFIG_NET_CONTEXT_NET_PKT_POOL)
|
||||
net_app_set_net_pkt_pool(&udp, tx_udp_slab, data_udp_pool);
|
||||
#endif
|
||||
|
||||
ret = net_app_set_cb(&udp, NULL, udp_received, pkt_sent, NULL);
|
||||
if (ret < 0) {
|
||||
NET_ERR("Cannot set callbacks (%d)", ret);
|
||||
net_app_release(&udp);
|
||||
return;
|
||||
}
|
||||
|
||||
net_app_server_enable(&udp);
|
||||
|
||||
ret = net_app_listen(&udp);
|
||||
if (ret < 0) {
|
||||
NET_ERR("Cannot wait connection (%d)", ret);
|
||||
net_app_release(&udp);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void stop_udp(void)
|
||||
{
|
||||
net_app_close(&udp);
|
||||
net_app_release(&udp);
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
cmake_minimum_required(VERSION 3.13.1)
|
||||
|
||||
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
|
||||
project(traffic_class)
|
||||
|
||||
target_sources(app PRIVATE src/main.c)
|
||||
|
||||
include($ENV{ZEPHYR_BASE}/samples/net/common/common.cmake)
|
|
@ -1,48 +0,0 @@
|
|||
# Kconfig - Private config options for traffic class sample app
|
||||
|
||||
#
|
||||
# Copyright (c) 2018 Intel Corporation
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
|
||||
mainmenu "Networking traffic class sample application"
|
||||
|
||||
config SAMPLE_VLAN_TAG
|
||||
int "Virtual lan tag used in sample app"
|
||||
default 100
|
||||
range 0 4094
|
||||
depends on NET_VLAN
|
||||
help
|
||||
Set virtual lan tag (id) that is used in sample application.
|
||||
|
||||
config SAMPLE_VLAN_TAG_2
|
||||
int "Second VLAN tag used in sample app"
|
||||
default 200
|
||||
range 0 4094
|
||||
depends on NET_VLAN
|
||||
help
|
||||
Set virtual lan tag (id) that is used in sample application.
|
||||
|
||||
config SAMPLE_IPV6_ADDR_2
|
||||
string "My IPv6 address for second interface"
|
||||
help
|
||||
The value depends on your network setup.
|
||||
|
||||
config SAMPLE_IPV4_ADDR_2
|
||||
string "My IPv4 address for second interface"
|
||||
help
|
||||
The value depends on your network setup.
|
||||
|
||||
config SAMPLE_PEER_IPV6_ADDR_2
|
||||
string "Peer IPv6 address for second interface"
|
||||
help
|
||||
The value depends on your network setup.
|
||||
|
||||
config SAMPLE_PEER_IPV4_ADDR_2
|
||||
string "Peer IPv4 address for second interface"
|
||||
help
|
||||
The value depends on your network setup.
|
||||
|
||||
|
||||
source "Kconfig.zephyr"
|
|
@ -1,78 +0,0 @@
|
|||
.. _tc-sample:
|
||||
|
||||
Traffic Class Sample Application
|
||||
################################
|
||||
|
||||
Overview
|
||||
********
|
||||
|
||||
The TC sample application for Zephyr sets up two virtual LAN networks and
|
||||
starts to send prioritized UDP packets from one VLAN network to the other.
|
||||
The use of VLAN network is optional but as VLAN defines priorities to network
|
||||
traffic, it is convenient to use that concept here. The application also
|
||||
enables net-shell and allows user to view VLAN settings.
|
||||
|
||||
The source code for this sample application can be found at:
|
||||
:file:`samples/net/traffic_class`.
|
||||
|
||||
Requirements
|
||||
************
|
||||
|
||||
- :ref:`networking_with_qemu`
|
||||
|
||||
Building and Running
|
||||
********************
|
||||
|
||||
A good way to run this TC application is with QEMU as described in
|
||||
:ref:`networking_with_qemu`.
|
||||
Currently only one VLAN network (tag) is supported when Zephyr is run inside
|
||||
QEMU. If you're using a FRDM-K64F board, then multiple VLAN networks can be
|
||||
configured. Note that VLAN is only supported for boards that have ethernet
|
||||
port.
|
||||
|
||||
Follow these steps to build the TC sample application:
|
||||
|
||||
.. zephyr-app-commands::
|
||||
:zephyr-app: samples/net/traffic_class
|
||||
:board: <board to use>
|
||||
:conf: prj.conf
|
||||
:goals: build
|
||||
:compact:
|
||||
|
||||
The default configuration file prj.conf creates two virtual LAN networks
|
||||
with these settings:
|
||||
|
||||
- VLAN tag 100: IPv4 198.51.100.1 and IPv6 2001:db8:100::1
|
||||
- VLAN tag 200: IPv4 203.0.113.1 and IPv6 2001:db8:200::1
|
||||
|
||||
Setting up Linux Host
|
||||
=====================
|
||||
|
||||
The :file:`samples/net/vlan/vlan-setup-linux.sh` provides a script that can be
|
||||
executed on the Linux host. It creates two VLANs on the Linux host and creates
|
||||
routes to Zephyr.
|
||||
|
||||
If everything is configured correctly, you will be able to successfully execute
|
||||
the following commands on the Linux host.
|
||||
|
||||
.. code-block:: console
|
||||
|
||||
ping -c 1 2001:db8:100::1
|
||||
ping -c 1 198.51.100.1
|
||||
ping -c 1 2001:db8:200::1
|
||||
ping -c 1 203.0.113.1
|
||||
|
||||
Running echo-server in Linux Host
|
||||
=================================
|
||||
|
||||
There is one useful testing scenario that can be used with Linux host.
|
||||
Here traffic-class application is run in QEMU and echo-server is run in
|
||||
Linux host.
|
||||
|
||||
In a terminal window:
|
||||
|
||||
.. code-block:: console
|
||||
|
||||
$ sudo ./echo-server -i tap0
|
||||
|
||||
Then you can run traffic-class application in QEMU as described above.
|
|
@ -1,65 +0,0 @@
|
|||
CONFIG_NETWORKING=y
|
||||
CONFIG_NET_LOG=y
|
||||
CONFIG_LOG=y
|
||||
CONFIG_NET_IPV6=y
|
||||
CONFIG_NET_IPV4=y
|
||||
CONFIG_NET_DHCPV4=n
|
||||
CONFIG_NET_UDP=y
|
||||
CONFIG_NET_TCP=y
|
||||
CONFIG_NET_STATISTICS=y
|
||||
|
||||
CONFIG_TEST_RANDOM_GENERATOR=y
|
||||
|
||||
CONFIG_NET_PKT_RX_COUNT=100
|
||||
CONFIG_NET_PKT_TX_COUNT=200
|
||||
CONFIG_NET_BUF_RX_COUNT=200
|
||||
CONFIG_NET_BUF_TX_COUNT=400
|
||||
CONFIG_NET_IF_UNICAST_IPV6_ADDR_COUNT=5
|
||||
CONFIG_NET_IF_MCAST_IPV6_ADDR_COUNT=5
|
||||
CONFIG_NET_IF_UNICAST_IPV4_ADDR_COUNT=1
|
||||
CONFIG_NET_MAX_CONTEXTS=20
|
||||
|
||||
CONFIG_INIT_STACKS=y
|
||||
CONFIG_PRINTK=y
|
||||
CONFIG_NET_SHELL=y
|
||||
|
||||
# Ethernet is needed for VLAN
|
||||
CONFIG_NET_L2_ETHERNET=y
|
||||
|
||||
CONFIG_NET_APP_CLIENT=y
|
||||
CONFIG_NET_CONFIG_NEED_IPV6=y
|
||||
CONFIG_NET_CONFIG_NEED_IPV4=y
|
||||
CONFIG_NET_CONFIG_SETTINGS=y
|
||||
CONFIG_NET_CONFIG_INIT_TIMEOUT=15
|
||||
|
||||
# First ethernet interface will use these settings
|
||||
CONFIG_NET_CONFIG_MY_IPV6_ADDR="2001:db8:100::1"
|
||||
CONFIG_NET_CONFIG_PEER_IPV6_ADDR="2001:db8:100::2"
|
||||
# TEST-NET-2 from RFC 5737
|
||||
CONFIG_NET_CONFIG_MY_IPV4_ADDR="198.51.100.1"
|
||||
CONFIG_NET_CONFIG_PEER_IPV4_ADDR="198.51.100.2"
|
||||
# VLAN tag for the first interface
|
||||
CONFIG_SAMPLE_VLAN_TAG=100
|
||||
|
||||
# Settings for the second network interface
|
||||
CONFIG_SAMPLE_IPV6_ADDR_2="2001:db8:200::1"
|
||||
CONFIG_SAMPLE_PEER_IPV6_ADDR_2="2001:db8:200::2"
|
||||
CONFIG_SAMPLE_VLAN_TAG_2=200
|
||||
# TEST-NET-3 from RFC 5737
|
||||
CONFIG_SAMPLE_IPV4_ADDR_2="203.0.113.1"
|
||||
CONFIG_SAMPLE_PEER_IPV4_ADDR_2="203.0.113.2"
|
||||
|
||||
# VLAN settings. Note that currently SLIP only supports one VLAN tag,
|
||||
# and that is enforced by Kconfig file.
|
||||
CONFIG_NET_VLAN=y
|
||||
CONFIG_NET_VLAN_COUNT=2
|
||||
|
||||
# How many traffic classes to enable for each network device.
|
||||
CONFIG_NET_TC_TX_COUNT=8
|
||||
CONFIG_NET_TC_RX_COUNT=8
|
||||
|
||||
# Enable priority support in net_context
|
||||
CONFIG_NET_CONTEXT_PRIORITY=y
|
||||
|
||||
# To avoid "Too many thread objects" error
|
||||
CONFIG_USERSPACE=n
|
|
@ -1,10 +0,0 @@
|
|||
common:
|
||||
harness: net
|
||||
tags: net vlan traffic_class
|
||||
sample:
|
||||
description: Test traffic class functionality
|
||||
name: Traffic class sample app
|
||||
tests:
|
||||
test:
|
||||
depends_on: netif
|
||||
min_ram: 170
|
|
@ -1,585 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2018 Intel Corporation.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <logging/log.h>
|
||||
LOG_MODULE_REGISTER(net_tc_sample, LOG_LEVEL_DBG);
|
||||
|
||||
#include <zephyr.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <net/net_core.h>
|
||||
#include <net/net_l2.h>
|
||||
#include <net/net_if.h>
|
||||
#include <net/ethernet.h>
|
||||
#include <net/net_context.h>
|
||||
#include <net/net_app.h>
|
||||
|
||||
#define MY_PORT 0
|
||||
#define PEER_PORT 4242
|
||||
|
||||
#define WAIT_TIME K_SECONDS(2)
|
||||
#define CONNECT_TIME K_SECONDS(10)
|
||||
|
||||
#if defined(CONFIG_NET_IPV6)
|
||||
static struct net_app_ctx udp6[NET_TC_COUNT];
|
||||
#endif
|
||||
#if defined(CONFIG_NET_IPV4)
|
||||
static struct net_app_ctx udp4[NET_TC_COUNT];
|
||||
#endif
|
||||
|
||||
static struct k_sem quit_lock;
|
||||
|
||||
/* Generated by http://www.lipsum.com/
|
||||
* 3 paragraphs, 176 words, 1230 bytes of Lorem Ipsum
|
||||
*/
|
||||
const char lorem_ipsum[] =
|
||||
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. "
|
||||
"Vestibulum id cursus felis, sit amet suscipit velit. Integer "
|
||||
"facilisis malesuada porta. Nunc at accumsan mauris. Etiam vehicula, "
|
||||
"arcu consequat feugiat venenatis, tellus velit gravida ligula, quis "
|
||||
"posuere sem leo eget urna. Curabitur condimentum leo nec orci "
|
||||
"mattis, nec faucibus dui rutrum. Ut mollis orci in iaculis "
|
||||
"consequat. Nulla volutpat nibh eu velit sagittis, a iaculis dui "
|
||||
"aliquam."
|
||||
"\n"
|
||||
"Quisque interdum consequat eros a eleifend. Fusce dapibus nisl "
|
||||
"sit amet velit posuere imperdiet. Quisque accumsan tempor massa "
|
||||
"sit amet tincidunt. Integer sollicitudin vehicula tristique. Nulla "
|
||||
"sagittis massa turpis, ac ultricies neque posuere eu. Nulla et "
|
||||
"imperdiet ex. Etiam venenatis sed lacus tincidunt hendrerit. In "
|
||||
"libero nisl, congue id tellus vitae, tincidunt tristique mauris. "
|
||||
"Nullam sed porta massa. Sed condimentum sem eu convallis euismod. "
|
||||
"Suspendisse lobortis purus faucibus, gravida turpis id, mattis "
|
||||
"velit. Maecenas eleifend sapien eu tincidunt lobortis. Sed elementum "
|
||||
"sapien id enim laoreet consequat."
|
||||
"\n"
|
||||
"Aenean et neque aliquam, lobortis lectus in, consequat leo. Sed "
|
||||
"quis egestas nulla. Quisque ac risus quis elit mollis finibus. "
|
||||
"Phasellus efficitur imperdiet metus."
|
||||
"\n";
|
||||
|
||||
static int ipsum_len = sizeof(lorem_ipsum) - 1;
|
||||
|
||||
struct stats {
|
||||
u32_t sent;
|
||||
u32_t received;
|
||||
u32_t dropped;
|
||||
u32_t wrong_order;
|
||||
u32_t invalid;
|
||||
|
||||
u32_t sent_time_sum;
|
||||
u32_t sent_time_count;
|
||||
s64_t sent_time; /* in milliseconds */
|
||||
};
|
||||
|
||||
struct configs;
|
||||
|
||||
struct data {
|
||||
/* Work controlling udp data sending */
|
||||
struct k_delayed_work recv;
|
||||
struct net_app_ctx *udp;
|
||||
struct configs *conf;
|
||||
sa_family_t family;
|
||||
|
||||
const char *proto;
|
||||
u32_t expecting_udp;
|
||||
u8_t priority;
|
||||
|
||||
struct stats stats;
|
||||
};
|
||||
|
||||
struct configs {
|
||||
struct data ipv4[NET_TC_COUNT];
|
||||
struct data ipv6[NET_TC_COUNT];
|
||||
};
|
||||
|
||||
static struct configs conf = {
|
||||
.ipv4 = {
|
||||
[0 ... (NET_TC_COUNT - 1)] = {
|
||||
.proto = "IPv4",
|
||||
.family = AF_INET,
|
||||
}
|
||||
},
|
||||
.ipv6 = {
|
||||
[0 ... (NET_TC_COUNT - 1)] = {
|
||||
.proto = "IPv6",
|
||||
.family = AF_INET6,
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#define TYPE_SEQ_NUM 42
|
||||
|
||||
struct header {
|
||||
u8_t type;
|
||||
u8_t len;
|
||||
union {
|
||||
u8_t value[0];
|
||||
struct {
|
||||
u32_t seq;
|
||||
s64_t sent;
|
||||
};
|
||||
};
|
||||
} __packed;
|
||||
|
||||
#if CONFIG_NET_VLAN_COUNT > 1
|
||||
#define CREATE_MULTIPLE_TAGS
|
||||
#endif
|
||||
|
||||
struct ud {
|
||||
struct net_if *first;
|
||||
struct net_if *second;
|
||||
};
|
||||
|
||||
#if defined(CREATE_MULTIPLE_TAGS)
|
||||
static void iface_cb(struct net_if *iface, void *user_data)
|
||||
{
|
||||
struct ud *ud = user_data;
|
||||
|
||||
if (net_if_l2(iface) != &NET_L2_GET_NAME(ETHERNET)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (iface == ud->first) {
|
||||
return;
|
||||
}
|
||||
|
||||
ud->second = iface;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int init_app(void)
|
||||
{
|
||||
struct net_if *iface;
|
||||
int ret;
|
||||
|
||||
#if defined(CREATE_MULTIPLE_TAGS)
|
||||
struct net_if_addr *ifaddr;
|
||||
struct in_addr addr4;
|
||||
struct in6_addr addr6;
|
||||
struct ud ud;
|
||||
#endif
|
||||
|
||||
iface = net_if_get_first_by_type(&NET_L2_GET_NAME(ETHERNET));
|
||||
if (!iface) {
|
||||
LOG_ERR("No ethernet interfaces found.");
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
#if defined(CONFIG_NET_VLAN)
|
||||
ret = net_eth_vlan_enable(iface, CONFIG_SAMPLE_VLAN_TAG);
|
||||
if (ret < 0) {
|
||||
LOG_ERR("Cannot enable VLAN for tag %d (%d)",
|
||||
CONFIG_SAMPLE_VLAN_TAG, ret);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(CREATE_MULTIPLE_TAGS)
|
||||
ud.first = iface;
|
||||
ud.second = NULL;
|
||||
|
||||
net_if_foreach(iface_cb, &ud);
|
||||
|
||||
/* This sample has two VLANs. For the second one we need to manually
|
||||
* create IP address for this test. But first the VLAN needs to be
|
||||
* added to the interface so that IPv6 DAD can work properly.
|
||||
*/
|
||||
ret = net_eth_vlan_enable(ud.second, CONFIG_SAMPLE_VLAN_TAG_2);
|
||||
if (ret < 0) {
|
||||
LOG_ERR("Cannot enable VLAN for tag %d (%d)",
|
||||
CONFIG_SAMPLE_VLAN_TAG_2, ret);
|
||||
}
|
||||
|
||||
#if defined(CONFIG_NET_IPV6)
|
||||
if (net_addr_pton(AF_INET6, CONFIG_SAMPLE_IPV6_ADDR_2, &addr6)) {
|
||||
LOG_ERR("Invalid address: %s", CONFIG_SAMPLE_IPV6_ADDR_2);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ifaddr = net_if_ipv6_addr_add(ud.second, &addr6, NET_ADDR_MANUAL, 0);
|
||||
if (!ifaddr) {
|
||||
LOG_ERR("Cannot add %s to interface %p",
|
||||
CONFIG_SAMPLE_IPV6_ADDR_2, ud.second);
|
||||
return -EINVAL;
|
||||
}
|
||||
#else
|
||||
ARG_UNUSED(addr6);
|
||||
#endif /* IPV6 */
|
||||
|
||||
#if defined(CONFIG_NET_IPV4)
|
||||
if (net_addr_pton(AF_INET, CONFIG_SAMPLE_IPV4_ADDR_2, &addr4)) {
|
||||
LOG_ERR("Invalid address: %s", CONFIG_SAMPLE_IPV4_ADDR_2);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ifaddr = net_if_ipv4_addr_add(ud.second, &addr4, NET_ADDR_MANUAL, 0);
|
||||
if (!ifaddr) {
|
||||
LOG_ERR("Cannot add %s to interface %p",
|
||||
CONFIG_SAMPLE_IPV4_ADDR_2, ud.second);
|
||||
return -EINVAL;
|
||||
}
|
||||
#else
|
||||
ARG_UNUSED(addr4);
|
||||
#endif /* IPV4 */
|
||||
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static u32_t calc_time(u32_t count, u32_t sum)
|
||||
{
|
||||
if (!count) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (sum * 1000) / count;
|
||||
}
|
||||
|
||||
#define PRINT_STATISTICS_INTERVAL (30 * MSEC_PER_SEC)
|
||||
|
||||
static void stats(struct data *data)
|
||||
{
|
||||
static bool first = true;
|
||||
static s64_t next_print;
|
||||
s64_t curr = k_uptime_get();
|
||||
|
||||
if (!next_print || (next_print < curr &&
|
||||
(!((curr - next_print) > PRINT_STATISTICS_INTERVAL)))) {
|
||||
s64_t new_print;
|
||||
int i;
|
||||
|
||||
if (first) {
|
||||
first = false;
|
||||
goto skip_print;
|
||||
}
|
||||
|
||||
LOG_INF("Traffic class statistics:");
|
||||
LOG_INF(" Prio\tSent\tRecv\tDrop\tMiss\tTime (us)");
|
||||
|
||||
#if defined(CONFIG_NET_IPV6)
|
||||
for (i = 0; i < NET_TC_COUNT; i++) {
|
||||
u32_t round_trip_time =
|
||||
calc_time(
|
||||
data->conf->ipv6[i].stats.sent_time_count,
|
||||
data->conf->ipv6[i].stats.sent_time_sum);
|
||||
|
||||
LOG_INF("v6 %d\t%u\t%u\t%u\t%u\t%u",
|
||||
data->conf->ipv6[i].priority,
|
||||
data->conf->ipv6[i].stats.sent,
|
||||
data->conf->ipv6[i].stats.received,
|
||||
data->conf->ipv6[i].stats.dropped,
|
||||
data->conf->ipv6[i].stats.wrong_order,
|
||||
round_trip_time);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_NET_IPV4)
|
||||
for (i = 0; i < NET_TC_COUNT; i++) {
|
||||
u32_t round_trip_time =
|
||||
calc_time(
|
||||
data->conf->ipv4[i].stats.sent_time_count,
|
||||
data->conf->ipv4[i].stats.sent_time_sum);
|
||||
|
||||
LOG_INF("v4 %d\t%u\t%u\t%u\t%u\t%u",
|
||||
data->conf->ipv4[i].priority,
|
||||
data->conf->ipv4[i].stats.sent,
|
||||
data->conf->ipv4[i].stats.received,
|
||||
data->conf->ipv4[i].stats.dropped,
|
||||
data->conf->ipv4[i].stats.wrong_order,
|
||||
round_trip_time);
|
||||
}
|
||||
#endif
|
||||
LOG_INF("---");
|
||||
|
||||
skip_print:
|
||||
new_print = curr + PRINT_STATISTICS_INTERVAL;
|
||||
if (new_print > curr) {
|
||||
next_print = new_print;
|
||||
} else {
|
||||
/* Overflow */
|
||||
next_print = PRINT_STATISTICS_INTERVAL -
|
||||
(LLONG_MAX - curr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static struct net_pkt *prepare_send_pkt(struct net_app_ctx *ctx,
|
||||
const char *name,
|
||||
int *expecting_len,
|
||||
struct data *data)
|
||||
{
|
||||
struct net_pkt *send_pkt;
|
||||
struct header *hdr;
|
||||
u32_t seq;
|
||||
s32_t timeout = K_SECONDS(1);
|
||||
|
||||
send_pkt = net_app_get_net_pkt(ctx, data->family, timeout);
|
||||
if (!send_pkt) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
seq = htonl(data->stats.sent + 1);
|
||||
|
||||
*expecting_len = net_pkt_append(send_pkt, *expecting_len,
|
||||
lorem_ipsum, timeout);
|
||||
|
||||
hdr = (struct header *)send_pkt->frags->data;
|
||||
hdr->type = TYPE_SEQ_NUM;
|
||||
hdr->len = sizeof(seq);
|
||||
|
||||
UNALIGNED_PUT(seq, &hdr->seq);
|
||||
UNALIGNED_PUT(k_uptime_get(), &hdr->sent);
|
||||
|
||||
return send_pkt;
|
||||
}
|
||||
|
||||
static bool send_udp_data(struct net_app_ctx *ctx, struct data *data)
|
||||
{
|
||||
s32_t timeout = K_SECONDS(1);
|
||||
struct net_pkt *pkt;
|
||||
size_t len;
|
||||
int ret;
|
||||
|
||||
data->expecting_udp = sys_rand32_get() % ipsum_len;
|
||||
|
||||
pkt = prepare_send_pkt(ctx, data->proto, &data->expecting_udp, data);
|
||||
if (!pkt) {
|
||||
return false;
|
||||
}
|
||||
|
||||
len = net_pkt_get_len(pkt);
|
||||
|
||||
NET_ASSERT_INFO(data->expecting_udp == len,
|
||||
"Data to send %d bytes, real len %zu",
|
||||
data->expecting_udp, len);
|
||||
|
||||
data->stats.sent_time = k_uptime_get();
|
||||
|
||||
ret = net_app_send_pkt(ctx, pkt, NULL, 0, timeout,
|
||||
UINT_TO_POINTER(len));
|
||||
if (ret < 0) {
|
||||
net_pkt_unref(pkt);
|
||||
}
|
||||
|
||||
data->stats.sent++;
|
||||
|
||||
k_delayed_work_submit(&data->recv, WAIT_TIME);
|
||||
|
||||
stats(data);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void send_more_data(struct net_app_ctx *ctx, struct data *data)
|
||||
{
|
||||
bool ret;
|
||||
|
||||
do {
|
||||
ret = send_udp_data(ctx, data);
|
||||
if (!ret) {
|
||||
/* Avoid too much flooding */
|
||||
k_sleep(K_MSEC(10));
|
||||
}
|
||||
} while (!ret);
|
||||
|
||||
/* We should not call k_yield() here as that will not let lower
|
||||
* priority thread to run.
|
||||
*/
|
||||
k_sleep(K_MSEC(1));
|
||||
}
|
||||
|
||||
static void udp_received(struct net_app_ctx *ctx,
|
||||
struct net_pkt *pkt,
|
||||
int status,
|
||||
void *user_data)
|
||||
{
|
||||
struct data *data = ctx->user_data;
|
||||
struct header *hdr = (struct header *)net_pkt_appdata(pkt);
|
||||
|
||||
ARG_UNUSED(user_data);
|
||||
ARG_UNUSED(status);
|
||||
|
||||
if (data->expecting_udp != net_pkt_appdatalen(pkt)) {
|
||||
LOG_DBG("Sent %d bytes, received %u bytes",
|
||||
data->expecting_udp, net_pkt_appdatalen(pkt));
|
||||
}
|
||||
|
||||
net_pkt_unref(pkt);
|
||||
|
||||
k_delayed_work_cancel(&data->recv);
|
||||
|
||||
if (hdr->type != TYPE_SEQ_NUM) {
|
||||
data->stats.invalid++;
|
||||
} else {
|
||||
if (ntohl(UNALIGNED_GET(&hdr->seq)) != data->stats.sent) {
|
||||
data->stats.wrong_order++;
|
||||
} else {
|
||||
data->stats.received++;
|
||||
|
||||
data->stats.sent_time_sum += k_uptime_get() -
|
||||
data->stats.sent_time;
|
||||
data->stats.sent_time_count++;
|
||||
}
|
||||
}
|
||||
|
||||
send_more_data(ctx, data);
|
||||
}
|
||||
|
||||
static int connect_udp(sa_family_t family, struct net_app_ctx *ctx,
|
||||
const char *peer, void *user_data, u8_t priority)
|
||||
{
|
||||
struct data *data = user_data;
|
||||
size_t optlen = sizeof(priority);
|
||||
int ret;
|
||||
|
||||
data->udp = ctx;
|
||||
|
||||
ret = net_app_init_udp_client(ctx, NULL, NULL, peer, PEER_PORT,
|
||||
WAIT_TIME, user_data);
|
||||
if (ret < 0) {
|
||||
LOG_ERR("Cannot init %s UDP client (%d)", data->proto, ret);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
#if defined(CONFIG_NET_CONTEXT_NET_PKT_POOL)
|
||||
net_app_set_net_pkt_pool(ctx, tx_udp_slab, data_udp_pool);
|
||||
#endif
|
||||
|
||||
ret = net_app_set_cb(ctx, NULL, udp_received, NULL, NULL);
|
||||
if (ret < 0) {
|
||||
LOG_ERR("Cannot set callbacks (%d)", ret);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
ret = net_app_connect(ctx, CONNECT_TIME);
|
||||
if (ret < 0) {
|
||||
LOG_ERR("Cannot connect UDP (%d)", ret);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
#if defined(CONFIG_NET_IPV4)
|
||||
if (family == AF_INET) {
|
||||
net_context_set_option(ctx->ipv4.ctx, NET_OPT_PRIORITY,
|
||||
&priority, sizeof(u8_t));
|
||||
|
||||
net_context_get_option(ctx->ipv4.ctx, NET_OPT_PRIORITY,
|
||||
&priority, &optlen);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_NET_IPV6)
|
||||
if (family == AF_INET6) {
|
||||
net_context_set_option(ctx->ipv6.ctx, NET_OPT_PRIORITY,
|
||||
&priority, sizeof(u8_t));
|
||||
|
||||
net_context_get_option(ctx->ipv6.ctx, NET_OPT_PRIORITY,
|
||||
&priority, &optlen);
|
||||
}
|
||||
#endif
|
||||
|
||||
data->priority = priority;
|
||||
fail:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void wait_reply(struct k_work *work)
|
||||
{
|
||||
/* This means that we did not receive response in time. */
|
||||
struct data *data = CONTAINER_OF(work, struct data, recv);
|
||||
|
||||
data->stats.dropped++;
|
||||
|
||||
/* Send a new packet at this point */
|
||||
send_more_data(data->udp, data);
|
||||
}
|
||||
|
||||
static void setup_clients(void)
|
||||
{
|
||||
int ret, i;
|
||||
|
||||
#if defined(CONFIG_NET_IPV6)
|
||||
for (i = 0; i < NET_TC_COUNT; i++) {
|
||||
k_delayed_work_init(&conf.ipv6[i].recv, wait_reply);
|
||||
|
||||
conf.ipv6[i].conf = &conf;
|
||||
|
||||
if (i % 2) {
|
||||
LOG_DBG("TC %d connecting to %s", i,
|
||||
CONFIG_NET_CONFIG_PEER_IPV6_ADDR);
|
||||
ret = connect_udp(AF_INET6, &udp6[i],
|
||||
CONFIG_NET_CONFIG_PEER_IPV6_ADDR,
|
||||
&conf.ipv6[i], i);
|
||||
} else {
|
||||
LOG_DBG("TC %d connecting to %s", i,
|
||||
CONFIG_SAMPLE_PEER_IPV6_ADDR_2);
|
||||
ret = connect_udp(AF_INET6, &udp6[i],
|
||||
CONFIG_SAMPLE_PEER_IPV6_ADDR_2,
|
||||
&conf.ipv6[i], i);
|
||||
}
|
||||
|
||||
if (ret < 0) {
|
||||
LOG_ERR("Cannot init IPv6 UDP client %d (%d)",
|
||||
i + 1, ret);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_NET_IPV4)
|
||||
for (i = 0; i < NET_TC_COUNT; i++) {
|
||||
k_delayed_work_init(&conf.ipv4[i].recv, wait_reply);
|
||||
|
||||
conf.ipv4[i].conf = &conf;
|
||||
|
||||
if (i % 2) {
|
||||
LOG_DBG("TC %d connecting to %s", i,
|
||||
CONFIG_NET_CONFIG_PEER_IPV4_ADDR);
|
||||
ret = connect_udp(AF_INET, &udp4[i],
|
||||
CONFIG_NET_CONFIG_PEER_IPV4_ADDR,
|
||||
&conf.ipv4[i], i);
|
||||
} else {
|
||||
LOG_DBG("TC %d connecting to %s", i,
|
||||
CONFIG_SAMPLE_PEER_IPV4_ADDR_2);
|
||||
ret = connect_udp(AF_INET, &udp4[i],
|
||||
CONFIG_SAMPLE_PEER_IPV4_ADDR_2,
|
||||
&conf.ipv4[i], i);
|
||||
}
|
||||
|
||||
if (ret < 0) {
|
||||
LOG_ERR("Cannot init IPv4 UDP client %d (%d)",
|
||||
i + 1, ret);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* We can start to send data when UDP is "connected" */
|
||||
for (i = 0; i < NET_TC_COUNT; i++) {
|
||||
#if defined(CONFIG_NET_IPV6)
|
||||
send_more_data(&udp6[i], &conf.ipv6[i]);
|
||||
#endif
|
||||
#if defined(CONFIG_NET_IPV4)
|
||||
send_more_data(&udp4[i], &conf.ipv4[i]);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void main(void)
|
||||
{
|
||||
k_sem_init(&quit_lock, 0, UINT_MAX);
|
||||
|
||||
init_app();
|
||||
|
||||
/* This extra sleep is needed so that the network stabilizes a bit
|
||||
* before we start to send data. This is important as we have multiple
|
||||
* network interfaces and all of them should be configured properly
|
||||
* before we continue.
|
||||
*/
|
||||
k_sleep(K_SECONDS(5));
|
||||
|
||||
setup_clients();
|
||||
|
||||
k_sem_take(&quit_lock, K_FOREVER);
|
||||
}
|
|
@ -25,7 +25,6 @@ CONFIG_NET_SHELL=y
|
|||
# Ethernet is needed for VLAN
|
||||
CONFIG_NET_L2_ETHERNET=y
|
||||
|
||||
CONFIG_NET_APP_SERVER=y
|
||||
CONFIG_NET_CONFIG_NEED_IPV6=y
|
||||
CONFIG_NET_CONFIG_NEED_IPV4=y
|
||||
CONFIG_NET_CONFIG_SETTINGS=y
|
||||
|
|
Loading…
Reference in a new issue