1 /* 2 * Copyright (c) 2017 Intel Corporation. 3 * Copyright (c) 2018 Nordic Semiconductor ASA. 4 * 5 * SPDX-License-Identifier: Apache-2.0 6 */ 7 8 #include <zephyr/kernel.h> 9 10 /* Value of 0 will cause the IP stack to select next free port */ 11 #define MY_PORT 0 12 13 #define PEER_PORT 4242 14 15 #if defined(CONFIG_USERSPACE) 16 #include <zephyr/app_memory/app_memdomain.h> 17 extern struct k_mem_partition app_partition; 18 extern struct k_mem_domain app_domain; 19 #define APP_BMEM K_APP_BMEM(app_partition) 20 #define APP_DMEM K_APP_DMEM(app_partition) 21 #else 22 #define APP_BMEM 23 #define APP_DMEM 24 #endif 25 26 #if defined(CONFIG_NET_TC_THREAD_PREEMPTIVE) 27 #define THREAD_PRIORITY K_PRIO_PREEMPT(8) 28 #else 29 #define THREAD_PRIORITY K_PRIO_COOP(CONFIG_NUM_COOP_PRIORITIES - 1) 30 #endif 31 32 #define UDP_STACK_SIZE 2048 33 34 struct udp_control { 35 struct k_poll_signal tx_signal; 36 struct k_timer tx_timer; 37 struct k_timer rx_timer; 38 }; 39 40 struct data { 41 const char *proto; 42 43 struct { 44 int sock; 45 uint32_t expecting; 46 uint32_t counter; 47 uint32_t mtu; 48 struct udp_control *ctrl; 49 } udp; 50 51 struct { 52 int sock; 53 uint32_t expecting; 54 uint32_t received; 55 uint32_t counter; 56 } tcp; 57 }; 58 59 struct configs { 60 struct data ipv4; 61 struct data ipv6; 62 }; 63 64 #if !defined(CONFIG_NET_CONFIG_PEER_IPV4_ADDR) 65 #define CONFIG_NET_CONFIG_PEER_IPV4_ADDR "" 66 #endif 67 68 #if !defined(CONFIG_NET_CONFIG_PEER_IPV6_ADDR) 69 #define CONFIG_NET_CONFIG_PEER_IPV6_ADDR "" 70 #endif 71 72 extern const char lorem_ipsum[]; 73 extern const int ipsum_len; 74 extern struct configs conf; 75 76 #if defined(CONFIG_NET_UDP) 77 /* init_udp initializes kernel objects, hence it has to be called from 78 * supervisor thread. 79 */ 80 void init_udp(void); 81 int start_udp(void); 82 int process_udp(void); 83 void stop_udp(void); 84 #else init_udp(void)85static inline void init_udp(void) { } start_udp(void)86static inline int start_udp(void) { return 0; } process_udp(void)87static inline int process_udp(void) { return 0; } stop_udp(void)88static inline void stop_udp(void) { } 89 #endif /* defined(CONFIG_NET_UDP) */ 90 91 int start_tcp(void); 92 int process_tcp(void); 93 void stop_tcp(void); 94 95 #if defined(CONFIG_NET_VLAN) 96 int init_vlan(void); 97 #else init_vlan(void)98static inline int init_vlan(void) 99 { 100 return 0; 101 } 102 #endif 103