first time UE connection established

This commit is contained in:
Raymond Knopp
2017-04-25 11:50:15 -07:00
parent ca2c8357c9
commit 63a18b8193
39 changed files with 1267 additions and 1593 deletions
+97 -103
View File
@@ -64,11 +64,11 @@ int eth_socket_init_raw(openair0_device *device) {
local_mac = device->eth_params->my_addr;
remote_mac = malloc(ETH_ALEN);
memset((void*)remote_mac,0,ETH_ALEN);
printf("[%s] local MAC addr %s remote MAC addr %s\n","RRU", local_mac,remote_mac);
printf("[%s] local MAC addr (user) %s remote MAC addr (user) %s\n","RRU", local_mac,remote_mac);
} else {
local_mac = device->eth_params->my_addr;
remote_mac = device->eth_params->remote_addr;
printf("[%s] local MAC addr %s remote MAC addr %s\n","RAU", local_mac,remote_mac);
printf("[%s] local MAC addr (user) %s remote MAC addr (user) %s\n","RAU", local_mac,remote_mac);
}
@@ -76,46 +76,64 @@ int eth_socket_init_raw(openair0_device *device) {
sock_dom=AF_PACKET;
sock_type=SOCK_RAW;
sock_proto=IPPROTO_RAW;
if ((eth->sockfd = socket(sock_dom, sock_type, sock_proto)) == -1) {
perror("ETHERNET: Error opening RAW socket");
if ((eth->sockfdc = socket(sock_dom, sock_type, sock_proto)) == -1) {
perror("ETHERNET: Error opening RAW socket (control)");
exit(0);
}
if ((eth->sockfdd = socket(sock_dom, sock_type, sock_proto)) == -1) {
perror("ETHERNET: Error opening RAW socket (user)");
exit(0);
}
/* initialize destination address */
bzero((void *)&(eth->local_addr_ll), sizeof(struct sockaddr_ll));
bzero((void *)&(eth->local_addrc_ll), sizeof(struct sockaddr_ll));
bzero((void *)&(eth->local_addrd_ll), sizeof(struct sockaddr_ll));
bzero((void *)&(eth->if_index), sizeof(struct ifreq));
/* Get the index of the interface to send on */
strcpy(eth->if_index.ifr_name,eth->if_name);
if (ioctl(eth->sockfd, SIOCGIFINDEX, &(eth->if_index)) < 0)
if (ioctl(eth->sockfdc, SIOCGIFINDEX, &(eth->if_index)) < 0)
perror("SIOCGIFINDEX");
if (ioctl(eth->sockfdd, SIOCGIFINDEX, &(eth->if_index)) < 0)
perror("SIOCGIFINDEX");
eth->local_addr_ll.sll_family = AF_PACKET;
eth->local_addr_ll.sll_ifindex = eth->if_index.ifr_ifindex;
eth->local_addrc_ll.sll_family = AF_PACKET;
eth->local_addrc_ll.sll_ifindex = eth->if_index.ifr_ifindex;
eth->local_addrd_ll.sll_family = AF_PACKET;
eth->local_addrd_ll.sll_ifindex = eth->if_index.ifr_ifindex;
/* hear traffic from specific protocol*/
if (eth->flags == ETH_RAW_IF5_MOBIPASS) {
eth->local_addr_ll.sll_protocol = htons(0xbffe);
eth->local_addrd_ll.sll_protocol = htons(0xbffe);
} else{
eth->local_addr_ll.sll_protocol = htons((short)device->eth_params->my_port);
eth->local_addrc_ll.sll_protocol = htons((short)device->eth_params->my_portc);
eth->local_addrd_ll.sll_protocol = htons((short)device->eth_params->my_portd);
}
eth->local_addr_ll.sll_halen = ETH_ALEN;
eth->local_addr_ll.sll_pkttype = PACKET_OTHERHOST;
eth->local_addrc_ll.sll_halen = ETH_ALEN;
eth->local_addrc_ll.sll_pkttype = PACKET_OTHERHOST;
eth->local_addrd_ll.sll_halen = ETH_ALEN;
eth->local_addrd_ll.sll_pkttype = PACKET_OTHERHOST;
eth->addr_len = sizeof(struct sockaddr_ll);
if (bind(eth->sockfd,(struct sockaddr *)&eth->local_addr_ll,eth->addr_len)<0) {
perror("ETHERNET: Cannot bind to socket");
exit(0);
}
if ((eth->flags != ETH_RAW_IF5_MOBIPASS ) &&
(bind(eth->sockfdc,(struct sockaddr *)&eth->local_addrc_ll,eth->addr_len)<0)) {
perror("ETHERNET: Cannot bind to socket (control)");
exit(0);
}
if (bind(eth->sockfdd,(struct sockaddr *)&eth->local_addrd_ll,eth->addr_len)<0) {
perror("ETHERNET: Cannot bind to socket (user)");
exit(0);
}
/* Construct the Ethernet header */
ether_aton_r(local_mac, (struct ether_addr *)(&(eth->eh.ether_shost)));
ether_aton_r(remote_mac, (struct ether_addr *)(&(eth->eh.ether_dhost)));
ether_aton_r(local_mac, (struct ether_addr *)(&(eth->ehd.ether_shost)));
ether_aton_r(remote_mac, (struct ether_addr *)(&(eth->ehd.ether_dhost)));
if (eth->flags == ETH_RAW_IF5_MOBIPASS) {
eth->eh.ether_type = htons(0xbffe);
eth->ehd.ether_type = htons(0xbffe);
} else {
eth->eh.ether_type = htons((short)device->eth_params->my_port);
eth->ehc.ether_type = htons((short)device->eth_params->my_portc);
eth->ehd.ether_type = htons((short)device->eth_params->my_portd);
}
printf("[%s] binding to hardware address %x:%x:%x:%x:%x:%x\n",((device->host_type == RAU_HOST) ? "RAU": "RRU"),eth->eh.ether_shost[0],eth->eh.ether_shost[1],eth->eh.ether_shost[2],eth->eh.ether_shost[3],eth->eh.ether_shost[4],eth->eh.ether_shost[5]);
printf("[%s] binding to hardware address %x:%x:%x:%x:%x:%x\n",((device->host_type == RAU_HOST) ? "RAU": "RRU"),eth->ehd.ether_shost[0],eth->ehd.ether_shost[1],eth->ehd.ether_shost[2],eth->ehd.ether_shost[3],eth->ehd.ether_shost[4],eth->ehd.ether_shost[5]);
return 0;
}
@@ -142,7 +160,7 @@ int trx_eth_write_raw(openair0_device *device, openair0_timestamp timestamp, voi
openair0_timestamp temp1 = *(openair0_timestamp *)(buff2 + MAC_HEADER_SIZE_BYTES + sizeof(int32_t));
bytes_sent = 0;
memcpy(buff2,(void*)&eth->eh,MAC_HEADER_SIZE_BYTES);
memcpy(buff2,(void*)&eth->ehd,MAC_HEADER_SIZE_BYTES);
*(int16_t *)(buff2 + MAC_HEADER_SIZE_BYTES + sizeof(int16_t))=1+(i<<1);
*(openair0_timestamp *)(buff2 + MAC_HEADER_SIZE_BYTES + sizeof(int32_t)) = timestamp;
@@ -157,10 +175,10 @@ int trx_eth_write_raw(openair0_device *device, openair0_timestamp timestamp, voi
bytes_sent);
#endif
/* Send packet */
bytes_sent += send(eth->sockfd,
buff2,
RAW_PACKET_SIZE_BYTES(nsamps),
sendto_flag);
bytes_sent += send(eth->sockfdd,
buff2,
RAW_PACKET_SIZE_BYTES(nsamps),
sendto_flag);
if ( bytes_sent == -1) {
eth->num_tx_errors++;
perror("ETHERNET WRITE: ");
@@ -212,10 +230,10 @@ int trx_eth_write_raw_IF4p5(openair0_device *device, openair0_timestamp timestam
eth->tx_nsamps = nblocks;
memcpy(buff[0], (void*)&eth->eh, MAC_HEADER_SIZE_BYTES);
memcpy(buff[0], (void*)&eth->ehd, MAC_HEADER_SIZE_BYTES);
bytes_sent = send(eth->sockfd,
bytes_sent = send(eth->sockfdd,
buff[0],
packet_size,
0);
@@ -240,7 +258,8 @@ int trx_eth_read_raw(openair0_device *device, openair0_timestamp *timestamp, voi
int i=0;
eth_state_t *eth = (eth_state_t*)device->priv;
int rcvfrom_flag =0;
int ret;
eth->rx_nsamps=nsamps;
for (i=0;i<cc;i++) {
@@ -256,17 +275,17 @@ int trx_eth_read_raw(openair0_device *device, openair0_timestamp *timestamp, voi
bytes_received=0;
while(bytes_received < RAW_PACKET_SIZE_BYTES(nsamps)) {
bytes_received +=recv(eth->sockfd,
buff2,
RAW_PACKET_SIZE_BYTES(nsamps),
rcvfrom_flag);
ret = recv(eth->sockfdd,
buff2,
RAW_PACKET_SIZE_BYTES(nsamps),
rcvfrom_flag);
if (bytes_received ==-1) {
if (ret ==-1) {
eth->num_rx_errors++;
perror("ETHERNET IF5 READ: ");
if (errno == EAGAIN) continue;
exit(-1);
return(-1);
} else {
bytes_received += ret;
/* 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;
@@ -303,26 +322,26 @@ int trx_eth_read_raw_IF4p5(openair0_device *device, openair0_timestamp *timestam
ssize_t packet_size = MAC_HEADER_SIZE_BYTES + sizeof_IF4p5_header_t;
IF4p5_header_t *test_header = (IF4p5_header_t*)(buff[0] + MAC_HEADER_SIZE_BYTES);
int ret;
#ifdef DEBUG
printf("Reading from device %p, eth %p, sockfd %d\n",device,eth,eth->sockfd);
#endif
bytes_received = recv(eth->sockfd,
bytes_received = recv(eth->sockfdd,
buff[0],
packet_size,
MSG_PEEK);
if (bytes_received ==-1) {
eth->num_rx_errors++;
perror("ETHERNET IF4p5 READ (header): ");
exit(-1);
}
if (bytes_received ==-1) {
eth->num_rx_errors++;
perror("ETHERNET IF4p5 READ (header): ");
#ifdef DEBUG
for (int i=0;i<packet_size;i++)
printf("%2x.",((uint8_t*)buff[0])[i]);
printf("\n");
for (int i=0;i<packet_size;i++)
printf("%2x.",((uint8_t*)buff[0])[i]);
printf("\n");
#endif
return(-1);
}
*timestamp = test_header->sub_type;
if (test_header->sub_type == IF4p5_PDLFFT) {
@@ -335,15 +354,16 @@ int trx_eth_read_raw_IF4p5(openair0_device *device, openair0_timestamp *timestam
while(bytes_received < packet_size) {
bytes_received = recv(eth->sockfd,
buff[0],
packet_size,
0);
if (bytes_received ==-1) {
ret = recv(eth->sockfdd,
buff[0],
packet_size,
0);
if (ret ==-1) {
eth->num_rx_errors++;
perror("ETHERNET IF4p5 READ (payload): ");
exit(-1);
return(-1);
} else {
bytes_received+=ret;
eth->rx_actual_nsamps = bytes_received>>1;
eth->rx_count++;
}
@@ -357,14 +377,14 @@ int trx_eth_read_raw_IF4p5(openair0_device *device, openair0_timestamp *timestam
int trx_eth_read_raw_IF5_mobipass(openair0_device *device, openair0_timestamp *timestamp, void **buff, int nsamps, int cc) {
// Read nblocks info from packet itself
int nblocks = nsamps;
int bytes_received=0;
eth_state_t *eth = (eth_state_t*)device->priv;
int ret;
ssize_t packet_size = 28; //MAC_HEADER_SIZE_BYTES + sizeof_IF5_mobipass_header_t ;
ssize_t packet_size = 28; //MAC_HEADER_SIZE_BYTES + sizeof_IF5_mobipass_header_t ;
// ssize_t packet_size = MAC_HEADER_SIZE_BYTES + sizeof_IF5_mobipass_header_t + 640*sizeof(int16_t);
bytes_received = recv(eth->sockfd,
bytes_received = recv(eth->sockfdd,
buff[0],
packet_size,
MSG_PEEK);
@@ -380,15 +400,16 @@ int trx_eth_read_raw_IF5_mobipass(openair0_device *device, openair0_timestamp *t
packet_size = MAC_HEADER_SIZE_BYTES + sizeof_IF5_mobipass_header_t + 640*sizeof(int16_t);
while(bytes_received < packet_size) {
bytes_received = recv(eth->sockfd,
buff[0],
packet_size,
0);
ret = recv(eth->sockfdd,
buff[0],
packet_size,
0);
if (bytes_received ==-1) {
eth->num_rx_errors++;
perror("[MOBIPASS] ETHERNET IF5 READ (payload): ");
exit(-1);
return(-1);
} else {
bytes_received+=ret;
eth->rx_actual_nsamps = bytes_received>>1;
eth->rx_count++;
}
@@ -398,35 +419,8 @@ int trx_eth_read_raw_IF5_mobipass(openair0_device *device, openair0_timestamp *t
return(bytes_received);
/*
if (bytes_received > 0) {
while(bytes_received < packet_size) {
bytes_received = recv(eth->sockfd,
buff[0],
packet_size,
0);
if (bytes_received ==-1) {
eth->num_rx_errors++;
perror("ETHERNET IF5_MOBIPASS READ (payload): ");
exit(-1);
} else {
eth->rx_actual_nsamps = bytes_received>>1;
eth->rx_count++;
}
}
if (bytes_received == packet_size){
IF5_mobipass_header_t *test_header = (IF5_mobipass_header_t*)((uint8_t *)buff[0] + MAC_HEADER_SIZE_BYTES);
*timestamp = test_header->time_stamp;
}
eth->rx_nsamps = nsamps;
}
return(bytes_received);
*/
}
int eth_set_dev_conf_raw(openair0_device *device) {
eth_state_t *eth = (eth_state_t*)device->priv;
@@ -441,13 +435,13 @@ int eth_set_dev_conf_raw(openair0_device *device) {
msg_len = MAC_HEADER_SIZE_BYTES + sizeof(openair0_config_t);
memcpy(msg,(void*)&eth->eh,MAC_HEADER_SIZE_BYTES);
memcpy(msg,(void*)&eth->ehc,MAC_HEADER_SIZE_BYTES);
memcpy((msg+MAC_HEADER_SIZE_BYTES),(void*)device->openair0_cfg,sizeof(openair0_config_t));
if (send(eth->sockfd,
msg,
msg_len,
0)==-1) {
if (send(eth->sockfdc,
msg,
msg_len,
0)==-1) {
perror("ETHERNET: ");
exit(0);
}
@@ -472,13 +466,13 @@ int eth_set_dev_conf_raw_IF4p5(openair0_device *device) {
msg_len = MAC_HEADER_SIZE_BYTES + sizeof(openair0_config_t);
memcpy(msg,(void*)&eth->eh,MAC_HEADER_SIZE_BYTES);
memcpy(msg,(void*)&eth->ehc,MAC_HEADER_SIZE_BYTES);
memcpy((msg+MAC_HEADER_SIZE_BYTES),(void*)device->openair0_cfg,sizeof(openair0_config_t));
if (send(eth->sockfd,
msg,
msg_len,
0)==-1) {
if (send(eth->sockfdc,
msg,
msg_len,
0)==-1) {
perror("ETHERNET: ");
exit(0);
}
@@ -497,7 +491,7 @@ int eth_get_dev_conf_raw(openair0_device *device) {
msg_len = MAC_HEADER_SIZE_BYTES + sizeof(openair0_config_t);
/* RRU receives from RAU openair0_config_t */
if (recv(eth->sockfd,
if (recv(eth->sockfdc,
msg,
msg_len,
0)==-1) {
@@ -506,10 +500,10 @@ int eth_get_dev_conf_raw(openair0_device *device) {
}
/* RRU stores the remote MAC address */
memcpy(eth->eh.ether_dhost,(msg+ETH_ALEN),ETH_ALEN);
memcpy(eth->ehd.ether_dhost,(msg+ETH_ALEN),ETH_ALEN);
//memcpy((void*)&device->openair0_cfg,(msg + MAC_HEADER_SIZE_BYTES), sizeof(openair0_config_t));
device->openair0_cfg=(openair0_config_t *)(msg + MAC_HEADER_SIZE_BYTES);
printf("[%s] binding mod to hardware address %x:%x:%x:%x:%x:%x hardware address %x:%x:%x:%x:%x:%x\n",((device->host_type == RAU_HOST) ? "RAU": "RRU"),eth->eh.ether_shost[0],eth->eh.ether_shost[1],eth->eh.ether_shost[2],eth->eh.ether_shost[3],eth->eh.ether_shost[4],eth->eh.ether_shost[5],eth->eh.ether_dhost[0],eth->eh.ether_dhost[1],eth->eh.ether_dhost[2],eth->eh.ether_dhost[3],eth->eh.ether_dhost[4],eth->eh.ether_dhost[5]);
printf("[%s] binding mod to hardware address %x:%x:%x:%x:%x:%x hardware address %x:%x:%x:%x:%x:%x\n",((device->host_type == RAU_HOST) ? "RAU": "RRU"),eth->ehd.ether_shost[0],eth->ehd.ether_shost[1],eth->ehd.ether_shost[2],eth->ehd.ether_shost[3],eth->ehd.ether_shost[4],eth->ehd.ether_shost[5],eth->ehd.ether_dhost[0],eth->ehd.ether_dhost[1],eth->ehd.ether_dhost[2],eth->ehd.ether_dhost[3],eth->ehd.ether_dhost[4],eth->ehd.ether_dhost[5]);
return 0;
}
@@ -526,7 +520,7 @@ int eth_get_dev_conf_raw_IF4p5(openair0_device *device) {
msg_len = MAC_HEADER_SIZE_BYTES + sizeof(openair0_config_t);
/* RRU receives from RAU openair0_config_t */
if (recv(eth->sockfd,
if (recv(eth->sockfdc,
msg,
msg_len,
0)==-1) {
@@ -535,10 +529,10 @@ int eth_get_dev_conf_raw_IF4p5(openair0_device *device) {
}
/* RRU stores the remote MAC address */
memcpy(eth->eh.ether_dhost,(msg+ETH_ALEN),ETH_ALEN);
memcpy(eth->ehd.ether_dhost,(msg+ETH_ALEN),ETH_ALEN);
//memcpy((void*)&device->openair0_cfg,(msg + MAC_HEADER_SIZE_BYTES), sizeof(openair0_config_t));
//device->openair0_cfg=(openair0_config_t *)(msg + MAC_HEADER_SIZE_BYTES);
printf("[%s] binding mod to hardware address %x:%x:%x:%x:%x:%x hardware address %x:%x:%x:%x:%x:%x\n",((device->host_type == RAU_HOST) ? "RAU": "RRU"),eth->eh.ether_shost[0],eth->eh.ether_shost[1],eth->eh.ether_shost[2],eth->eh.ether_shost[3],eth->eh.ether_shost[4],eth->eh.ether_shost[5],eth->eh.ether_dhost[0],eth->eh.ether_dhost[1],eth->eh.ether_dhost[2],eth->eh.ether_dhost[3],eth->eh.ether_dhost[4],eth->eh.ether_dhost[5]);
printf("[%s] binding mod to hardware address %x:%x:%x:%x:%x:%x hardware address %x:%x:%x:%x:%x:%x\n",((device->host_type == RAU_HOST) ? "RAU": "RRU"),eth->ehd.ether_shost[0],eth->ehd.ether_shost[1],eth->ehd.ether_shost[2],eth->ehd.ether_shost[3],eth->ehd.ether_shost[4],eth->ehd.ether_shost[5],eth->ehd.ether_dhost[0],eth->ehd.ether_dhost[1],eth->ehd.ether_dhost[2],eth->ehd.ether_dhost[3],eth->ehd.ether_dhost[4],eth->ehd.ether_dhost[5]);
return 0;
}