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 #include "net_sample_common.h"
9 
10 #define MY_PORT 4242
11 #if defined(CONFIG_NET_SOCKETS_SOCKOPT_TLS) || defined(CONFIG_NET_TCP) || \
12 	defined(CONFIG_COVERAGE_GCOV)
13 #define STACK_SIZE 4096
14 #else
15 #define STACK_SIZE 2048
16 #endif
17 
18 #if defined(CONFIG_NET_TC_THREAD_COOPERATIVE)
19 #define THREAD_PRIORITY K_PRIO_COOP(CONFIG_NUM_COOP_PRIORITIES - 1)
20 #else
21 #define THREAD_PRIORITY K_PRIO_PREEMPT(8)
22 #endif
23 
24 #define RECV_BUFFER_SIZE 1280
25 #define STATS_TIMER 60 /* How often to print statistics (in seconds) */
26 
27 #if defined(CONFIG_USERSPACE)
28 #include <zephyr/app_memory/app_memdomain.h>
29 extern struct k_mem_partition app_partition;
30 extern struct k_mem_domain app_domain;
31 #define APP_BMEM K_APP_BMEM(app_partition)
32 #define APP_DMEM K_APP_DMEM(app_partition)
33 #else
34 #define APP_BMEM
35 #define APP_DMEM
36 #endif
37 
38 struct data {
39 	const char *proto;
40 
41 	struct {
42 		int sock;
43 		char recv_buffer[RECV_BUFFER_SIZE];
44 		uint32_t counter;
45 		atomic_t bytes_received;
46 		struct k_work_delayable stats_print;
47 	} udp;
48 
49 	struct {
50 		int sock;
51 		atomic_t bytes_received;
52 		struct k_work_delayable stats_print;
53 
54 		struct {
55 			int sock;
56 			char recv_buffer[RECV_BUFFER_SIZE];
57 			uint32_t counter;
58 		} accepted[CONFIG_NET_SAMPLE_NUM_HANDLERS];
59 	} tcp;
60 };
61 
62 struct configs {
63 	struct data ipv4;
64 	struct data ipv6;
65 };
66 
67 extern struct configs conf;
68 
69 void start_udp(void);
70 void stop_udp(void);
71 
72 void start_tcp(void);
73 void stop_tcp(void);
74 
75 void quit(void);
76 
77 #if defined(CONFIG_NET_SAMPLE_WEBSOCKET_CONSOLE)
78 int init_ws(void);
79 #else
init_ws(void)80 static inline int init_ws(void)
81 {
82 	return 0;
83 }
84 #endif /* CONFIG_NET_SAMPLE_WEBSOCKET_CONSOLE */
85 
86 #if defined(CONFIG_USB_DEVICE_STACK) || defined(CONFIG_USB_DEVICE_STACK_NEXT)
87 int init_usb(void);
88 #else
init_usb(void)89 static inline int init_usb(void)
90 {
91 	return 0;
92 }
93 #endif /* CONFIG_USB_DEVICE_STACK */
94