1 /*
2  * Copyright (c) 2024 Nordic Semiconductor ASA
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 /** @file
7  *
8  * @addtogroup nrf70_off_raw_tx_api nRF70 Offloaded raw TX API
9  * @{
10  *
11  * @brief File containing API's for the Offloaded raw TX feature.
12  */
13 
14 #ifndef INCLUDE_ZEPHYR_DRIVERS_OFF_RAW_TX_API_H_
15 #define INCLUDE_ZEPHYR_DRIVERS_OFF_RAW_TX_API_H_
16 
17 #include <stdbool.h>
18 #include <stdint.h>
19 
20 /*  Minimum frame size for raw packet transmission */
21 #define NRF_WIFI_OFF_RAW_TX_FRAME_SIZE_MIN 26
22 /*  Maximum frame size for raw packet transmission */
23 #define NRF_WIFI_OFF_RAW_TX_FRAME_SIZE_MAX 600
24 /* Maximum length of country code*/
25 #define NRF_WIFI_COUNTRY_CODE_LEN 2
26 /**
27  * @brief- Transmission rates
28  * Rate to be used for transmitting a packet.
29  */
30 enum nrf_wifi_off_raw_tx_rate {
31 	/** 1 Mbps */
32 	RATE_1M,
33 	/** 2 Mbps */
34 	RATE_2M,
35 	/** 5.5 Mbps */
36 	RATE_5_5M,
37 	/** 11 Mbps */
38 	RATE_11M,
39 	/** 6 Mbps */
40 	RATE_6M,
41 	/** 9 Mbps */
42 	RATE_9M,
43 	/** 12 Mbps */
44 	RATE_12M,
45 	/** 18 Mbps */
46 	RATE_18M,
47 	/** 24 Mbps */
48 	RATE_24M,
49 	/** 36 Mbps */
50 	RATE_36M,
51 	/** 48 Mbps */
52 	RATE_48M,
53 	/** 54 Mbps */
54 	RATE_54M,
55 	/** MCS 0 */
56 	RATE_MCS0,
57 	/** MCS 1 */
58 	RATE_MCS1,
59 	/** MCS 2 */
60 	RATE_MCS2,
61 	/** MCS 3 */
62 	RATE_MCS3,
63 	/** MCS 4 */
64 	RATE_MCS4,
65 	/** MCS 5 */
66 	RATE_MCS5,
67 	/** MCS 6 */
68 	RATE_MCS6,
69 	/** MCS 7 */
70 	RATE_MCS7,
71 	/** Invalid rate */
72 	RATE_MAX
73 };
74 
75 
76 /**
77  * @brief- HE guard interval value
78  * Value of the guard interval to be used between symbols when transmitting using HE.
79  */
80 enum nrf_wifi_off_raw_tx_he_gi {
81 	/** 800 ns */
82 	HE_GI_800NS,
83 	/** 1600 ns */
84 	HE_GI_1600NS,
85 	/** 3200 ns */
86 	HE_GI_3200NS,
87 	/** Invalid value */
88 	HE_GI_MAX
89 };
90 
91 
92 /**
93  * @brief- HE long training field duration
94  * Value of the long training field duration to be used when transmitting using HE.
95  */
96 enum nrf_wifi_off_raw_tx_he_ltf {
97 	/** 3.2us */
98 	HE_LTF_3200NS,
99 	/** 6.4us */
100 	HE_LTF_6400NS,
101 	/** 12.8us */
102 	HE_LTF_12800NS,
103 	/** Invalid value */
104 	HE_LTF_MAX
105 };
106 
107 /**
108  * @brief- Throughput mode
109  * Throughput mode to be used for transmitting the packet.
110  */
111 enum nrf_wifi_off_raw_tx_tput_mode {
112 	/** Legacy mode */
113 	TPUT_MODE_LEGACY,
114 	/** High Throughput mode (11n) */
115 	TPUT_MODE_HT,
116 	/** Very high throughput mode (11ac) */
117 	TPUT_MODE_VHT,
118 	/** HE SU mode */
119 	TPUT_MODE_HE_SU,
120 	/** HE ER SU mode */
121 	TPUT_MODE_HE_ER_SU,
122 	/** HE TB mode */
123 	TPUT_MODE_HE_TB,
124 	/** Highest throughput mode currently defined */
125 	TPUT_MODE_MAX
126 };
127 
128 /**
129  * @brief This structure defines the Offloaded raw tx debug statistics.
130  *
131  */
132 struct nrf_wifi_off_raw_tx_stats {
133 	/** Number of packets sent */
134 	unsigned int off_raw_tx_pkt_sent;
135 };
136 
137 /**
138  * @brief- Configuration parameters for offloaded raw TX
139  * Parameters which can be used to configure the offloaded raw TX operation.
140  */
141 struct nrf_wifi_off_raw_tx_conf {
142 	/** Time interval (in microseconds) between transmissions */
143 	unsigned int period_us;
144 	/** Transmit power in dBm (0 to 20) */
145 	unsigned int tx_pwr;
146 	/** Channel number on which to transmit */
147 	unsigned int chan;
148 	/** Set to TRUE to use short preamble for FALSE to disable short preamble */
149 	bool short_preamble;
150 	/* Number of times a packet should be retried at each possible rate */
151 	unsigned int num_retries;
152 	/** Throughput mode for packet transmittion. Refer &enum nrf_wifi_off_raw_tx_tput_mode */
153 	enum nrf_wifi_off_raw_tx_tput_mode tput_mode;
154 	/* Rate at which packet needs to be transmitted. Refer &enum nrf_wifi_off_raw_tx_rate */
155 	enum nrf_wifi_off_raw_tx_rate rate;
156 	/** HE GI. Refer &enum nrf_wifi_off_raw_tx_he_gi */
157 	enum nrf_wifi_off_raw_tx_he_gi he_gi;
158 	/** HE GI. Refer &enum nrf_wifi_off_raw_tx_he_ltf */
159 	enum nrf_wifi_off_raw_tx_he_ltf he_ltf;
160 	/* Pointer to packet to be transmitted */
161 	void *pkt;
162 	/** Packet length of the frame to be transmitted, (min 26 bytes and max 600 bytes) */
163 	unsigned int pkt_len;
164 };
165 
166 
167 /**
168  * @brief Initialize the nRF70 for operating in the offloaded raw TX mode.
169  * @param mac_addr MAC address to be used for the nRF70 device.
170  * @param country_code Country code to be set for regularity domain.
171  *
172  * This function is initializes the nRF70 device for offloaded raw TX mode by:
173  *  - Powering it up,
174  *  - Downloading a firmware patch (if any).
175  *  - Initializing the firmware to accept further commands
176  *
177  * The mac_addr parameter is used to set the MAC address of the nRF70 device.
178  * This address can be used to override the MAC addresses programmed in the OTP and
179  * the value configured (if any) in CONFIG_WIFI_FIXED_MAC_ADDRESS.
180  * The priority order in which the MAC address values for the nRF70 device are used is:
181  * - If mac_addr is provided, the MAC address is set to the value provided.
182  * - If CONFIG_WIFI_FIXED_MAC_ADDRESS is enabled, the MAC address uses the Kconfig value.
183  * - If none of the above are provided, the MAC address is set to the value programmed in the OTP.
184  *
185  * @retval 0 If the operation was successful.
186  * @retval -1 If the operation failed.
187  */
188 int nrf70_off_raw_tx_init(uint8_t *mac_addr, unsigned char *country_code);
189 
190 /**
191  * @brief Initialize the nRF70 for operating in the offloaded raw TX mode.
192  *
193  * This function is deinitializes the nRF70 device.
194  *
195  */
196 void nrf70_off_raw_tx_deinit(void);
197 
198 /**
199  * @brief Update the configured offloaded raw TX parameters.
200  * @param conf Configuration parameters to be updated for the offloaded raw TX operation.
201  *
202  * This function is used to update configured parameters for offloaded raw TX operation.
203  * This function should be used to when the parameters need to be updated during an ongoing
204  * raw TX operation without having to stop it.
205  *
206  * @retval 0 If the operation was successful.
207  * @retval -1 If the operation failed.
208  */
209 int nrf70_off_raw_tx_conf_update(struct nrf_wifi_off_raw_tx_conf *conf);
210 
211 /**
212  * @brief Start the offloaded raw TX.
213  * @param conf Configuration parameters necessary for the offloaded raw TX operation.
214  *
215  * This function is used to start offloaded raw TX operation. When this function is invoked
216  * the nRF70 device will start transmitting frames as per the configuration specified by @p conf.
217  *
218  * @retval 0 If the operation was successful.
219  * @retval -1 If the operation failed.
220  */
221 int nrf70_off_raw_tx_start(struct nrf_wifi_off_raw_tx_conf *conf);
222 
223 /**
224  * @brief Stop the offloaded raw TX.
225  *
226  * This function is used to stop offloaded raw TX operation. When this function is invoked
227  * the nRF70 device will stop transmitting frames.
228  *
229  * @retval 0 If the operation was successful.
230  * @retval -1 If the operation failed.
231  */
232 int nrf70_off_raw_tx_stop(void);
233 
234 /**
235  * @brief Get the MAC address of the nRF70 device.
236  * @param mac_addr Buffer to store the MAC address.
237  *
238  * This function is used to get the MAC address of the nRF70 device.
239  * The MAC address is stored in the buffer pointed by mac_addr.
240  * The MAC address is expected to be a 6 byte value.
241  *
242  * @retval 0 If the operation was successful.
243  * @retval -1 If the operation failed.
244  */
245 int nrf70_off_raw_tx_mac_addr_get(uint8_t *mac_addr);
246 
247 /**
248  * @brief Get statistics of the offloaded raw TX.
249  * @param off_raw_tx_stats Statistics of the offloaded raw TX operation.
250  *
251  * This function is used to get statistics of offloaded raw TX operation. When this function
252  * is invoked the nRF70 device will show statistics.
253  *
254  * @retval 0 If the operation was successful.
255  * @retval -1 If the operation failed.
256  */
257 int nrf70_off_raw_tx_stats(struct nrf_wifi_off_raw_tx_stats *off_raw_tx_stats);
258 /**
259  * @}
260  */
261 #endif /* INCLUDE_ZEPHYR_DRIVERS_OFF_RAW_TX_API_H_ */
262