1 /* 2 * Copyright (c) 2022 ASR Microelectronics (Shanghai) Co., Ltd. All rights reserved. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef __LWIP_APP_IPERF_H__ 17 #define __LWIP_APP_IPERF_H__ 18 19 #include "lwipopts.h" 20 #ifdef LWIP_APP_IPERF 21 #include "lwip/ip_addr.h" 22 #include "lwip/inet.h" 23 #include "lega_rtos.h" 24 #define TCP_MAX_TXPERF_CONNECTION 1 25 #define IPERF_OUTPUT_INTERVIEW 1 // 1s 26 #define TCP_SEND_BUFSIZE (TCP_MSS) 27 #define UDP_SEND_BUFSIZE (TCP_MSS+12) 28 #define SEND_BUFSIZE UDP_SEND_BUFSIZE // (TCP_SEND_BUFSIZE>UDP_SEND_BUFSIZE?TCP_SEND_BUFSIZE:UDP_SEND_BUFSIZE) 29 typedef unsigned long long u64_t; 30 31 extern char iperf_send_buf[SEND_BUFSIZE]; 32 extern lega_timer_t iperf_output_timer; 33 typedef enum { 34 IPERF_MODE_UNINIT = 0, 35 IPERF_MODE_SERVER, 36 IPERF_MODE_CLIENT 37 } IPERF_MODE; 38 39 typedef enum { 40 IPERF_PROTOCOL_TCP = 0, 41 IPERF_PROTOCOL_UDP 42 } IPERF_PROTOCOL; 43 44 typedef enum { 45 IPERF_TCP_SERVER_UNINIT = 0, 46 IPERF_TCP_SERVER_INIT, 47 IPERF_TCP_SERVER_LISTENING, 48 IPERF_TCP_SERVER_RXRUNNING 49 } IPERF_TCP_SERVER_STATUS; 50 typedef enum { 51 IPERF_UDP_SERVER_UNINIT = 0, 52 IPERF_UDP_SERVER_INIT, 53 IPERF_UDP_SERVER_RXRUNNING 54 } IPERF_UDP_SERVER_STATUS; 55 typedef enum { 56 IPERF_TCP_CLINET_UNINIT = 0, 57 IPERF_TCP_CLIENT_INIT, 58 IPERF_TCP_CLIENT_CONNECTING, 59 IPERF_TCP_CLIENT_CONNECTED, 60 IPERF_TCP_CLIENT_STARTING, 61 IPERF_TCP_CLIENT_TXRUNNING, 62 } IPERF_TCP_CLINET_STATUS; 63 typedef enum { 64 IPERF_UDP_CLIENT_UNINIT = 0, 65 IPERF_UDP_CLIENT_INIT, 66 IPERF_UDP_CLIENT_START, 67 IPERF_UDP_CLIENT_TXRUNNING 68 } IPERF_UDP_CLIENT_STATUS; 69 typedef void (*discon_handle_t)(); 70 extern volatile IPERF_TCP_SERVER_STATUS iperf_tcp_server_status; 71 extern volatile IPERF_UDP_SERVER_STATUS iperf_udp_server_status; 72 extern volatile IPERF_TCP_CLINET_STATUS iperf_tcp_client_status; 73 extern volatile IPERF_UDP_CLIENT_STATUS iperf_udp_client_status; 74 // extern volatile int iperf_tcp_server_term; 75 // extern volatile int iperf_udp_server_term; 76 // extern volatile int iperf_tcp_client_running; 77 // extern volatile int iperf_udp_client_term; 78 79 struct lwip_iperf_outputInfo { 80 int seconds; // start time 81 u64_t lastByte; 82 u64_t currentByte; 83 u64_t lastPacketNum; 84 u64_t currentPacketNum; 85 }; 86 struct lwip_iperf_config_t { 87 int termFlag; 88 IPERF_MODE mode; 89 IPERF_PROTOCOL protocol; 90 int port; 91 ip4_addr_t ipaddr; 92 u8_t tx_delay_ms; 93 }; 94 extern struct lwip_iperf_config_t iperf_config; 95 extern struct lwip_iperf_outputInfo txperf_outinfo; 96 extern struct lwip_iperf_outputInfo rxperf_outinfo; 97 extern struct lwip_iperf_outputInfo utxperf_outinfo; 98 extern struct lwip_iperf_outputInfo urxperf_outinfo; 99 100 void lega_wifi_iperf(int argc, char **argv); 101 void lega_wifi_iperf_init(void); 102 103 void rxperf_init(); 104 void txperf_init(); 105 void urxperf_init(); 106 void utxperf_init(); 107 void txperf_output(); 108 109 int start_txperf_application(ip4_addr_t *ipaddr, int port); 110 int transfer_txperf_data(); 111 int start_utxperf_application(ip4_addr_t *ipaddr, int port); 112 int transfer_utxperf_data(); 113 int start_rxperf_application(int port); 114 int start_urxperf_application(int port); 115 void clear_rxperf(); 116 void disconnect_txperf(); 117 void clear_urxperf(); 118 void disconnect_utxperf(); 119 void do_iperf_terminate_timer(char *mode, struct lwip_iperf_outputInfo *outputInfo); 120 #endif 121 #endif 122