1 | /** @file wlan_mac_entries.c |
---|
2 | * @brief Event log |
---|
3 | * |
---|
4 | * This contains the code for accessing event log. |
---|
5 | * |
---|
6 | * @copyright Copyright 2014-2019, Mango Communications. All rights reserved. |
---|
7 | * Distributed under the Mango Communications Reference Design License |
---|
8 | * See LICENSE.txt included in the design archive or |
---|
9 | * at http://mangocomm.com/802.11/license |
---|
10 | * |
---|
11 | * @note This is the only code that the user should modify in order to add entries |
---|
12 | * to the event log. To add a new entry, please follow the template provided |
---|
13 | * and create: |
---|
14 | * 1) A new entry type in wlan_mac_entries.h |
---|
15 | * 2) Wrapper function: get_next_empty_*_entry() |
---|
16 | * 3) Update the print function so that it is easy to print the log to the |
---|
17 | * terminal |
---|
18 | * |
---|
19 | * This file is part of the Mango 802.11 Reference Design (https://mangocomm.com/802.11) |
---|
20 | */ |
---|
21 | |
---|
22 | |
---|
23 | /***************************** Include Files *********************************/ |
---|
24 | |
---|
25 | #include "wlan_mac_high_sw_config.h" |
---|
26 | |
---|
27 | // SDK includes |
---|
28 | #include "stdio.h" |
---|
29 | #include "stdlib.h" |
---|
30 | #include "string.h" |
---|
31 | #include "xil_types.h" |
---|
32 | #include "xstatus.h" |
---|
33 | |
---|
34 | // WLAN includes |
---|
35 | #include "wlan_mac_common.h" |
---|
36 | #include "wlan_mac_pkt_buf_util.h" |
---|
37 | #include "wlan_mac_event_log.h" |
---|
38 | #include "wlan_mac_entries.h" |
---|
39 | #include "wlan_mac_802_11_defs.h" |
---|
40 | #include "wlan_platform_common.h" |
---|
41 | #include "wlan_mac_packet_types.h" |
---|
42 | |
---|
43 | // WLAN Exp includes |
---|
44 | #include "wlan_exp_common.h" |
---|
45 | #include "wlan_exp_node.h" |
---|
46 | |
---|
47 | // Includes for wlan_exp_log_get_txrx_entry_sizes() |
---|
48 | #include "wlan_mac_eth_util.h" |
---|
49 | #include "wlan_mac_high.h" |
---|
50 | #include "wlan_mac_ltg.h" |
---|
51 | |
---|
52 | #if WLAN_SW_CONFIG_ENABLE_LOGGING |
---|
53 | |
---|
54 | |
---|
55 | /*************************** Constant Definitions ****************************/ |
---|
56 | |
---|
57 | |
---|
58 | |
---|
59 | /*********************** Global Variable Definitions *************************/ |
---|
60 | |
---|
61 | static u8 log_entry_en_mask; |
---|
62 | static u32 system_time_id; |
---|
63 | |
---|
64 | extern volatile s8 low_param_tx_ctrl_pow; |
---|
65 | extern wlan_mac_hw_info_t wlan_mac_hw_info; |
---|
66 | extern platform_common_dev_info_t platform_common_dev_info; |
---|
67 | |
---|
68 | |
---|
69 | //----------------------------------------------- |
---|
70 | // mac_payload_log_len |
---|
71 | // |
---|
72 | // Global variable that defines the number of payload bytes that are recorded |
---|
73 | // for each transmission / reception. This value must be between: |
---|
74 | // MIN_MAC_PAYLOAD_LOG_LEN |
---|
75 | // MAX_MAC_PAYLOAD_LOG_LEN |
---|
76 | // and be 4-byte aligned. Use the wlan_exp_log_set_mac_payload_len() method |
---|
77 | // to change the value of this variable. By default, this is set to the minimum |
---|
78 | // payload length to save space in the log and can be altered by C code or |
---|
79 | // through WLAN Exp. |
---|
80 | // |
---|
81 | |
---|
82 | u32 mac_payload_log_len; |
---|
83 | |
---|
84 | |
---|
85 | |
---|
86 | /*************************** Variable Definitions ****************************/ |
---|
87 | |
---|
88 | |
---|
89 | |
---|
90 | /*************************** Functions Prototypes ****************************/ |
---|
91 | |
---|
92 | void wlan_exp_log_get_txrx_entry_sizes( u32 type, u16 packet_payload_size, u32* min_log_len, u32* entry_size, u32* payload_size ); |
---|
93 | |
---|
94 | |
---|
95 | |
---|
96 | /******************************** Functions **********************************/ |
---|
97 | |
---|
98 | /*****************************************************************************/ |
---|
99 | /** |
---|
100 | * Get / Set entry enable mask. |
---|
101 | * |
---|
102 | * @param mask - Enable Mask. Bitwise OR of: |
---|
103 | * - ENTRY_EN_MASK_TXRX_CTRL |
---|
104 | * - ENTRY_EN_MASK_TXRX_MPDU |
---|
105 | * |
---|
106 | * @return None |
---|
107 | * |
---|
108 | *****************************************************************************/ |
---|
109 | u8 wlan_exp_log_get_entry_en_mask(){ |
---|
110 | return log_entry_en_mask; |
---|
111 | } |
---|
112 | |
---|
113 | void wlan_exp_log_set_entry_en_mask(u8 mask){ |
---|
114 | log_entry_en_mask = mask; |
---|
115 | } |
---|
116 | |
---|
117 | |
---|
118 | |
---|
119 | /*****************************************************************************/ |
---|
120 | /** |
---|
121 | * Reset system time ID |
---|
122 | * |
---|
123 | * Resets the system time ID to the TIME_INFO_ENTRY_BASE_SYSTEM_TIME_ID constant |
---|
124 | * |
---|
125 | * @param None |
---|
126 | * @return None |
---|
127 | * |
---|
128 | *****************************************************************************/ |
---|
129 | void wlan_exp_log_reset_system_time_id(){ |
---|
130 | system_time_id = TIME_INFO_ENTRY_BASE_SYSTEM_TIME_ID; |
---|
131 | } |
---|
132 | |
---|
133 | |
---|
134 | |
---|
135 | /*****************************************************************************/ |
---|
136 | /** |
---|
137 | * Get / Set max_mac_payload_log_len |
---|
138 | * |
---|
139 | * @param payload_len - Number of bytes to set aside for payload. |
---|
140 | * NOTE: This needs to be 4-byte aligned. |
---|
141 | * |
---|
142 | * @return None |
---|
143 | * |
---|
144 | *****************************************************************************/ |
---|
145 | u32 wlan_exp_log_get_mac_payload_len() { |
---|
146 | return mac_payload_log_len; |
---|
147 | } |
---|
148 | |
---|
149 | void wlan_exp_log_set_mac_payload_len(u32 payload_len){ |
---|
150 | u32 value; |
---|
151 | u32 offset; |
---|
152 | |
---|
153 | // Make sure that value is 4-byte aligned. |
---|
154 | offset = payload_len % 4; |
---|
155 | if (offset != 0) { |
---|
156 | value = payload_len; |
---|
157 | } else { |
---|
158 | value = payload_len + (4 - offset); |
---|
159 | } |
---|
160 | |
---|
161 | // If the value is less than the minimum, then set it to the minimum |
---|
162 | if (value < MIN_MAC_PAYLOAD_LOG_LEN) { |
---|
163 | value = MIN_MAC_PAYLOAD_LOG_LEN; |
---|
164 | } |
---|
165 | |
---|
166 | // If the value is greater than the maximum, then set it to the maximum |
---|
167 | if (value > MAX_MAC_PAYLOAD_LOG_LEN) { |
---|
168 | value = MAX_MAC_PAYLOAD_LOG_LEN; |
---|
169 | } |
---|
170 | |
---|
171 | // Set the global variable |
---|
172 | mac_payload_log_len = value; |
---|
173 | } |
---|
174 | |
---|
175 | |
---|
176 | |
---|
177 | /*****************************************************************************/ |
---|
178 | /** |
---|
179 | * Get the next empty log entry |
---|
180 | * |
---|
181 | * @param entry_type_id - ID of the entry being requested |
---|
182 | * @param entry_size - Number of total bytes in the entry. |
---|
183 | * NOTE: This needs to be 4-byte aligned. |
---|
184 | * |
---|
185 | * @return void * - Pointer to memory that was allocated for the entry in the log |
---|
186 | * NOTE: This can be NULL if an entry was not allocated |
---|
187 | * |
---|
188 | *****************************************************************************/ |
---|
189 | void* wlan_exp_log_create_entry(u16 entry_type_id, u16 entry_size){ |
---|
190 | |
---|
191 | void* ret_val = NULL; |
---|
192 | |
---|
193 | // |
---|
194 | // NOTE: This is where filtering on entry_type_id would be in future implementations |
---|
195 | // |
---|
196 | |
---|
197 | ret_val = event_log_get_next_empty_entry( entry_type_id, entry_size ); |
---|
198 | |
---|
199 | return ret_val; |
---|
200 | } |
---|
201 | |
---|
202 | |
---|
203 | |
---|
204 | /*****************************************************************************/ |
---|
205 | /** |
---|
206 | * Create a TX Low Log entry |
---|
207 | * |
---|
208 | * @param tx_frame_info - Pointer to frame info of the associated TX low entry |
---|
209 | * @param tx_low_details - Pointer to specific information of the TX low transmission |
---|
210 | * @param tx_low_count - Indicates which TX low this is for the TX MPDU (starts at zero) |
---|
211 | * |
---|
212 | * @return tx_low_entry * - Pointer to tx_low_entry log entry |
---|
213 | * NOTE: This can be NULL if an entry was not allocated |
---|
214 | * |
---|
215 | *****************************************************************************/ |
---|
216 | tx_low_entry* wlan_exp_log_create_tx_low_entry(tx_frame_info_t* tx_frame_info, wlan_mac_low_tx_details_t* tx_low_details){ |
---|
217 | |
---|
218 | tx_low_entry* tx_low_event_log_entry = NULL; |
---|
219 | void* mac_payload; |
---|
220 | u8* mac_payload_ptr_u8; |
---|
221 | mac_header_80211* tx_80211_header; |
---|
222 | u32 packet_payload_size; |
---|
223 | u16 entry_type; |
---|
224 | u32 entry_size; |
---|
225 | u32 entry_payload_size; |
---|
226 | u32 min_entry_payload_size; |
---|
227 | u8 is_ltg; |
---|
228 | |
---|
229 | mac_payload = (u8*)tx_frame_info + PHY_TX_PKT_BUF_MPDU_OFFSET; |
---|
230 | mac_payload_ptr_u8 = (u8*)mac_payload; |
---|
231 | tx_80211_header = (mac_header_80211*)((void *)mac_payload_ptr_u8); |
---|
232 | is_ltg = 0; |
---|
233 | |
---|
234 | // ---------------------------------------------------- |
---|
235 | // Create RTS log entry |
---|
236 | // |
---|
237 | if (((tx_low_details->tx_details_type == TX_DETAILS_RTS_ONLY) || (tx_low_details->tx_details_type == TX_DETAILS_RTS_MPDU)) && |
---|
238 | (log_entry_en_mask & ENTRY_EN_MASK_TXRX_CTRL)) { |
---|
239 | |
---|
240 | entry_type = ENTRY_TYPE_TX_LOW; |
---|
241 | packet_payload_size = sizeof(mac_header_80211_RTS) + WLAN_PHY_FCS_NBYTES; |
---|
242 | |
---|
243 | // Get all the necessary sizes to log the packet |
---|
244 | wlan_exp_log_get_txrx_entry_sizes(entry_type, packet_payload_size, &entry_size, &entry_payload_size, &min_entry_payload_size); |
---|
245 | |
---|
246 | // Request space for a TX_LOW log entry |
---|
247 | tx_low_event_log_entry = (tx_low_entry *) wlan_exp_log_create_entry(entry_type, entry_size); |
---|
248 | |
---|
249 | if (tx_low_event_log_entry != NULL) { |
---|
250 | // Store the payload size in the log entry |
---|
251 | tx_low_event_log_entry->mac_payload_log_len = entry_payload_size; |
---|
252 | |
---|
253 | // Create the payload for the log entry |
---|
254 | // The actual RTS bytes that were transmitted aren't visible to this function. We only |
---|
255 | // have the underlying MPDU that the RTS was trying to reserve the medium for. Instead, |
---|
256 | // we can reconstruct what the RTS payload actually was in this log entry. |
---|
257 | // |
---|
258 | wlan_create_rts_frame((void*)(&((tx_low_entry*)tx_low_event_log_entry)->mac_payload), |
---|
259 | tx_80211_header->address_1, |
---|
260 | tx_80211_header->address_2, |
---|
261 | tx_low_details->duration); |
---|
262 | |
---|
263 | // Zero pad out the rest of the payload |
---|
264 | // A RTS is smaller than a typical 24-byte 802.11 header. |
---|
265 | // |
---|
266 | // TODO: There is no good way to get a valid FCS for CTRL transmissions since the packet |
---|
267 | // buffer is long gone. Instead, we'll explicitly zero out those bytes as well. |
---|
268 | // |
---|
269 | if ((packet_payload_size - WLAN_PHY_FCS_NBYTES) < entry_payload_size) { |
---|
270 | bzero((u8*)(((u32)((tx_low_entry*)tx_low_event_log_entry)->mac_payload) + (packet_payload_size - WLAN_PHY_FCS_NBYTES)), |
---|
271 | (entry_payload_size - (packet_payload_size - WLAN_PHY_FCS_NBYTES))); |
---|
272 | } |
---|
273 | |
---|
274 | // Update the log entry fields |
---|
275 | tx_low_event_log_entry->timestamp_send = tx_low_details->tx_start_timestamp_ctrl; |
---|
276 | tx_low_event_log_entry->unique_seq = tx_frame_info->unique_seq; // NOTE: RTS frames don't have sequence numbers. However, for easier processing |
---|
277 | // we'll include the MPDU's unique sequence number in this RTS TX LOW entry |
---|
278 | // Copy: MCS, PHY mode, Antenna mode, and Power |
---|
279 | memcpy((&((tx_low_entry*)tx_low_event_log_entry)->phy_params), &(tx_low_details->phy_params_ctrl), sizeof(phy_tx_params_t)); |
---|
280 | |
---|
281 | // We need to overwrite the Tx power for the RTS entry with the default control power, not the power |
---|
282 | // in the tx_frame_info_t used by the MPDU |
---|
283 | ((tx_low_entry*)tx_low_event_log_entry)->phy_params.power = low_param_tx_ctrl_pow; |
---|
284 | |
---|
285 | tx_low_event_log_entry->transmission_count = tx_low_details->attempt_number; |
---|
286 | tx_low_event_log_entry->chan_num = tx_low_details->chan_num; |
---|
287 | tx_low_event_log_entry->length = packet_payload_size; |
---|
288 | tx_low_event_log_entry->num_slots = tx_low_details->num_slots; |
---|
289 | tx_low_event_log_entry->cw = tx_low_details->cw; |
---|
290 | tx_low_event_log_entry->flags = 0; |
---|
291 | tx_low_event_log_entry->pkt_type = MAC_FRAME_CTRL1_SUBTYPE_RTS; |
---|
292 | tx_low_event_log_entry->flags = 0; |
---|
293 | |
---|
294 | if(tx_low_details->flags & TX_DETAILS_FLAGS_RECEIVED_RESPONSE){ |
---|
295 | tx_low_event_log_entry->flags |= TX_LOW_FLAGS_RECEIVED_RESPONSE; |
---|
296 | } else { |
---|
297 | tx_low_event_log_entry->flags &= ~TX_LOW_FLAGS_RECEIVED_RESPONSE; |
---|
298 | } |
---|
299 | |
---|
300 | tx_low_event_log_entry->timestamp_send_frac = tx_low_details->tx_start_timestamp_frac_ctrl; |
---|
301 | tx_low_event_log_entry->phy_samp_rate = tx_frame_info->phy_samp_rate; |
---|
302 | } |
---|
303 | } |
---|
304 | |
---|
305 | // ---------------------------------------------------- |
---|
306 | // Create MPDU, CTS, or ACK log entry |
---|
307 | // |
---|
308 | // Note: CTS and ACK entries will only be created in this |
---|
309 | // context if they were directly enqueued by the upper |
---|
310 | // level MAC |
---|
311 | if (((tx_low_details->tx_details_type == TX_DETAILS_MPDU) || (tx_low_details->tx_details_type == TX_DETAILS_RTS_MPDU) |
---|
312 | || (tx_low_details->tx_details_type == TX_DETAILS_CTS) || (tx_low_details->tx_details_type == TX_DETAILS_ACK) ) && |
---|
313 | (log_entry_en_mask & ENTRY_EN_MASK_TXRX_MPDU)) { |
---|
314 | |
---|
315 | packet_payload_size = tx_frame_info->length; |
---|
316 | |
---|
317 | // Determine the type of the packet |
---|
318 | is_ltg = wlan_mac_high_is_pkt_ltg(mac_payload, packet_payload_size); |
---|
319 | |
---|
320 | // Determine the entry type |
---|
321 | if (is_ltg) { |
---|
322 | entry_type = ENTRY_TYPE_TX_LOW_LTG; |
---|
323 | } else { |
---|
324 | entry_type = ENTRY_TYPE_TX_LOW; |
---|
325 | } |
---|
326 | |
---|
327 | // Get all the necessary sizes to log the packet |
---|
328 | wlan_exp_log_get_txrx_entry_sizes(entry_type, packet_payload_size, &entry_size, &entry_payload_size, &min_entry_payload_size); |
---|
329 | |
---|
330 | // Request space for a TX_LOW log entry |
---|
331 | tx_low_event_log_entry = (tx_low_entry *) wlan_exp_log_create_entry(entry_type, entry_size); |
---|
332 | |
---|
333 | if(tx_low_event_log_entry != NULL){ |
---|
334 | // Store the payload size in the log entry |
---|
335 | tx_low_event_log_entry->mac_payload_log_len = entry_payload_size; |
---|
336 | |
---|
337 | // Transfer the payload to the log entry |
---|
338 | wlan_mac_high_cdma_start_transfer((&((tx_low_entry*)tx_low_event_log_entry)->mac_payload), tx_80211_header, entry_payload_size); |
---|
339 | |
---|
340 | // Zero pad log entry if payload_size was less than the allocated space in the log (ie min_log_len) |
---|
341 | if(entry_payload_size < min_entry_payload_size){ |
---|
342 | bzero((u8*)(((u32)((tx_low_entry*)tx_low_event_log_entry)->mac_payload) + entry_payload_size), (min_entry_payload_size - entry_payload_size)); |
---|
343 | } |
---|
344 | |
---|
345 | // Update the log entry fields |
---|
346 | tx_low_event_log_entry->timestamp_send = tx_low_details->tx_start_timestamp_mpdu; |
---|
347 | tx_low_event_log_entry->unique_seq = tx_frame_info->unique_seq; |
---|
348 | |
---|
349 | // Copy: MCS, PHY mode, Antenna mode, and Power |
---|
350 | memcpy((&((tx_low_entry*)tx_low_event_log_entry)->phy_params), &(tx_low_details->phy_params_mpdu), sizeof(phy_tx_params_t)); |
---|
351 | |
---|
352 | tx_low_event_log_entry->transmission_count = tx_low_details->attempt_number; |
---|
353 | tx_low_event_log_entry->chan_num = tx_low_details->chan_num; |
---|
354 | tx_low_event_log_entry->length = tx_frame_info->length; |
---|
355 | tx_low_event_log_entry->num_slots = tx_low_details->num_slots; |
---|
356 | tx_low_event_log_entry->cw = tx_low_details->cw; |
---|
357 | tx_low_event_log_entry->pkt_type = tx_80211_header->frame_control_1; |
---|
358 | |
---|
359 | if(is_ltg){ |
---|
360 | tx_low_event_log_entry->flags |= TX_LOW_FLAGS_LTG_PYLD; |
---|
361 | tx_low_event_log_entry->flags |= TX_LOW_FLAGS_LTG; |
---|
362 | } else { |
---|
363 | tx_low_event_log_entry->flags &= ~TX_LOW_FLAGS_LTG_PYLD; |
---|
364 | tx_low_event_log_entry->flags &= ~TX_LOW_FLAGS_LTG; |
---|
365 | } |
---|
366 | |
---|
367 | if(tx_low_details->flags & TX_DETAILS_FLAGS_RECEIVED_RESPONSE){ |
---|
368 | tx_low_event_log_entry->flags |= TX_LOW_FLAGS_RECEIVED_RESPONSE; |
---|
369 | } else { |
---|
370 | tx_low_event_log_entry->flags &= ~TX_LOW_FLAGS_RECEIVED_RESPONSE; |
---|
371 | } |
---|
372 | |
---|
373 | tx_low_event_log_entry->timestamp_send_frac = tx_low_details->tx_start_timestamp_frac_mpdu; |
---|
374 | tx_low_event_log_entry->phy_samp_rate = tx_frame_info->phy_samp_rate; |
---|
375 | |
---|
376 | // Finish CDMA transfer of the payload |
---|
377 | wlan_mac_high_cdma_finish_transfer(); |
---|
378 | |
---|
379 | // CPU Low updates the retry flag in the header for any re-transmissions |
---|
380 | // Re-create the original header for the first TX_LOW by de-asserting the flag |
---|
381 | if(tx_low_details->attempt_number == 1) { |
---|
382 | // This is the first transmission |
---|
383 | mac_header_80211* mac_header = (mac_header_80211*)(tx_low_event_log_entry->mac_payload); |
---|
384 | mac_header->frame_control_2 &= ~MAC_FRAME_CTRL2_FLAG_RETRY; |
---|
385 | } else { |
---|
386 | // This is all subsequent transmissions |
---|
387 | mac_header_80211* mac_header = (mac_header_80211*)(tx_low_event_log_entry->mac_payload); |
---|
388 | mac_header->frame_control_2 |= ~MAC_FRAME_CTRL2_FLAG_RETRY; |
---|
389 | } |
---|
390 | } |
---|
391 | } |
---|
392 | |
---|
393 | return tx_low_event_log_entry; |
---|
394 | } |
---|
395 | |
---|
396 | |
---|
397 | |
---|
398 | /*****************************************************************************/ |
---|
399 | /** |
---|
400 | * Create a TX High Log entry |
---|
401 | * |
---|
402 | * @param tx_frame_info - Pointer to frame info of the associated TX entry |
---|
403 | * @param channel_number - Indicates the channel on which the transmission occurred |
---|
404 | * |
---|
405 | * @return tx_high_entry * - Pointer to the tx_high_entry log entry |
---|
406 | * NOTE: This can be NULL if an entry was not allocated |
---|
407 | * |
---|
408 | *****************************************************************************/ |
---|
409 | tx_high_entry* wlan_exp_log_create_tx_high_entry(tx_frame_info_t* tx_frame_info){ |
---|
410 | |
---|
411 | tx_high_entry* tx_high_event_log_entry = NULL; |
---|
412 | void* mac_payload = (u8*)tx_frame_info + PHY_TX_PKT_BUF_MPDU_OFFSET; |
---|
413 | u8* mac_payload_ptr_u8 = (u8*)mac_payload; |
---|
414 | mac_header_80211* tx_80211_header = (mac_header_80211*)((void *)mac_payload_ptr_u8); |
---|
415 | u32 packet_payload_size = tx_frame_info->length; |
---|
416 | u16 entry_type; |
---|
417 | u32 entry_size; |
---|
418 | u32 entry_payload_size; |
---|
419 | u32 min_entry_payload_size; |
---|
420 | u32 transfer_len; |
---|
421 | u8 is_ltg; |
---|
422 | |
---|
423 | // MPDU logging is disabled |
---|
424 | if((log_entry_en_mask & ENTRY_EN_MASK_TXRX_MPDU) == 0){ |
---|
425 | return NULL; |
---|
426 | } |
---|
427 | |
---|
428 | is_ltg = wlan_mac_high_is_pkt_ltg(mac_payload, packet_payload_size); |
---|
429 | |
---|
430 | // Determine the entry type |
---|
431 | if (is_ltg) { |
---|
432 | entry_type = ENTRY_TYPE_TX_HIGH_LTG; |
---|
433 | } else { |
---|
434 | entry_type = ENTRY_TYPE_TX_HIGH; |
---|
435 | } |
---|
436 | |
---|
437 | // Get all the necessary sizes to log the packet |
---|
438 | wlan_exp_log_get_txrx_entry_sizes( entry_type, packet_payload_size, &entry_size, &entry_payload_size, &min_entry_payload_size ); |
---|
439 | |
---|
440 | // Request space for a TX entry |
---|
441 | tx_high_event_log_entry = (tx_high_entry *)wlan_exp_log_create_entry( entry_type, entry_size ); |
---|
442 | |
---|
443 | if(tx_high_event_log_entry != NULL){ |
---|
444 | |
---|
445 | // Fill in the TX log entry |
---|
446 | // This is done one field at a time, as the TX log entry format is not a byte-for-byte copy of the tx_frame_info |
---|
447 | tx_high_event_log_entry->mac_payload_log_len = entry_payload_size; |
---|
448 | |
---|
449 | // Compute the length of the DMA transfer to log the packet: |
---|
450 | // |
---|
451 | // We have two arrays in memory that we have to be aware of: |
---|
452 | // 1) The packet payload that has "packet_payload_size" bytes; |
---|
453 | // 2) The TX log entry that has "entry_payload_size" bytes; |
---|
454 | // |
---|
455 | // Because the packet payload does not have to be 32-bit aligned and we could be logging an arbitrary number of |
---|
456 | // bytes of the packet, we have to be careful about not walking off the end of either array. Therefore, we need |
---|
457 | // to transfer the shorter of the two arrays and then zero pad the log entry if we transfered less than |
---|
458 | // "entry_payload_size" bytes. |
---|
459 | // |
---|
460 | transfer_len = WLAN_MIN(entry_payload_size, packet_payload_size); |
---|
461 | |
---|
462 | wlan_mac_high_cdma_start_transfer((&((tx_high_entry*)tx_high_event_log_entry)->mac_payload), tx_80211_header, transfer_len); |
---|
463 | |
---|
464 | // Zero pad log entry if transfer_len was less than the allocated space in the log (ie entry_payload_size) |
---|
465 | if(transfer_len < entry_payload_size){ |
---|
466 | bzero((u8*)(((u32)((tx_high_entry*)tx_high_event_log_entry)->mac_payload) + transfer_len), (entry_payload_size - transfer_len) ); |
---|
467 | } |
---|
468 | |
---|
469 | // Populate the log entry |
---|
470 | tx_high_event_log_entry->timestamp_create = tx_frame_info->queue_info.enqueue_timestamp; |
---|
471 | tx_high_event_log_entry->delay_accept = (u32)(tx_frame_info->timestamp_accept - tx_frame_info->queue_info.enqueue_timestamp); |
---|
472 | tx_high_event_log_entry->delay_done = (u32)(tx_frame_info->timestamp_done - tx_frame_info->timestamp_accept); |
---|
473 | tx_high_event_log_entry->unique_seq = tx_frame_info->unique_seq; |
---|
474 | tx_high_event_log_entry->num_tx = tx_frame_info->num_tx_attempts; // TODO: Add long/short distinction to event log |
---|
475 | tx_high_event_log_entry->length = tx_frame_info->length; |
---|
476 | tx_high_event_log_entry->flags = 0; |
---|
477 | |
---|
478 | if(is_ltg){ |
---|
479 | tx_high_event_log_entry->flags |= TX_LOW_FLAGS_LTG_PYLD; |
---|
480 | tx_high_event_log_entry->flags |= TX_LOW_FLAGS_LTG; |
---|
481 | } else { |
---|
482 | tx_high_event_log_entry->flags &= ~TX_LOW_FLAGS_LTG_PYLD; |
---|
483 | tx_high_event_log_entry->flags &= ~TX_LOW_FLAGS_LTG; |
---|
484 | } |
---|
485 | if(tx_frame_info->tx_result == TX_FRAME_INFO_RESULT_SUCCESS){ |
---|
486 | tx_high_event_log_entry->flags |= TX_HIGH_FLAGS_SUCCESSFUL; |
---|
487 | } else { |
---|
488 | tx_high_event_log_entry->flags &= ~TX_HIGH_FLAGS_SUCCESSFUL; |
---|
489 | } |
---|
490 | tx_high_event_log_entry->pkt_type = tx_80211_header->frame_control_1; |
---|
491 | tx_high_event_log_entry->queue_id = tx_frame_info->queue_info.id; |
---|
492 | tx_high_event_log_entry->queue_occupancy = tx_frame_info->queue_info.occupancy; |
---|
493 | } |
---|
494 | |
---|
495 | return tx_high_event_log_entry; |
---|
496 | } |
---|
497 | |
---|
498 | |
---|
499 | |
---|
500 | /*****************************************************************************/ |
---|
501 | /** |
---|
502 | * Create a RX Log entry |
---|
503 | * |
---|
504 | * @param rx_mpdu - Pointer to RX MPDU of the associated RX entry |
---|
505 | * @param rate - Indicates the rate at which the reception occurred |
---|
506 | * |
---|
507 | * @return rx_common_entry * - Pointer to the rx_common_entry log entry |
---|
508 | * NOTE: This can be NULL if an entry was not allocated |
---|
509 | * |
---|
510 | *****************************************************************************/ |
---|
511 | rx_common_entry* wlan_exp_log_create_rx_entry(rx_frame_info_t* rx_frame_info){ |
---|
512 | |
---|
513 | rx_common_entry* rx_event_log_entry = NULL; |
---|
514 | tx_low_entry* tx_low_event_log_entry = NULL; //This is for any inferred CTRL transmissions |
---|
515 | void* mac_payload = (u8*)rx_frame_info + PHY_RX_PKT_BUF_MPDU_OFFSET; |
---|
516 | u8* mac_payload_ptr_u8 = (u8*)mac_payload; |
---|
517 | ltg_packet_id_t* pkt_id; |
---|
518 | mac_header_80211* rx_80211_header = (mac_header_80211*)((void *)mac_payload_ptr_u8); |
---|
519 | u32 packet_payload_size = rx_frame_info->phy_details.length; |
---|
520 | u8 phy_mode = rx_frame_info->phy_details.phy_mode; |
---|
521 | u32 entry_type; |
---|
522 | u8 rx_is_ltg = 0; |
---|
523 | u32 entry_size; |
---|
524 | u32 entry_payload_size; |
---|
525 | u32 min_entry_payload_size; |
---|
526 | u32 transfer_len; |
---|
527 | |
---|
528 | pkt_id = (ltg_packet_id_t*)(mac_payload_ptr_u8 + sizeof(mac_header_80211)); |
---|
529 | |
---|
530 | typedef enum copy_order_t{ |
---|
531 | PAYLOAD_FIRST, |
---|
532 | CHAN_EST_FIRST |
---|
533 | } copy_order_t; |
---|
534 | copy_order_t copy_order; |
---|
535 | |
---|
536 | if ((((rx_80211_header->frame_control_1 & 0xF) == MAC_FRAME_CTRL1_TYPE_DATA) && (log_entry_en_mask & ENTRY_EN_MASK_TXRX_MPDU)) || |
---|
537 | (((rx_80211_header->frame_control_1 & 0xF) == MAC_FRAME_CTRL1_TYPE_CTRL) && (log_entry_en_mask & ENTRY_EN_MASK_TXRX_CTRL)) || |
---|
538 | ( (rx_80211_header->frame_control_1 & 0xF) == MAC_FRAME_CTRL1_TYPE_MGMT) || |
---|
539 | ( (rx_frame_info->flags & RX_FRAME_INFO_FLAGS_FCS_GOOD) == 0)) { |
---|
540 | //Note: If the frame was not correctly decoded, we can not rely on the frame control byte to filter away log entry types. All |
---|
541 | //bad FCS packets are logged and any content based on MAC payload are best effort and should not be trusted by the log |
---|
542 | //processing context. |
---|
543 | |
---|
544 | // Determine the type of the packet |
---|
545 | rx_is_ltg = wlan_mac_high_is_pkt_ltg(mac_payload, packet_payload_size); |
---|
546 | |
---|
547 | // Determine the entry type based on the received waveform format |
---|
548 | if((phy_mode & PHY_MODE_HTMF) || (phy_mode & PHY_MODE_NONHT)) { |
---|
549 | if(rx_is_ltg){ |
---|
550 | entry_type = ENTRY_TYPE_RX_OFDM_LTG; |
---|
551 | } else { |
---|
552 | entry_type = ENTRY_TYPE_RX_OFDM; |
---|
553 | } |
---|
554 | } else { |
---|
555 | // DSSS reception |
---|
556 | entry_type = ENTRY_TYPE_RX_DSSS; |
---|
557 | } |
---|
558 | |
---|
559 | // Get all the necessary sizes to log the packet |
---|
560 | wlan_exp_log_get_txrx_entry_sizes(entry_type, packet_payload_size, &entry_size, &entry_payload_size, &min_entry_payload_size); |
---|
561 | |
---|
562 | // Create the log entry |
---|
563 | rx_event_log_entry = (rx_common_entry*) wlan_exp_log_create_entry(entry_type, entry_size); |
---|
564 | |
---|
565 | // Populate the log entry |
---|
566 | if (rx_event_log_entry != NULL) { |
---|
567 | |
---|
568 | // For maximum pipelining, we'll break up the two major log copy operations (packet payload + [optional] channel estimates) |
---|
569 | // We will start the CDMA operation for whichever of those copies is shorter, then fill in the rest of the log entry |
---|
570 | // while that copy is under way, and then start the CDMA operation for the larger (which will first block on the shorter if |
---|
571 | // it is still going). |
---|
572 | |
---|
573 | if (phy_mode == PHY_MODE_DSSS) { |
---|
574 | // This is a DSSS packet that has no channel estimates |
---|
575 | copy_order = PAYLOAD_FIRST; |
---|
576 | } else { |
---|
577 | // This is an OFDM packet that contains channel estimates |
---|
578 | #ifdef WLAN_MAC_ENTRIES_LOG_CHAN_EST |
---|
579 | if (sizeof(rx_frame_info->channel_est) < packet_payload_size) { |
---|
580 | copy_order = CHAN_EST_FIRST; |
---|
581 | } else { |
---|
582 | copy_order = PAYLOAD_FIRST; |
---|
583 | } |
---|
584 | #else |
---|
585 | copy_order = PAYLOAD_FIRST; |
---|
586 | #endif |
---|
587 | } |
---|
588 | |
---|
589 | // Compute the length of the DMA transfer to log the packet: |
---|
590 | // |
---|
591 | // We have two arrays in memory that we have to be aware of: |
---|
592 | // 1) The packet payload that has "packet_payload_size" bytes; |
---|
593 | // 2) The RX log entry that has "entry_payload_size" bytes; |
---|
594 | // |
---|
595 | // Because the packet payload does not have to be 32-bit aligned and we could be logging an arbitrary number of |
---|
596 | // bytes of the packet, we have to be careful about not walking off the end of either array. Therefore, we need |
---|
597 | // to transfer the shorter of the two arrays and then zero pad the log entry if we transfered less than |
---|
598 | // "entry_payload_size" bytes. |
---|
599 | // |
---|
600 | transfer_len = WLAN_MIN(entry_payload_size, packet_payload_size); |
---|
601 | |
---|
602 | // Start copy based on the copy order |
---|
603 | switch (copy_order) { |
---|
604 | case PAYLOAD_FIRST: |
---|
605 | if (phy_mode != PHY_MODE_DSSS) { |
---|
606 | ((rx_ofdm_entry*)rx_event_log_entry)->mac_payload_log_len = entry_payload_size; |
---|
607 | wlan_mac_high_cdma_start_transfer((((rx_ofdm_entry*)rx_event_log_entry)->mac_payload), rx_80211_header, transfer_len); |
---|
608 | |
---|
609 | // Zero pad log entry if transfer_len was less than the allocated space in the log (ie entry_payload_size) |
---|
610 | if (transfer_len < entry_payload_size) { |
---|
611 | bzero((u8*)(((u32)((rx_ofdm_entry*)rx_event_log_entry)->mac_payload) + transfer_len), (entry_payload_size - transfer_len)); |
---|
612 | } |
---|
613 | } else { |
---|
614 | ((rx_dsss_entry*)rx_event_log_entry)->mac_payload_log_len = entry_payload_size; |
---|
615 | wlan_mac_high_cdma_start_transfer((((rx_dsss_entry*)rx_event_log_entry)->mac_payload), rx_80211_header, transfer_len); |
---|
616 | |
---|
617 | // Zero pad log entry if transfer_len was less than the allocated space in the log (ie entry_payload_size) |
---|
618 | if (transfer_len < entry_payload_size) { |
---|
619 | bzero((u8*)(((u32)((rx_dsss_entry*)rx_event_log_entry)->mac_payload) + transfer_len), (entry_payload_size - transfer_len)); |
---|
620 | } |
---|
621 | } |
---|
622 | break; |
---|
623 | |
---|
624 | case CHAN_EST_FIRST: |
---|
625 | #ifdef WLAN_MAC_ENTRIES_LOG_CHAN_EST |
---|
626 | if (phy_mode != PHY_MODE_DSSS) wlan_mac_high_cdma_start_transfer(((rx_ofdm_entry*)rx_event_log_entry)->channel_est, rx_frame_info->channel_est, sizeof(rx_frame_info->channel_est)); |
---|
627 | #endif |
---|
628 | break; |
---|
629 | } |
---|
630 | |
---|
631 | // Fill in Log Entry |
---|
632 | rx_event_log_entry->timestamp = rx_frame_info->timestamp; |
---|
633 | rx_event_log_entry->timestamp_frac = rx_frame_info->timestamp_frac; |
---|
634 | rx_event_log_entry->phy_samp_rate = rx_frame_info->phy_samp_rate; |
---|
635 | rx_event_log_entry->length = rx_frame_info->phy_details.length; |
---|
636 | rx_event_log_entry->cfo_est = rx_frame_info->cfo_est; |
---|
637 | rx_event_log_entry->mcs = rx_frame_info->phy_details.mcs; |
---|
638 | rx_event_log_entry->phy_mode = rx_frame_info->phy_details.phy_mode; |
---|
639 | rx_event_log_entry->ant_mode = rx_frame_info->ant_mode; |
---|
640 | rx_event_log_entry->power = rx_frame_info->rx_power; |
---|
641 | rx_event_log_entry->flags = 0; |
---|
642 | if(rx_is_ltg){ |
---|
643 | rx_event_log_entry->flags |= RX_FLAGS_LTG_PYLD; |
---|
644 | rx_event_log_entry->flags |= RX_FLAGS_LTG; |
---|
645 | } else { |
---|
646 | rx_event_log_entry->flags &= ~RX_FLAGS_LTG_PYLD; |
---|
647 | rx_event_log_entry->flags &= ~RX_FLAGS_LTG; |
---|
648 | } |
---|
649 | |
---|
650 | |
---|
651 | if( (rx_frame_info->flags & RX_FRAME_INFO_FLAGS_FCS_GOOD) ){ |
---|
652 | rx_event_log_entry->flags |= RX_FLAGS_FCS_GOOD; |
---|
653 | } else { |
---|
654 | rx_event_log_entry->flags &= ~RX_FLAGS_FCS_GOOD; |
---|
655 | } |
---|
656 | |
---|
657 | if( (rx_frame_info->flags & RX_FRAME_INFO_UNEXPECTED_RESPONSE) ){ |
---|
658 | rx_event_log_entry->flags |= RX_FLAGS_UNEXPECTED_RESPONSE; |
---|
659 | } else { |
---|
660 | rx_event_log_entry->flags &= ~RX_FLAGS_UNEXPECTED_RESPONSE; |
---|
661 | } |
---|
662 | |
---|
663 | rx_event_log_entry->pkt_type = rx_80211_header->frame_control_1; |
---|
664 | rx_event_log_entry->chan_num = rx_frame_info->channel; |
---|
665 | rx_event_log_entry->rx_gain_index = rx_frame_info->rx_gain_index; |
---|
666 | |
---|
667 | // Start second copy based on the copy order |
---|
668 | switch(copy_order){ |
---|
669 | case PAYLOAD_FIRST: |
---|
670 | #ifdef WLAN_MAC_ENTRIES_LOG_CHAN_EST |
---|
671 | if(phy_mode != PHY_MODE_DSSS) wlan_mac_high_cdma_start_transfer(((rx_ofdm_entry*)rx_event_log_entry)->channel_est, rx_frame_info->channel_est, sizeof(rx_frame_info->channel_est)); |
---|
672 | #endif |
---|
673 | break; |
---|
674 | |
---|
675 | case CHAN_EST_FIRST: |
---|
676 | if (phy_mode != PHY_MODE_DSSS) { |
---|
677 | ((rx_ofdm_entry*)rx_event_log_entry)->mac_payload_log_len = entry_payload_size; |
---|
678 | wlan_mac_high_cdma_start_transfer((((rx_ofdm_entry*)rx_event_log_entry)->mac_payload), rx_80211_header, transfer_len); |
---|
679 | |
---|
680 | // Zero pad log entry if transfer_len was less than the allocated space in the log (ie entry_payload_size) |
---|
681 | if (transfer_len < entry_payload_size) { |
---|
682 | bzero((u8*)(((u32)((rx_ofdm_entry*)rx_event_log_entry)->mac_payload) + transfer_len), (entry_payload_size - transfer_len)); |
---|
683 | } |
---|
684 | } else { |
---|
685 | ((rx_dsss_entry*)rx_event_log_entry)->mac_payload_log_len = entry_payload_size; |
---|
686 | wlan_mac_high_cdma_start_transfer((((rx_dsss_entry*)rx_event_log_entry)->mac_payload), rx_80211_header, transfer_len); |
---|
687 | |
---|
688 | // Zero pad log entry if transfer_len was less than the allocated space in the log (ie entry_payload_size) |
---|
689 | if (transfer_len < entry_payload_size) { |
---|
690 | bzero((u8*)(((u32)((rx_dsss_entry*)rx_event_log_entry)->mac_payload) + transfer_len), (entry_payload_size - transfer_len)); |
---|
691 | } |
---|
692 | } |
---|
693 | break; |
---|
694 | } |
---|
695 | } |
---|
696 | } |
---|
697 | |
---|
698 | if ((rx_frame_info->flags & RX_FRAME_INFO_FLAGS_CTRL_RESP_TX) && (log_entry_en_mask & ENTRY_EN_MASK_TXRX_CTRL)) { |
---|
699 | |
---|
700 | // ------------------------------------------------ |
---|
701 | // Create CTS log entry |
---|
702 | // |
---|
703 | if (rx_80211_header->frame_control_1 == MAC_FRAME_CTRL1_SUBTYPE_RTS) { |
---|
704 | |
---|
705 | entry_type = ENTRY_TYPE_TX_LOW; |
---|
706 | packet_payload_size = sizeof(mac_header_80211_CTS) + WLAN_PHY_FCS_NBYTES; |
---|
707 | |
---|
708 | // Get all the necessary sizes to log the packet |
---|
709 | wlan_exp_log_get_txrx_entry_sizes(entry_type, packet_payload_size, &entry_size, &entry_payload_size, &min_entry_payload_size); |
---|
710 | |
---|
711 | // Request space for a TX_LOW log entry |
---|
712 | tx_low_event_log_entry = (tx_low_entry *) wlan_exp_log_create_entry(entry_type, entry_size); |
---|
713 | |
---|
714 | if (tx_low_event_log_entry != NULL) { |
---|
715 | // Store the payload size in the log entry |
---|
716 | tx_low_event_log_entry->mac_payload_log_len = entry_payload_size; |
---|
717 | |
---|
718 | // Create the payload for the log entry |
---|
719 | // The actual CTS bytes that were transmitted aren't visible to this function. We only |
---|
720 | // have the underlying MPDU that the CTS was trying to reserve the medium for. Instead, |
---|
721 | // we can reconstruct what the CTS payload actually was in this log entry. |
---|
722 | // |
---|
723 | wlan_create_cts_frame((void*)(&((tx_low_entry*)tx_low_event_log_entry)->mac_payload), |
---|
724 | rx_80211_header->address_2, |
---|
725 | rx_frame_info->resp_low_tx_details.duration); |
---|
726 | |
---|
727 | // Zero pad out the rest of the payload |
---|
728 | // A CTS is smaller than a typical 24-byte 802.11 header. |
---|
729 | // |
---|
730 | // TODO: There is no good way to get a valid FCS for CTRL transmissions since the packet |
---|
731 | // buffer is long gone. Instead, we'll explicitly zero out those bytes as well. |
---|
732 | // |
---|
733 | if ((packet_payload_size - WLAN_PHY_FCS_NBYTES) < entry_payload_size) { |
---|
734 | bzero((u8*)(((u32)((tx_low_entry*)tx_low_event_log_entry)->mac_payload) + (packet_payload_size - WLAN_PHY_FCS_NBYTES)), |
---|
735 | (entry_payload_size - (packet_payload_size - WLAN_PHY_FCS_NBYTES))); |
---|
736 | } |
---|
737 | |
---|
738 | // Update the log entry fields |
---|
739 | tx_low_event_log_entry->timestamp_send = rx_frame_info->resp_low_tx_details.tx_start_timestamp_ctrl; |
---|
740 | tx_low_event_log_entry->unique_seq = UNIQUE_SEQ_INVALID; |
---|
741 | |
---|
742 | // Copy: MCS, PHY mode, Antenna mode, and Power |
---|
743 | memcpy((&((tx_low_entry*)tx_low_event_log_entry)->phy_params), &(rx_frame_info->resp_low_tx_details.phy_params_ctrl), sizeof(phy_tx_params_t)); |
---|
744 | |
---|
745 | tx_low_event_log_entry->transmission_count = 1; |
---|
746 | tx_low_event_log_entry->chan_num = rx_frame_info->resp_low_tx_details.chan_num; |
---|
747 | tx_low_event_log_entry->length = packet_payload_size; |
---|
748 | tx_low_event_log_entry->num_slots = rx_frame_info->resp_low_tx_details.num_slots; |
---|
749 | tx_low_event_log_entry->cw = rx_frame_info->resp_low_tx_details.cw; |
---|
750 | tx_low_event_log_entry->pkt_type = MAC_FRAME_CTRL1_SUBTYPE_CTS; |
---|
751 | // Note: an Rx MPDU in response to this CTS will not be flagged as TX_LOW_FLAGS_RECEIVED_RESPONSE since there is no timeout after |
---|
752 | // a CTS transmission. |
---|
753 | tx_low_event_log_entry->flags = 0; |
---|
754 | tx_low_event_log_entry->timestamp_send_frac = rx_frame_info->resp_low_tx_details.tx_start_timestamp_frac_ctrl; |
---|
755 | tx_low_event_log_entry->phy_samp_rate = rx_frame_info->phy_samp_rate; // TODO: Makes assumption that response uses same PHY BW as Rx |
---|
756 | } |
---|
757 | |
---|
758 | // ------------------------------------------------ |
---|
759 | // Create ACK log entry |
---|
760 | // |
---|
761 | } else { |
---|
762 | // Note: this clause will be called for any reception that led to a control frame response. Since we have dealt with the CTS case |
---|
763 | // above, the only ever control response must be an ACK transmission. |
---|
764 | entry_type = ENTRY_TYPE_TX_LOW; |
---|
765 | packet_payload_size = sizeof(mac_header_80211_ACK) + WLAN_PHY_FCS_NBYTES; |
---|
766 | |
---|
767 | // Get all the necessary sizes to log the packet |
---|
768 | wlan_exp_log_get_txrx_entry_sizes(entry_type, packet_payload_size, &entry_size, &entry_payload_size, &min_entry_payload_size); |
---|
769 | |
---|
770 | // Request space for a TX_LOW log entry |
---|
771 | tx_low_event_log_entry = (tx_low_entry *) wlan_exp_log_create_entry(entry_type, entry_size); |
---|
772 | |
---|
773 | if (tx_low_event_log_entry != NULL) { |
---|
774 | // Store the payload size in the log entry |
---|
775 | tx_low_event_log_entry->mac_payload_log_len = entry_payload_size; |
---|
776 | |
---|
777 | // Create the payload for the log entry |
---|
778 | // The actual ACK bytes that were transmitted aren't visible to this function. We only |
---|
779 | // have the underlying MPDU that the ACK was a response for. Instead, we can reconstruct |
---|
780 | // what the ACK payload actually was in this log entry. |
---|
781 | // |
---|
782 | wlan_create_ack_frame((void*)(&((tx_low_entry*)tx_low_event_log_entry)->mac_payload), |
---|
783 | rx_80211_header->address_2); |
---|
784 | |
---|
785 | // Zero pad out the rest of the payload |
---|
786 | // An ACK is smaller than a typical 24-byte 802.11 header. |
---|
787 | // |
---|
788 | // TODO: There is no good way to get a valid FCS for CTRL transmissions since the packet |
---|
789 | // buffer is long gone. Instead, we'll explicitly zero out those bytes as well. |
---|
790 | // |
---|
791 | if ((packet_payload_size - WLAN_PHY_FCS_NBYTES) < entry_payload_size) { |
---|
792 | bzero((u8*)(((u32)((tx_low_entry*)tx_low_event_log_entry)->mac_payload) + (packet_payload_size - WLAN_PHY_FCS_NBYTES)), |
---|
793 | (entry_payload_size - (packet_payload_size - WLAN_PHY_FCS_NBYTES))); |
---|
794 | } |
---|
795 | |
---|
796 | // Update the log entry fields |
---|
797 | tx_low_event_log_entry->timestamp_send = rx_frame_info->resp_low_tx_details.tx_start_timestamp_ctrl; |
---|
798 | |
---|
799 | // If the received MPDU is an LTG, we can mirror its unique seq into the Tx unique seq for the ACK |
---|
800 | if (rx_is_ltg) { |
---|
801 | tx_low_event_log_entry->unique_seq = pkt_id->unique_seq; |
---|
802 | } else { |
---|
803 | tx_low_event_log_entry->unique_seq = UNIQUE_SEQ_INVALID; |
---|
804 | } |
---|
805 | |
---|
806 | // Copy: MCS, PHY mode, Antenna mode, and Power |
---|
807 | memcpy((&((tx_low_entry*)tx_low_event_log_entry)->phy_params), &(rx_frame_info->resp_low_tx_details.phy_params_ctrl), sizeof(phy_tx_params_t)); |
---|
808 | |
---|
809 | tx_low_event_log_entry->transmission_count = 1; |
---|
810 | tx_low_event_log_entry->chan_num = rx_frame_info->resp_low_tx_details.chan_num; |
---|
811 | tx_low_event_log_entry->length = packet_payload_size; |
---|
812 | tx_low_event_log_entry->num_slots = rx_frame_info->resp_low_tx_details.num_slots; |
---|
813 | tx_low_event_log_entry->cw = rx_frame_info->resp_low_tx_details.cw; |
---|
814 | tx_low_event_log_entry->pkt_type = MAC_FRAME_CTRL1_SUBTYPE_ACK; |
---|
815 | tx_low_event_log_entry->flags = 0; |
---|
816 | tx_low_event_log_entry->timestamp_send_frac = rx_frame_info->resp_low_tx_details.tx_start_timestamp_frac_ctrl; |
---|
817 | tx_low_event_log_entry->phy_samp_rate = rx_frame_info->phy_samp_rate; // TODO: Makes assumption that response uses same PHY BW as Rx |
---|
818 | tx_low_event_log_entry->flags = 0; |
---|
819 | } |
---|
820 | } |
---|
821 | } |
---|
822 | |
---|
823 | return rx_event_log_entry; |
---|
824 | } |
---|
825 | |
---|
826 | |
---|
827 | |
---|
828 | /*****************************************************************************/ |
---|
829 | /** |
---|
830 | * Determine RX/TX entry size |
---|
831 | * |
---|
832 | * @param rx_mpdu - Pointer to RX MPDU of the associated RX entry |
---|
833 | * @param channel_number - Indicates the channel on which the reception occurred |
---|
834 | * @param rate - Indicates the rate at which the reception occurred |
---|
835 | * |
---|
836 | * @return rx_common_entry * - Pointer to the rx_common_entry log entry |
---|
837 | * NOTE: This can be NULL if an entry was not allocated |
---|
838 | * |
---|
839 | *****************************************************************************/ |
---|
840 | void wlan_exp_log_get_txrx_entry_sizes( u32 entry_type, u16 packet_payload_size, |
---|
841 | u32* entry_size, u32* entry_payload_size, u32* min_entry_payload_size ) { |
---|
842 | u32 base_entry_size; |
---|
843 | u32 pkt_bytes_to_log; |
---|
844 | u32 log_bytes_to_log; |
---|
845 | u32 extra_entry_payload; |
---|
846 | |
---|
847 | u32 tmp_entry_size = 0; |
---|
848 | u32 tmp_entry_payload_size = 0; |
---|
849 | u32 tmp_min_entry_payload_size; |
---|
850 | |
---|
851 | // Set the base entry size based on the entry type |
---|
852 | switch (entry_type) { |
---|
853 | case ENTRY_TYPE_RX_OFDM: |
---|
854 | case ENTRY_TYPE_RX_OFDM_LTG: base_entry_size = sizeof(rx_ofdm_entry); break; |
---|
855 | |
---|
856 | case ENTRY_TYPE_RX_DSSS: base_entry_size = sizeof(rx_dsss_entry); break; |
---|
857 | |
---|
858 | case ENTRY_TYPE_TX_HIGH: |
---|
859 | case ENTRY_TYPE_TX_HIGH_LTG: base_entry_size = sizeof(tx_high_entry); break; |
---|
860 | |
---|
861 | case ENTRY_TYPE_TX_LOW: |
---|
862 | case ENTRY_TYPE_TX_LOW_LTG: base_entry_size = sizeof(tx_low_entry); break; |
---|
863 | |
---|
864 | default: base_entry_size = 0; break; |
---|
865 | } |
---|
866 | |
---|
867 | // Determine the minimum entry payload size based on entry type |
---|
868 | switch (entry_type) { |
---|
869 | // Non-LTG TX/RX Entry types |
---|
870 | case ENTRY_TYPE_RX_DSSS: |
---|
871 | case ENTRY_TYPE_RX_OFDM: |
---|
872 | case ENTRY_TYPE_TX_HIGH: |
---|
873 | case ENTRY_TYPE_TX_LOW: |
---|
874 | tmp_min_entry_payload_size = MIN_MAC_PAYLOAD_LOG_LEN; |
---|
875 | break; |
---|
876 | |
---|
877 | // LTG TX/RX Entry types |
---|
878 | case ENTRY_TYPE_RX_OFDM_LTG: |
---|
879 | case ENTRY_TYPE_TX_HIGH_LTG: |
---|
880 | case ENTRY_TYPE_TX_LOW_LTG: |
---|
881 | tmp_min_entry_payload_size = MIN_MAC_PAYLOAD_LTG_LOG_LEN; |
---|
882 | break; |
---|
883 | |
---|
884 | default: |
---|
885 | tmp_min_entry_payload_size = MIN_MAC_PAYLOAD_LOG_LEN; |
---|
886 | break; |
---|
887 | } |
---|
888 | |
---|
889 | // Determine the entry size and payload size based on the entry type |
---|
890 | switch (entry_type) { |
---|
891 | |
---|
892 | // Determine length required for RX / TX high log entry: |
---|
893 | // |
---|
894 | // - mac_payload_log_len is a global variable that determines the maximum number of payload bytes to log. This |
---|
895 | // can be changed during runtime by WLAN Exp or other C code. |
---|
896 | // - MIN_MAC_PAYLOAD_LOG_LEN and MIN_MAC_PAYLOAD_LTG_LOG_LEN define the minimum payload that should be logged |
---|
897 | // for regular and LTG packets, respectively. This value is guaranteed to be 32-bit aligned (ie a multiple |
---|
898 | // of 4 bytes). |
---|
899 | // |
---|
900 | // Procedure: |
---|
901 | // 1) Determine the number of bytes we would log from the packet, enforcing the minimum number of bytes from 1). |
---|
902 | // 2) Determine the number of bytes the infrastructure is asking us to log, enforcing the minimum number of bytes from 1). |
---|
903 | // 3) Determine the number of bytes we will actually log by taking the minimum bytes from 2) and 3) so we don't |
---|
904 | // add extra bytes to the log for no reason. |
---|
905 | // 4) Determine the number of bytes needed to be allocated for the log entry beyond the MIN_MAC_PAYLOAD_LOG_LEN which |
---|
906 | // is part of the log entry definition. |
---|
907 | // |
---|
908 | case ENTRY_TYPE_RX_DSSS: |
---|
909 | case ENTRY_TYPE_RX_OFDM: |
---|
910 | case ENTRY_TYPE_RX_OFDM_LTG: |
---|
911 | case ENTRY_TYPE_TX_HIGH: |
---|
912 | case ENTRY_TYPE_TX_HIGH_LTG: |
---|
913 | // Determine if we need to log the minimum entry payload size or the 32-bit aligned packet payload, whichever is larger |
---|
914 | pkt_bytes_to_log = WLAN_MAX(tmp_min_entry_payload_size, ((1 + ((packet_payload_size - 1U) / 4U))*4U)); |
---|
915 | |
---|
916 | // Determine if we need to log the mimimum entry payload size or the mac_payload_log_len, whichever is larger |
---|
917 | log_bytes_to_log = WLAN_MAX(tmp_min_entry_payload_size, mac_payload_log_len); |
---|
918 | |
---|
919 | // Log the minimum of either the pkt_bytes_to_log or the log_bytes_to_log |
---|
920 | tmp_entry_payload_size = WLAN_MIN( pkt_bytes_to_log, log_bytes_to_log ); |
---|
921 | |
---|
922 | // Determine the extra payload bytes needed for the entry beyond the MIN_MAC_PAYLOAD_LOG_LEN already allocated |
---|
923 | extra_entry_payload = (tmp_entry_payload_size > MIN_MAC_PAYLOAD_LOG_LEN) ? (tmp_entry_payload_size - MIN_MAC_PAYLOAD_LOG_LEN) : 0; |
---|
924 | |
---|
925 | // Then entry size is the base_entry_size plus the extra payload |
---|
926 | tmp_entry_size = base_entry_size + extra_entry_payload; |
---|
927 | break; |
---|
928 | |
---|
929 | |
---|
930 | // Determine length required for TX low log entry: |
---|
931 | // - Log the MAC header. |
---|
932 | // |
---|
933 | case ENTRY_TYPE_TX_LOW: |
---|
934 | tmp_entry_size = base_entry_size; |
---|
935 | tmp_entry_payload_size = sizeof(mac_header_80211); |
---|
936 | break; |
---|
937 | |
---|
938 | |
---|
939 | // Determine length required for TX low LTG log entry: |
---|
940 | // - Log the MAC header, LLC header, and LTG payload ID |
---|
941 | // |
---|
942 | case ENTRY_TYPE_TX_LOW_LTG: |
---|
943 | tmp_entry_size = base_entry_size + sizeof(ltg_packet_id_t); |
---|
944 | tmp_entry_payload_size = sizeof(mac_header_80211) + sizeof(ltg_packet_id_t); |
---|
945 | break; |
---|
946 | |
---|
947 | |
---|
948 | default: |
---|
949 | #if WLAN_SW_CONFIG_ENABLE_WLAN_EXP |
---|
950 | wlan_exp_printf(WLAN_EXP_PRINT_WARNING, print_type_event_log, "Unknown entry type: %d", entry_type); |
---|
951 | tmp_entry_size = 0; |
---|
952 | tmp_entry_payload_size = 0; |
---|
953 | #endif |
---|
954 | break; |
---|
955 | } |
---|
956 | |
---|
957 | // Assign output arguments |
---|
958 | *entry_size = tmp_entry_size; |
---|
959 | *entry_payload_size = tmp_entry_payload_size; |
---|
960 | *min_entry_payload_size = tmp_min_entry_payload_size; |
---|
961 | } |
---|
962 | |
---|
963 | |
---|
964 | /*****************************************************************************/ |
---|
965 | // |
---|
966 | // Functions to add fields to the log |
---|
967 | // |
---|
968 | // NOTE: These functions should not be modified unless necessary |
---|
969 | // |
---|
970 | /*****************************************************************************/ |
---|
971 | |
---|
972 | |
---|
973 | /*****************************************************************************/ |
---|
974 | /** |
---|
975 | * Add a node info entry |
---|
976 | * |
---|
977 | * @param None |
---|
978 | * |
---|
979 | * @return None |
---|
980 | * |
---|
981 | * |
---|
982 | *****************************************************************************/ |
---|
983 | void add_node_info_entry() { |
---|
984 | |
---|
985 | |
---|
986 | node_info_entry* entry; |
---|
987 | |
---|
988 | // For this entry, we do not use the wlan_exp_log_create_entry wrapper because this entry should never be |
---|
989 | // filtered due to assumptions on the log structure (ie the first entry in the log will always be a NODE_INFO |
---|
990 | // entry) |
---|
991 | // |
---|
992 | entry = (node_info_entry *)event_log_get_next_empty_entry(ENTRY_TYPE_NODE_INFO, sizeof(node_info_entry)); |
---|
993 | |
---|
994 | if (entry != NULL) { |
---|
995 | entry->timestamp = get_mac_time_usec(); |
---|
996 | entry->serial_number = wlan_mac_hw_info.serial_number; |
---|
997 | entry->platform_id = platform_common_dev_info.platform_id; |
---|
998 | |
---|
999 | entry->wlan_mac_addr = (u64)wlan_mac_hw_info.hw_addr_wlan[5] + \ |
---|
1000 | (((u64)wlan_mac_hw_info.hw_addr_wlan[4]) << 8) + \ |
---|
1001 | (((u64)wlan_mac_hw_info.hw_addr_wlan[3]) << 16) + \ |
---|
1002 | (((u64)wlan_mac_hw_info.hw_addr_wlan[2]) << 24) + \ |
---|
1003 | (((u64)wlan_mac_hw_info.hw_addr_wlan[1]) << 32) + \ |
---|
1004 | (((u64)wlan_mac_hw_info.hw_addr_wlan[0]) << 40); |
---|
1005 | |
---|
1006 | entry->wlan_max_tx_power_dbm = platform_common_dev_info.tx_power_max_dbm; |
---|
1007 | entry->wlan_min_tx_power_dbm = platform_common_dev_info.tx_power_min_dbm; |
---|
1008 | |
---|
1009 | #if WLAN_SW_CONFIG_ENABLE_WLAN_EXP |
---|
1010 | wlan_exp_node_info_t* wlan_exp_node_info = wlan_exp_get_node_info(); |
---|
1011 | |
---|
1012 | entry->high_sw_id = wlan_exp_node_info->high_sw_id; |
---|
1013 | entry->high_sw_config = wlan_exp_node_info->high_sw_config; |
---|
1014 | entry->low_sw_id = wlan_exp_node_info->low_sw_id; |
---|
1015 | entry->low_sw_config = wlan_exp_node_info->low_sw_config; |
---|
1016 | entry->node_id = wlan_exp_node_info->node_id; |
---|
1017 | entry->wlan_exp_version = wlan_exp_node_info->wlan_exp_version; |
---|
1018 | |
---|
1019 | //FIXME: these shouldn't be wlan_exp specific, but at the moment the only struct that actually |
---|
1020 | // stores these details is wlan_exp's node_info |
---|
1021 | memcpy(entry->high_compilation_date, wlan_exp_node_info->high_compilation_date, sizeof(wlan_exp_node_info->high_compilation_date)); |
---|
1022 | memcpy(entry->high_compilation_time, wlan_exp_node_info->high_compilation_time, sizeof(wlan_exp_node_info->high_compilation_time)); |
---|
1023 | memcpy(entry->low_compilation_date, wlan_exp_node_info->low_compilation_date, sizeof(wlan_exp_node_info->low_compilation_date)); |
---|
1024 | memcpy(entry->low_compilation_time, wlan_exp_node_info->low_compilation_time, sizeof(wlan_exp_node_info->low_compilation_time)); |
---|
1025 | |
---|
1026 | #endif //WLAN_SW_CONFIG_ENABLE_WLAN_EXP |
---|
1027 | } |
---|
1028 | } |
---|
1029 | |
---|
1030 | |
---|
1031 | |
---|
1032 | /*****************************************************************************/ |
---|
1033 | /** |
---|
1034 | * Add a Time Info log entry to the log |
---|
1035 | * |
---|
1036 | * @param timestamp - Timestamp to use for the log entry (MAC time old timebase) |
---|
1037 | * @param mac_time - MAC time (new timebase) |
---|
1038 | * @param system_time - System time |
---|
1039 | * @param host_time - Host time |
---|
1040 | * @param reason - Reason the time info entry was created |
---|
1041 | * @param time_id - ID to use for the time info entry |
---|
1042 | * @param use_time_id - Use the provided time_id or system_time_id |
---|
1043 | * 0 = Use system_time_id |
---|
1044 | * 1 = Use provided time_id |
---|
1045 | * |
---|
1046 | * @return time_info_entry * - Pointer to the time_info_entry log entry |
---|
1047 | * NOTE: This can be NULL if an entry was not allocated |
---|
1048 | * |
---|
1049 | *****************************************************************************/ |
---|
1050 | void add_time_info_entry(u64 timestamp, u64 mac_time, u64 system_time, u64 host_time, u32 reason, u32 time_id, u8 use_time_id) { |
---|
1051 | |
---|
1052 | time_info_entry* time_entry; |
---|
1053 | |
---|
1054 | // Create a time info log entry |
---|
1055 | time_entry = (time_info_entry *) wlan_exp_log_create_entry(ENTRY_TYPE_TIME_INFO, sizeof(time_info_entry)); |
---|
1056 | |
---|
1057 | if (time_entry != NULL) { |
---|
1058 | time_entry->timestamp = timestamp; |
---|
1059 | |
---|
1060 | if (use_time_id) { |
---|
1061 | time_entry->time_id = time_id; |
---|
1062 | } else { |
---|
1063 | time_entry->time_id = system_time_id; |
---|
1064 | system_time_id++; |
---|
1065 | } |
---|
1066 | |
---|
1067 | time_entry->reason = reason; |
---|
1068 | time_entry->mac_timestamp = mac_time; |
---|
1069 | time_entry->system_timestamp = system_time; |
---|
1070 | time_entry->host_timestamp = host_time; |
---|
1071 | } |
---|
1072 | } |
---|
1073 | |
---|
1074 | |
---|
1075 | |
---|
1076 | /*****************************************************************************/ |
---|
1077 | /** |
---|
1078 | * Add the temperature to the log |
---|
1079 | * |
---|
1080 | * @param None |
---|
1081 | * |
---|
1082 | * @return u32 - Status of the command: |
---|
1083 | * WLAN_SUCCESS - Command completed successfully |
---|
1084 | * WLAN_FAILURE - There was an error in the command |
---|
1085 | * |
---|
1086 | * |
---|
1087 | *****************************************************************************/ |
---|
1088 | u32 add_temperature_to_log() { |
---|
1089 | |
---|
1090 | temperature_entry* entry; |
---|
1091 | u32 entry_size = sizeof(temperature_entry); |
---|
1092 | // wlan_mac_hw_info_t * hw_info; |
---|
1093 | |
---|
1094 | // hw_info = get_mac_hw_info(); |
---|
1095 | |
---|
1096 | entry = (temperature_entry *)wlan_exp_log_create_entry(ENTRY_TYPE_TEMPERATURE, entry_size); |
---|
1097 | |
---|
1098 | if (entry != NULL) { |
---|
1099 | entry->timestamp = get_mac_time_usec(); |
---|
1100 | entry->curr_temp = wlan_platform_get_current_temp(); |
---|
1101 | entry->min_temp = wlan_platform_get_min_temp(); |
---|
1102 | entry->max_temp = wlan_platform_get_max_temp(); |
---|
1103 | |
---|
1104 | return WLAN_SUCCESS; |
---|
1105 | } |
---|
1106 | |
---|
1107 | return WLAN_FAILURE; |
---|
1108 | |
---|
1109 | |
---|
1110 | } |
---|
1111 | #endif //WLAN_SW_CONFIG_ENABLE_LOGGING |
---|