[4284] | 1 | /** @file wl_transport.h |
---|
| 2 | * @brief WARPLab Framework (Transport) |
---|
| 3 | * |
---|
| 4 | * This contains the code for WARPLab Framework. |
---|
| 5 | * |
---|
| 6 | * @copyright Copyright 2013, Mango Communications. All rights reserved. |
---|
| 7 | * Distributed under the WARP license (http://warpproject.org/license) |
---|
| 8 | * |
---|
| 9 | * @author Chris Hunter (chunter [at] mangocomm.com) |
---|
| 10 | * @author Patrick Murphy (murphpo [at] mangocomm.com) |
---|
| 11 | * @author Erik Welsh (welsh [at] mangocomm.com) |
---|
| 12 | */ |
---|
[1995] | 13 | |
---|
[4453] | 14 | /**********************************************************************************************************************/ |
---|
| 15 | /** |
---|
| 16 | * @brief Common Functions (WARP v2 and WARP v3) |
---|
| 17 | * |
---|
| 18 | **********************************************************************************************************************/ |
---|
| 19 | |
---|
[4284] | 20 | /***************************** Include Files *********************************/ |
---|
[2054] | 21 | |
---|
[4284] | 22 | // WARPLab includes |
---|
[1915] | 23 | #include "wl_common.h" |
---|
[4284] | 24 | |
---|
[1915] | 25 | |
---|
[4514] | 26 | // WARP UDP transport includes |
---|
| 27 | #include <WARP_ip_udp.h> |
---|
| 28 | #include <WARP_ip_udp_device.h> |
---|
[2054] | 29 | |
---|
[4514] | 30 | |
---|
[2054] | 31 | /*************************** Constant Definitions ****************************/ |
---|
[1915] | 32 | #ifndef WL_TRANSPORT_H_ |
---|
| 33 | #define WL_TRANSPORT_H_ |
---|
| 34 | |
---|
[4284] | 35 | // ********************************************************************** |
---|
| 36 | // Command IDs (must match the CMD_ properties in wl_transport_*.m) |
---|
| 37 | // |
---|
[4783] | 38 | #define CMDID_TRANSPORT_PING 0x000001 |
---|
| 39 | #define CMDID_TRANSPORT_PAYLOAD_SIZE_TEST 0x000002 |
---|
[2054] | 40 | |
---|
[4783] | 41 | #define CMDID_TRANSPORT_NODE_GROUP_ID_ADD 0x000010 |
---|
| 42 | #define CMDID_TRANSPORT_NODE_GROUP_ID_CLEAR 0x000011 |
---|
[1949] | 43 | |
---|
[4783] | 44 | |
---|
[4284] | 45 | // *********************************************************************** |
---|
| 46 | // Define WARPLab Transport Ethernet Information |
---|
| 47 | // |
---|
[4514] | 48 | #define WL_NUM_ETH_DEVICES WARP_IP_UDP_NUM_ETH_DEVICES |
---|
| 49 | #define WL_ETH_DEV_INITIALIZED 1 |
---|
[1949] | 50 | |
---|
[4514] | 51 | #define WL_IP_UDP_TRANSPORT 1 |
---|
[1915] | 52 | |
---|
[2019] | 53 | |
---|
[4417] | 54 | // Ethernet constants |
---|
| 55 | #define ETH_DO_NOT_WAIT_FOR_AUTO_NEGOTIATION 0 |
---|
| 56 | #define ETH_WAIT_FOR_AUTO_NEGOTIATION 1 |
---|
| 57 | |
---|
[4284] | 58 | // WARPLab message types |
---|
| 59 | #define PKTTYPE_TRIGGER 0 |
---|
| 60 | #define PKTTYPE_HTON_MSG 1 |
---|
| 61 | #define PKTTYPE_NTOH_MSG 2 |
---|
[1915] | 62 | |
---|
[4284] | 63 | // Transport status types |
---|
| 64 | #define LINK_READY 0 |
---|
| 65 | #define LINK_NOT_READY -1 |
---|
[1915] | 66 | |
---|
[4284] | 67 | // Transport header flags (16 bits) |
---|
| 68 | #define TRANSPORT_HDR_ROBUST_FLAG 0x0001 |
---|
| 69 | #define TRANSPORT_HDR_NODE_NOT_READY_FLAG 0x8000 |
---|
[1915] | 70 | |
---|
[2054] | 71 | |
---|
| 72 | /*********************** Global Structure Definitions ************************/ |
---|
| 73 | |
---|
[4284] | 74 | // WARPLab Transport header |
---|
[4514] | 75 | // NOTE: This conforms to the WARPLab Transport Header Wire Format: |
---|
| 76 | // http://warpproject.org/trac/wiki/WARPLab/Reference/Architecture/WireFormat |
---|
| 77 | // |
---|
[1915] | 78 | typedef struct { |
---|
[4453] | 79 | u16 dest_id; |
---|
| 80 | u16 src_id; |
---|
[4284] | 81 | u8 reserved; |
---|
[4453] | 82 | u8 pkt_type; |
---|
[4284] | 83 | u16 length; |
---|
[4453] | 84 | u16 seq_num; |
---|
[4284] | 85 | u16 flags; |
---|
[1915] | 86 | } wl_transport_header; |
---|
| 87 | |
---|
| 88 | |
---|
[4514] | 89 | // WARPLab Ethernet device information |
---|
| 90 | // NOTE: This is so that differences between different Ethernet devices can be consolidated |
---|
| 91 | // |
---|
| 92 | typedef struct { |
---|
| 93 | u32 initialized; // Etherent device initialized |
---|
| 94 | u32 default_speed; // Default Ethernet speed |
---|
| 95 | u32 phy_addr; // Address of the Ethernt PHY |
---|
[2054] | 96 | |
---|
[4514] | 97 | u32 type; // Transport Type |
---|
| 98 | u32 hw_addr[2]; // HW Address (big endian as 2 u32 values with 16 bit padding) |
---|
| 99 | u32 ip_addr; // IP Address (big endian) |
---|
| 100 | int unicast_socket; // Unicast socket index |
---|
| 101 | int broadcast_socket; // Broadcast socket index |
---|
| 102 | u32 group_id; // Group ID |
---|
| 103 | } wl_eth_dev_info; |
---|
[2057] | 104 | |
---|
[4284] | 105 | |
---|
| 106 | |
---|
[2054] | 107 | /*************************** Function Prototypes *****************************/ |
---|
| 108 | |
---|
[4514] | 109 | int transport_init(u32 eth_dev_num, u8 init_driver); |
---|
[2054] | 110 | |
---|
[4514] | 111 | int transport_set_process_hton_msg_callback(void(*handler)); |
---|
| 112 | int transport_process_cmd(int socket_index, void * from, wl_cmd_resp * command, wl_cmd_resp * response); |
---|
[2054] | 113 | |
---|
[4284] | 114 | void transport_poll(u32 eth_dev_num); |
---|
[4514] | 115 | void transport_send(int socket_index, struct sockaddr * to, warp_ip_udp_buffer ** buffers, u32 num_buffers); |
---|
[4284] | 116 | void transport_close(u32 eth_dev_num); |
---|
| 117 | |
---|
| 118 | int transport_get_hw_info(u32 eth_dev_num, u8 * ip_addr, u8 * hw_addr); |
---|
[4292] | 119 | int transport_config_sockets(u32 eth_dev_num, u32 unicast_port, u32 bcast_port); |
---|
[4514] | 120 | int transport_config_socket(u32 eth_dev_num, int * socket_index, u32 udp_port); |
---|
[4284] | 121 | |
---|
| 122 | int transport_link_status(u32 eth_dev_num); |
---|
[4417] | 123 | u32 transport_update_link_speed(u32 eth_dev_num, u32 wait_for_negotiation); |
---|
| 124 | u16 transport_get_ethernet_status(u32 eth_dev_num); |
---|
[4284] | 125 | |
---|
[4453] | 126 | |
---|
| 127 | |
---|
| 128 | |
---|
| 129 | |
---|
| 130 | /**********************************************************************************************************************/ |
---|
| 131 | /** |
---|
| 132 | * @brief WARP v3 Specific Functions |
---|
| 133 | * |
---|
| 134 | **********************************************************************************************************************/ |
---|
| 135 | |
---|
| 136 | #ifdef WARP_HW_VER_v3 |
---|
| 137 | |
---|
| 138 | /***************************** Include Files *********************************/ |
---|
| 139 | |
---|
| 140 | |
---|
| 141 | /*************************** Constant Definitions ****************************/ |
---|
| 142 | |
---|
[4514] | 143 | // Ethernet A constants |
---|
[4453] | 144 | #define WL_ETH_A ETH_A_MAC |
---|
| 145 | #define WL_ETH_A_MDIO_PHYADDR 0x6 |
---|
| 146 | |
---|
[4514] | 147 | // Ethernt B constants |
---|
[4453] | 148 | #define WL_ETH_B ETH_B_MAC |
---|
| 149 | #define WL_ETH_B_MDIO_PHYADDR 0x7 |
---|
| 150 | |
---|
[4514] | 151 | // Ethernet PHY constants |
---|
[4673] | 152 | #define ETH_PHY_CONTROL_REG 0 |
---|
[4514] | 153 | #define ETH_PHY_STATUS_REG 17 |
---|
[4453] | 154 | |
---|
[4673] | 155 | #define ETH_PHY_REG_0_RESET 0x8000 |
---|
| 156 | #define ETH_PHY_REG_0_SPEED_LSB 0x2000 |
---|
| 157 | #define ETH_PHY_REG_0_AUTO_NEGOTIATION 0x1000 |
---|
| 158 | #define ETH_PHY_REG_0_SPEED_MSB 0x0040 |
---|
| 159 | |
---|
[4514] | 160 | #define ETH_PHY_REG_17_0_SPEED 0xC000 |
---|
| 161 | #define ETH_PHY_REG_17_0_SPEED_RESOLVED 0x0800 |
---|
| 162 | #define ETH_PHY_REG_17_0_LINKUP 0x0400 |
---|
[4453] | 163 | |
---|
| 164 | |
---|
[4514] | 165 | // NOTE: These constants are for in place computation based on ETH_PHY_REG_17_0_SPEED (ie no bit shifting required) |
---|
| 166 | #define ETH_PHY_REG_17_0_SPEED_10_MBPS 0x0000 |
---|
| 167 | #define ETH_PHY_REG_17_0_SPEED_100_MBPS 0x4000 |
---|
| 168 | #define ETH_PHY_REG_17_0_SPEED_1000_MBPS 0x8000 |
---|
| 169 | #define ETH_PHY_REG_17_0_SPEED_RSVD 0xC000 |
---|
[4453] | 170 | |
---|
| 171 | |
---|
[4514] | 172 | // Ethernet PHY macros |
---|
| 173 | // NOTE: Speed is defined by the Ethernet hardware (xaxiethernet_hw.h and equivalent for WARP v2): |
---|
| 174 | // #define XAE_SPEED_10_MBPS 10 /**< Speed of 10 Mbps */ |
---|
| 175 | // #define XAE_SPEED_100_MBPS 100 /**< Speed of 100 Mbps */ |
---|
| 176 | // #define XAE_SPEED_1000_MBPS 1000 /**< Speed of 1000 Mbps */ |
---|
| 177 | // |
---|
[4673] | 178 | #define ETH_PHY_SPEED_10_MBPS 10 |
---|
| 179 | #define ETH_PHY_SPEED_100_MBPS 100 |
---|
| 180 | #define ETH_PHY_SPEED_1000_MBPS 1000 |
---|
[4453] | 181 | |
---|
[4673] | 182 | #define ETH_PHY_SPEED_TO_MBPS(speed) ((speed == ETH_PHY_REG_17_0_SPEED_1000_MBPS) ? ETH_PHY_SPEED_1000_MBPS : \ |
---|
| 183 | (speed == ETH_PHY_REG_17_0_SPEED_100_MBPS) ? ETH_PHY_SPEED_100_MBPS : \ |
---|
| 184 | (speed == ETH_PHY_REG_17_0_SPEED_10_MBPS) ? ETH_PHY_SPEED_10_MBPS : 0 ) |
---|
[4453] | 185 | |
---|
| 186 | |
---|
[4673] | 187 | |
---|
[4453] | 188 | /*********************** Global Structure Definitions ************************/ |
---|
| 189 | |
---|
| 190 | |
---|
| 191 | /******************************** Functions **********************************/ |
---|
| 192 | |
---|
| 193 | #endif |
---|
| 194 | |
---|
[1915] | 195 | #endif /* WL_TRANSPORT_H_ */ |
---|