1 /*
2  * Copyright (c) 2017-2019 Intel Corporation.
3  * Copyright (c) 2018 Nordic Semiconductor ASA.
4  *
5  * SPDX-License-Identifier: Apache-2.0
6  */
7 
8 
9 #define MY_PORT 4242
10 #if defined(CONFIG_NET_SOCKETS_SOCKOPT_TLS) || defined(CONFIG_NET_TCP) || \
11 	defined(CONFIG_COVERAGE_GCOV)
12 #define STACK_SIZE 4096
13 #else
14 #define STACK_SIZE 2048
15 #endif
16 
17 #if defined(CONFIG_NET_TC_THREAD_COOPERATIVE)
18 #define THREAD_PRIORITY K_PRIO_COOP(CONFIG_NUM_COOP_PRIORITIES - 1)
19 #else
20 #define THREAD_PRIORITY K_PRIO_PREEMPT(8)
21 #endif
22 
23 #define RECV_BUFFER_SIZE 1280
24 #define STATS_TIMER 60 /* How often to print statistics (in seconds) */
25 
26 #if defined(CONFIG_USERSPACE)
27 #include <zephyr/app_memory/app_memdomain.h>
28 extern struct k_mem_partition app_partition;
29 extern struct k_mem_domain app_domain;
30 #define APP_BMEM K_APP_BMEM(app_partition)
31 #define APP_DMEM K_APP_DMEM(app_partition)
32 #else
33 #define APP_BMEM
34 #define APP_DMEM
35 #endif
36 
37 struct data {
38 	const char *proto;
39 
40 	struct {
41 		int sock;
42 		char recv_buffer[RECV_BUFFER_SIZE];
43 		uint32_t counter;
44 		atomic_t bytes_received;
45 		struct k_work_delayable stats_print;
46 	} udp;
47 
48 	struct {
49 		int sock;
50 		atomic_t bytes_received;
51 		struct k_work_delayable stats_print;
52 
53 		struct {
54 			int sock;
55 			char recv_buffer[RECV_BUFFER_SIZE];
56 			uint32_t counter;
57 		} accepted[CONFIG_NET_SAMPLE_NUM_HANDLERS];
58 	} tcp;
59 };
60 
61 struct configs {
62 	struct data ipv4;
63 	struct data ipv6;
64 };
65 
66 extern struct configs conf;
67 
68 void start_udp(void);
69 void stop_udp(void);
70 
71 void start_tcp(void);
72 void stop_tcp(void);
73 
74 void quit(void);
75 
76 #if defined(CONFIG_NET_VLAN)
77 int init_vlan(void);
78 #else
init_vlan(void)79 static inline int init_vlan(void)
80 {
81 	return 0;
82 }
83 #endif /* CONFIG_NET_VLAN */
84 
85 #if defined(CONFIG_NET_SAMPLE_WEBSOCKET_CONSOLE)
86 int init_ws(void);
87 #else
init_ws(void)88 static inline int init_ws(void)
89 {
90 	return 0;
91 }
92 #endif /* CONFIG_NET_SAMPLE_WEBSOCKET_CONSOLE */
93 
94 #if defined(CONFIG_NET_L2_IPIP)
95 int init_tunnel(void);
96 bool is_tunnel(struct net_if *iface);
97 #else
init_tunnel(void)98 static inline int init_tunnel(void)
99 {
100 	return 0;
101 }
102 
is_tunnel(struct net_if * iface)103 static inline bool is_tunnel(struct net_if *iface)
104 {
105 	ARG_UNUSED(iface);
106 	return false;
107 }
108 #endif /* CONFIG_NET_L2_IPIP */
109 
110 #if defined(CONFIG_USB_DEVICE_STACK) || defined(CONFIG_USB_DEVICE_STACK_NEXT)
111 int init_usb(void);
112 #else
init_usb(void)113 static inline int init_usb(void)
114 {
115 	return 0;
116 }
117 #endif /* CONFIG_USB_DEVICE_STACK */
118