• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Chipsea Technologies (Shenzhen) Corp., 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 #ifndef _WIFI_HOST_PING_H
16 #define _WIFI_HOST_PING_H
17 
18 #include "sockets.h"
19 #include "wifi_host_tg.h"
20 
21 /// Maximum number of ping streams
22 #define FHOST_PING_MAX_STREAMS 3
23 /// Profile ID for ping command, @ref net_sleep_time
24 #define FHOST_PROF_PING 7
25 
26 /// Ping profile
27 struct fhost_ping_profile
28 {
29     /// IP address of destination
30     uint32_t dst_ip;
31     /// Ping rate (pkts /s)
32     uint32_t rate;
33     /// Packet size
34     uint32_t pksize;
35     /// Ping duration
36     uint32_t duration;
37     /// TOS value to be put in the IP header
38     uint16_t tos;
39 };
40 
41 /// Ping statistics
42 struct fhost_ping_stats
43 {
44     /// Number of TX frames sent
45     uint32_t tx_frames;
46     /// Number of RX frames received
47     uint32_t rx_frames;
48     /// Number of TX buffer bytes
49     uint32_t tx_bytes;
50     /// Number of RX buffer bytes
51     uint32_t rx_bytes;
52     /// Round trip time delay of ping command
53     uint32_t rt_time;
54 };
55 
56 /// Ping configuration structure
57 struct fhost_ping_stream
58 {
59     /// Ping thread ID
60     uint32_t id;
61     /// State of ping thread (true for active, false for inactive)
62     bool active;
63     /// Param pointer for @ref net_tg_al.c
64     void *arg;
65     /// Ping sequence number
66     u16_t ping_seq_num;
67     /// Ping semaphore used to synchronize the ping thread and the FHOST IPC one
68     rtos_semaphore ping_semaphore;
69     /// Handle of ping send task (not used yet)
70     rtos_task_handle ping_handle;
71     /// Ping timestamp
72     struct fhost_tg_time ping_timestamp;
73     /// Ping profile
74     struct fhost_ping_profile prof;
75     /// Ping statistics
76     struct fhost_ping_stats stats;
77     /// Background task
78     bool background;
79 };
80 
81 /// Arguments for @ref fhost_ping_start
82 struct fhost_ping_task_args
83 {
84     ///Destination IP address
85     u32_t rip;
86     ///Ping rate (pkts / s)
87     u32_t rate;
88     ///Packet size
89     u32_t pksize;
90     ///Ping duration
91     u32_t duration;
92     ///Type of service
93     u16_t tos;
94     ///Boolean for running ping in background
95     bool background;
96 };
97 
98 /*
99  * GLOBAL VARIABLES
100  ****************************************************************************************
101  */
102 /// Table of ping streams
103 extern struct fhost_ping_stream p_streams[FHOST_PING_MAX_STREAMS];
104 
105 /*
106  * FUNCTIONS
107  ****************************************************************************************
108  */
109 /**
110  ****************************************************************************************
111  * @brief Search ping stream by stream id
112  * It will return the ping stream associated to the provided ping stream id.
113  *
114  * @param[in] ping stream id
115  *
116  * @return Pointer to ping stream if found, NULL otherwise
117  ****************************************************************************************
118  **/
119 struct fhost_ping_stream *fhost_ping_find_stream_profile(u32_t stream_id);
120 
121 /**
122  ****************************************************************************************
123  * @brief Start ping command with certain configuration options
124  * This function creates the RTOS task dedicated to the ping send processing and return
125  * the stream id of ping stream launched.
126  *
127  * @param[in] args    Pointer to arguments for fhost_ping_start (@ref struct fhost_ping_task_args)
128  *
129  * @return RTOS task handle of ping task on success, NULL otherwise
130  ****************************************************************************************
131  */
132 rtos_task_handle fhost_ping_start(void *args);
133 
134 /**
135  ****************************************************************************************
136  * @brief Stop ping process launched
137  * This function stops the ping process according to ping stream
138  *
139  * @param[in] ping_stream Pointer to the ping stream to stop
140  ****************************************************************************************
141  */
142 void fhost_ping_stop(struct fhost_ping_stream *ping_stream);
143 
144 
145 /**
146  ****************************************************************************************
147  * @brief Ping sigkill handler. Closes connection and ping stream.
148  *
149  * @param[in] ping_handle      Ping task handle
150  *
151  * @return FHOST_IPC_SUCCESS if successful, FHOST_IPC_ERROR otherwise
152  ****************************************************************************************
153  **/
154 int fhost_ping_sigkill_handler(rtos_task_handle ping_handle);
155 
156 
157 #if NX_CSI
158 void csi_start(void);
159 void csi_stop(void);
160 #endif /* NX_CSI */
161 
162 #endif // _WIFI_HOST_PING_H
163