#ifndef WLAN_COMMON_TYPES_H_ #define WLAN_COMMON_TYPES_H_ #include "xil_types.h" #include "xil_io.h" #include "stddef.h" #define WLAN_SUCCESS 0 #define WLAN_FAILURE -1 // Define a compile-time macros that act like assert // We use these primarily to check that struct sizes match corresponding sizes expected by wlan_exp // This check catches cases where unexpected packing/padding change alignment of struct fields // Inspired by https://stackoverflow.com/a/809465 #define CASSERT(test_cond, failure_msg) \ typedef char CASSERT_FAILED_##failure_msg[2*!!(test_cond)-1]; #define ASSERT_TYPE_SIZE(check_type, req_size) \ typedef char ASSERT_TYPE_SIZE_FAILED_##check_type##_neq_##req_size[2*!!(req_size == sizeof(check_type))-1] #define ASSERT_FIELD_ALIGNMENT(type, field, alignment) \ typedef char ASSERT_FIELD_ALIGNMENT_FAILED_##type##_##member##_neq_##alignment[2*!!((offsetof(type,field) % alignment) == 0)-1] #define ASSERT_FIELD_OVERLAP_ALIGNMENT(type1, field1, type2, field2) \ CASSERT(offsetof(type1,field1)==offsetof(type2,field2),OVERLAP_ALIGNMENT_ERROR); #define ASSERT_FIELD_END_ALIGNMENT(type, field, size) \ CASSERT((offsetof(type,field)+size) == sizeof(type), END_ALIGNMENT_ERROR); #define ASSERT_U32_ALIGNED(type) \ CASSERT((sizeof(type) & 0x3) == 0, U32_ALIGNMENT_ERROR); //----------------------------------------------- // Compilation Details // typedef struct { char compilation_date[12]; // Must be at least 12 bytes. char compilation_time[12]; // Must be at least 9 bytes. Unfortunately, wlan_exp places an additional requirement that each field in // wlan_exp_node_info_t must be u32 aligned, so we increase the size to 12 bytes. } __attribute__((__packed__)) compilation_details_t; ASSERT_TYPE_SIZE(compilation_details_t, 24); // This type is sent as an IPC payload, which deals with u32 words ASSERT_U32_ALIGNED(compilation_details_t); //----------------------------------------------- // Generic function pointer // typedef int (*function_ptr_t)(); //----------------------------------------------- // Interrupt Connection Parameters // typedef struct intr_conn_params_t { function_ptr_t intr_handler0; void* intr_handler_arg0; function_ptr_t intr_handler1; void* intr_handler_arg1; } intr_conn_params_t ; typedef struct peripheral_args_t { void* driver_instance; function_ptr_t callback0; function_ptr_t callback1; } peripheral_args_t; //----------------------------------------------- // Field size defines // #define MAC_ADDR_LEN 6 ///< MAC Address Length (in bytes) #define IP_ADDR_LEN 4 ///< Length of IP address (in bytes) #define SSID_LEN_MAX 32 ///< Maximum SSID length #define MAX_PKT_SIZE_KB 2 #define MAX_PKT_SIZE_B (MAX_PKT_SIZE_KB << 10) // Helper macro to swap byte order for 64-bit values // Xil_ header only provides 16-bit and 32-bit macros #define wlan_htonll(x) ((((u64)Xil_Htonl(x)) << 32) + Xil_Htonl((x) >> 32)) //----------------------------------------------- // TX parameters // - Be careful when modifying these structures, there are alignment concerns // for many of the structures that contain these structures. In general, // tx_params_t should be 8-byte aligned. // // phy_tx_params_t is also used as a field in Tx log entries, so the struct // must be packed to match the log entry definition in Python typedef struct phy_tx_params_t{ u8 mcs; ///< MCS index u8 phy_mode; ///< PHY mode selection and flags u8 antenna_mode; ///< Tx antenna selection s8 power; ///< Tx power (in dBm) } __attribute__((__packed__)) phy_tx_params_t; ASSERT_TYPE_SIZE(phy_tx_params_t, 4); typedef struct mac_tx_params_t{ u8 flags; ///< Flags affecting waveform construction u8 reserved[3]; ///< Reserved for 32-bit alignment } mac_tx_params_t; typedef struct tx_params_t{ phy_tx_params_t phy; ///< PHY Tx params mac_tx_params_t mac; ///< Lower-level MAC Tx params } tx_params_t; //----------------------------------------------- // TX queue information // - Information about the TX queue that contained the packet while in CPU High. // - This structure must be 32-bit aligned. // typedef enum __attribute__ ((__packed__)){ PKT_BUF_GROUP_GENERAL = 0, PKT_BUF_GROUP_DTIM_MCAST = 1, PKT_BUF_GROUP_OTHER = 0xFF, } pkt_buf_group_t; ASSERT_TYPE_SIZE(pkt_buf_group_t, 1); typedef struct __attribute__ ((__packed__)) tx_queue_details_t{ u64 enqueue_timestamp; u8 id; ///< ID of the Queue pkt_buf_group_t pkt_buf_group; ///< Packet Buffer Group u16 occupancy; ///< Number of elements in the queue when the packet was enqueued (including itself) } tx_queue_details_t; ASSERT_TYPE_SIZE(tx_queue_details_t, 12); //----------------------------------------------- // LLC Header // typedef struct llc_header_t{ u8 dsap; u8 ssap; u8 control_field; u8 org_code[3]; u16 type; } llc_header_t; //----------------------------------------------- // LTG Payload Contents // typedef struct ltg_packet_id_t{ llc_header_t llc_hdr; u64 unique_seq; u32 ltg_id; } ltg_packet_id_t; //----------------------------------------------- // Doubly-Linked List // typedef struct dl_entry dl_entry; struct dl_entry{ dl_entry* next; dl_entry* prev; void* data; }; //Forward declaration of dl_entry typedef struct dl_list{ dl_entry* first; dl_entry* last; u32 length; } dl_list; //----------------------------------------------- // PHY Bandwidth Configuration // typedef enum phy_samp_rate_t{ PHY_10M = 10, PHY_20M = 20, PHY_40M = 40 } phy_samp_rate_t; #endif /* WLAN_COMMON_TYPES_H_ */