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