handling low level eth function for read
This commit is contained in:
@@ -52,6 +52,7 @@
|
||||
#include "common_lib.h"
|
||||
#include "ethernet_lib.h"
|
||||
#include "if_defs.h"
|
||||
#include "openair1/PHY/LTE_TRANSPORT/if4_tools.h"
|
||||
|
||||
#define DEBUG 0
|
||||
|
||||
@@ -214,7 +215,7 @@ int trx_eth_write_raw_IF4(openair0_device *device, openair0_timestamp timestamp,
|
||||
} else if (flags == IF4_PULFFT) {
|
||||
packet_size = RAW_IF4_PULFFT_SIZE_BYTES(nblocks);
|
||||
} else {
|
||||
packet_size = RAW_IF4_PRACH_SIZE_BYTES(nblocks);
|
||||
packet_size = RAW_IF4_PRACH_SIZE_BYTES;
|
||||
}
|
||||
|
||||
eth->tx_nsamps = nblocks;
|
||||
@@ -302,49 +303,66 @@ int trx_eth_read_raw(openair0_device *device, openair0_timestamp *timestamp, voi
|
||||
|
||||
int trx_eth_read_raw_IF4(openair0_device *device, openair0_timestamp *timestamp, void **buff, int nsamps, int cc) {
|
||||
|
||||
int nblocks = nsamps;
|
||||
int bytes_received=0;
|
||||
int i=0;
|
||||
eth_state_t *eth = (eth_state_t*)device->priv;
|
||||
int Mod_id = device->Mod_id;
|
||||
int rcvfrom_flag =0;
|
||||
|
||||
eth->rx_nsamps=nsamps;
|
||||
|
||||
/* buff[i] points to the position in rx buffer where the payload to be received will be placed
|
||||
buff2 points to the position in rx buffer where the packet header will be placed */
|
||||
void *buff2 = (void*)(buff[i]-APP_HEADER_SIZE_BYTES-MAC_HEADER_SIZE_BYTES);
|
||||
|
||||
/* we don't want to ovewrite with the header info the previous rx buffer data so we store it*/
|
||||
struct ether_header temp = *(struct ether_header *)buff2;
|
||||
int32_t temp0 = *(int32_t *)(buff2 + MAC_HEADER_SIZE_BYTES);
|
||||
openair0_timestamp temp1 = *(openair0_timestamp *)(buff2 + MAC_HEADER_SIZE_BYTES + sizeof(int32_t));
|
||||
|
||||
bytes_received=0;
|
||||
|
||||
while(bytes_received < RAW_PACKET_SIZE_BYTES(nsamps)) {
|
||||
bytes_received +=recv(eth->sockfd[Mod_id],
|
||||
buff2,
|
||||
RAW_PACKET_SIZE_BYTES(nsamps),
|
||||
rcvfrom_flag);
|
||||
|
||||
ssize_t packet_size = MAC_HEADER_SIZE_BYTES + sizeof_IF4_dl_header_t;
|
||||
|
||||
void *test_buffer = (void*)malloc(packet_size);
|
||||
void *rx_buffer=NULL;
|
||||
IF4_dl_header_t *test_header = (IF4_dl_header_t*)(test_buffer + MAC_HEADER_SIZE_BYTES);
|
||||
|
||||
bytes_received = recv(eth->sockfd[Mod_id],
|
||||
test_buffer,
|
||||
packet_size,
|
||||
0);
|
||||
if (bytes_received ==-1) {
|
||||
eth->num_rx_errors++;
|
||||
perror("ETHERNET READ: ");
|
||||
exit(-1);
|
||||
} else {
|
||||
/* store the timestamp value from packet's header */
|
||||
*timestamp = *(openair0_timestamp *)(buff2 + MAC_HEADER_SIZE_BYTES + sizeof(int32_t));
|
||||
eth->rx_actual_nsamps=bytes_received>>2;
|
||||
eth->rx_count++;
|
||||
}
|
||||
}
|
||||
|
||||
/* tx buffer values restored */
|
||||
*(struct ether_header *)buff2 = temp;
|
||||
*(int32_t *)(buff2 + MAC_HEADER_SIZE_BYTES) = temp0;
|
||||
*(openair0_timestamp *)(buff2 + MAC_HEADER_SIZE_BYTES + sizeof(int32_t)) = temp1;
|
||||
}
|
||||
|
||||
*timestamp = test_header->sub_type;
|
||||
|
||||
if (test_header->sub_type == IF4_PDLFFT) {
|
||||
buff[0] = (void*)malloc(RAW_IF4_PDLFFT_SIZE_BYTES(nblocks) - MAC_HEADER_SIZE_BYTES);
|
||||
packet_size = RAW_IF4_PDLFFT_SIZE_BYTES(nblocks) - packet_size;
|
||||
|
||||
} else if (test_header->sub_type == IF4_PULFFT) {
|
||||
buff[0] = (void*)malloc(RAW_IF4_PULFFT_SIZE_BYTES(nblocks) - MAC_HEADER_SIZE_BYTES);
|
||||
packet_size = RAW_IF4_PULFFT_SIZE_BYTES(nblocks) - packet_size;
|
||||
|
||||
} else {
|
||||
buff[0] = (void*)malloc(RAW_IF4_PRACH_SIZE_BYTES - MAC_HEADER_SIZE_BYTES);
|
||||
packet_size = RAW_IF4_PRACH_SIZE_BYTES - packet_size;
|
||||
}
|
||||
|
||||
return (bytes_received-APP_HEADER_SIZE_BYTES-MAC_HEADER_SIZE_BYTES)>>2;
|
||||
memcpy(buff[0], test_header, sizeof_IF4_dl_header_t);
|
||||
rx_buffer = (void*)(buff[0]+sizeof_IF4_dl_header_t);
|
||||
|
||||
bytes_received = 0;
|
||||
|
||||
while(bytes_received < packet_size) {
|
||||
bytes_received += recv(eth->sockfd[Mod_id],
|
||||
rx_buffer,
|
||||
packet_size-bytes_received,
|
||||
0);
|
||||
if (bytes_received ==-1) {
|
||||
eth->num_rx_errors++;
|
||||
perror("ETHERNET READ: ");
|
||||
exit(-1);
|
||||
} else {
|
||||
eth->rx_actual_nsamps = bytes_received>>1;
|
||||
eth->rx_count++;
|
||||
}
|
||||
}
|
||||
|
||||
eth->rx_nsamps = nsamps;
|
||||
|
||||
free(test_buffer);
|
||||
return (bytes_received-MAC_HEADER_SIZE_BYTES)>>1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -320,7 +320,8 @@ int transport_init(openair0_device *device, openair0_config_t *openair0_cfg, eth
|
||||
} else if (eth_params->transp_preference == 2) {
|
||||
eth->flags = ETH_UDP_IF4_MODE;
|
||||
} else {
|
||||
AssertFatal(0==4, "transport_init: Unknown transport preference %d", eth_params->transp_preference);
|
||||
printf("transport_init: Unknown transport preference %d - default to RAW", eth_params->transp_preference);
|
||||
eth->flags = ETH_RAW_MODE;
|
||||
}
|
||||
|
||||
printf("[ETHERNET]: Initializing openair0_device for %s ...\n", ((device->host_type == BBU_HOST) ? "BBU": "RRH"));
|
||||
@@ -346,16 +347,16 @@ int transport_init(openair0_device *device, openair0_config_t *openair0_cfg, eth
|
||||
device->trx_write_func = trx_eth_write_raw_IF4;
|
||||
device->trx_read_func = trx_eth_read_raw_IF4;
|
||||
} else {
|
||||
device->trx_write_func = trx_eth_write_udp_IF4;
|
||||
device->trx_read_func = trx_eth_read_udp_IF4;
|
||||
//device->trx_write_func = trx_eth_write_udp_IF4;
|
||||
//device->trx_read_func = trx_eth_read_udp_IF4;
|
||||
}
|
||||
|
||||
eth->if_name[device->Mod_id] = eth_params->local_if_name;
|
||||
device->priv = eth;
|
||||
|
||||
/* device specific */
|
||||
openair0_cfg[0].txlaunch_wait = 0;//manage when TX processing is triggered
|
||||
openair0_cfg[0].txlaunch_wait_slotcount = 0; //manage when TX processing is triggered
|
||||
//openair0_cfg[0].txlaunch_wait = 0;//manage when TX processing is triggered
|
||||
//openair0_cfg[0].txlaunch_wait_slotcount = 0; //manage when TX processing is triggered
|
||||
openair0_cfg[0].iq_rxrescale = 15;//rescale iqs
|
||||
openair0_cfg[0].iq_txshift = eth_params->iq_txshift;// shift
|
||||
openair0_cfg[0].tx_sample_advance = eth_params->tx_sample_advance;
|
||||
|
||||
@@ -222,8 +222,8 @@ int eth_set_dev_conf_udp(openair0_device *device);
|
||||
int eth_socket_init_raw(openair0_device *device);
|
||||
int trx_eth_write_raw(openair0_device *device, openair0_timestamp timestamp, void **buff, int nsamps,int cc, int flags);
|
||||
int trx_eth_read_raw(openair0_device *device, openair0_timestamp *timestamp, void **buff, int nsamps, int cc);
|
||||
//int trx_eth_write_raw_IF4(openair0_device *device, openair0_timestamp timestamp, void **buff, int nsamps,int cc, int flags);
|
||||
//int trx_eth_read_raw_IF4(openair0_device *device, openair0_timestamp *timestamp, void **buff, int nsamps, int cc);
|
||||
int trx_eth_write_raw_IF4(openair0_device *device, openair0_timestamp timestamp, void **buff, int nsamps,int cc, int flags);
|
||||
int trx_eth_read_raw_IF4(openair0_device *device, openair0_timestamp *timestamp, void **buff, int nsamps, int cc);
|
||||
int eth_get_dev_conf_raw(openair0_device *device);
|
||||
int eth_set_dev_conf_raw(openair0_device *device);
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@
|
||||
*/
|
||||
|
||||
#include <netinet/ether.h>
|
||||
#include <stdint.h>
|
||||
|
||||
// ETH transport preference modes
|
||||
#define ETH_UDP_MODE 0
|
||||
@@ -54,7 +55,9 @@
|
||||
#define RAW_PACKET_SIZE_BYTES(nsamps) (APP_HEADER_SIZE_BYTES + MAC_HEADER_SIZE_BYTES + PAYLOAD_SIZE_BYTES(nsamps))
|
||||
|
||||
// Packet sizes for IF4 interface format
|
||||
#define DATA_BLOCK_SIZE_BYTES(scaled_nblocks) (2*scaled_nblocks)
|
||||
#define DATA_BLOCK_SIZE_BYTES(scaled_nblocks) (sizeof(int16_t)*scaled_nblocks)
|
||||
#define PRACH_BLOCK_SIZE_BYTES (sizeof(int16_t)*839) // FIX hard coded prach size
|
||||
|
||||
#define RAW_IF4_PDLFFT_SIZE_BYTES(nblocks) (MAC_HEADER_SIZE_BYTES + sizeof_IF4_dl_header_t + DATA_BLOCK_SIZE_BYTES(nblocks))
|
||||
#define RAW_IF4_PULFFT_SIZE_BYTES(nblocks) (MAC_HEADER_SIZE_BYTES + sizeof_IF4_ul_header_t + DATA_BLOCK_SIZE_BYTES(nblocks))
|
||||
#define RAW_IF4_PRACH_SIZE_BYTES(nblocks) (MAC_HEADER_SIZE_BYTES + sizeof_IF4_prach_header_t + DATA_BLOCK_SIZE_BYTES(nblocks))
|
||||
#define RAW_IF4_PRACH_SIZE_BYTES (MAC_HEADER_SIZE_BYTES + sizeof_IF4_prach_header_t + PRACH_BLOCK_SIZE_BYTES)
|
||||
|
||||
Reference in New Issue
Block a user