software/drivers/sd8887/src/wlan/mapp/mlanutl/timestamp.c
/**
 *@brief      Receive Timestamps
 *
 *@param argc Number of arguments
 *@param argv Pointer to the arguments array
 *
 * @return     MLAN_STATUS_SUCCESS/MLAN_STATUS_FAILURE
 **/
@brief      Receive Timestamps
@param argc Number of arguments
@param argv Pointer to the arguments array


@brief Receive Timestamps @param argc Number of arguments @param argv Pointer to the arguments array
void
receive_timestamp(int argc, char *argv[])
{
	int sockfd;
	int sockopt;
	char ifName[IFNAMSIZ];
	struct ifreq if_ip;	
	int so_timestamping_flags = 0;
	int siocgstamp = 0;
	int siocgstampns = 0;
	struct timeval now;
	int res;
	struct ifreq if_idx;
	struct ifreq if_mac;
	fd_set readfs, errorfs;
	if (argc > 2)
		strcpy(ifName, argv[1]);
	else {
		fprintf(stderr,
			"invalid no. of arguments to receive_timestamp \n");
		exit(1);
	}
	so_timestamping_flags |= SOF_TIMESTAMPING_SOFTWARE;
	so_timestamping_flags |= SOF_TIMESTAMPING_RAW_HARDWARE;
	memset(&if_ip, 0, sizeof(struct ifreq));
	if ((sockfd = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_802_EX1))) == -1) {
		perror("listener: socket");
	}
	memset(&if_idx, 0, sizeof(struct ifreq));
	strncpy(if_idx.ifr_name, ifName, IFNAMSIZ - 1);
	if (ioctl(sockfd, SIOCGIFINDEX, &if_idx) < 0)
		perror("SIOCGIFINDEX");
	memset(&if_mac, 0, sizeof(struct ifreq));
	strncpy(if_mac.ifr_name, ifName, IFNAMSIZ - 1);
	if (ioctl(sockfd, SIOCGIFHWADDR, &if_mac) < 0)
		perror("SIOCGIFHWADDR");
	if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &sockopt,
		       sizeof sockopt) == -1) {
		perror("setsockopt");
		close(sockfd);
		exit(1);
	}
	if (setsockopt(sockfd, SOL_SOCKET, SO_BINDTODEVICE,
		       ifName, IFNAMSIZ - 1) == -1) {
		perror("SO_BINDTODEVICE");
		close(sockfd);
		exit(1);
	}
	if (so_timestamping_flags &&
	    setsockopt(sockfd, SOL_SOCKET, SO_TIMESTAMPING,
		       &so_timestamping_flags,
		       sizeof(so_timestamping_flags)) < 0)
		perror("setsockopt SO_TIMESTAMPING");
	while (1) {
		FD_ZERO(&readfs);
		FD_ZERO(&errorfs);
		FD_SET(sockfd, &readfs);
		FD_SET(sockfd, &errorfs);
		gettimeofday(&now, NULL);
		res = select(sockfd + 1, &readfs, 0, &errorfs, NULL);
		if (res > 0) {
			recvpacket(sockfd, 0, siocgstamp, siocgstampns);
		}
	}
}
void receive_timestamp ( int argc , char * argv [ ] ) { int sockfd ; int sockopt ; char ifName [ IFNAMSIZ ] ; struct ifreq if_ip ; int so_timestamping_flags = 0 ; int siocgstamp = 0 ; int siocgstampns = 0 ; struct timeval now ; int res ; struct ifreq if_idx ; struct ifreq if_mac ; fd_set readfs , errorfs ; if ( argc > 2 ) strcpy ( ifName , argv [ 1 ] ) ; else { fprintf ( stderr , " \n " ) ; exit ( 1 ) ; } so_timestamping_flags |= SOF_TIMESTAMPING_SOFTWARE ; so_timestamping_flags |= SOF_TIMESTAMPING_RAW_HARDWARE ; memset ( & if_ip , 0 , sizeof ( struct ifreq ) ) ; if ( ( sockfd = socket ( PF_PACKET , SOCK_RAW , htons ( ETH_P_802_EX1 ) ) ) == -1 ) { perror ( " " ) ; } memset ( & if_idx , 0 , sizeof ( struct ifreq ) ) ; strncpy ( if_idx . ifr_name , ifName , IFNAMSIZ - 1 ) ; if ( ioctl ( sockfd , SIOCGIFINDEX , & if_idx ) < 0 ) perror ( " " ) ; memset ( & if_mac , 0 , sizeof ( struct ifreq ) ) ; strncpy ( if_mac . ifr_name , ifName , IFNAMSIZ - 1 ) ; if ( ioctl ( sockfd , SIOCGIFHWADDR , & if_mac ) < 0 ) perror ( " " ) ; if ( setsockopt ( sockfd , SOL_SOCKET , SO_REUSEADDR , & sockopt , sizeof sockopt ) == -1 ) { perror ( " " ) ; close ( sockfd ) ; exit ( 1 ) ; } if ( setsockopt ( sockfd , SOL_SOCKET , SO_BINDTODEVICE , ifName , IFNAMSIZ - 1 ) == -1 ) { perror ( " " ) ; close ( sockfd ) ; exit ( 1 ) ; } if ( so_timestamping_flags && setsockopt ( sockfd , SOL_SOCKET , SO_TIMESTAMPING , & so_timestamping_flags , sizeof ( so_timestamping_flags ) ) < 0 ) perror ( " " ) ; while ( 1 ) { FD_ZERO ( & readfs ) ; FD_ZERO ( & errorfs ) ; FD_SET ( sockfd , & readfs ) ; FD_SET ( sockfd , & errorfs ) ; gettimeofday ( & now , NULL ) ; res = select ( sockfd + 1 , & readfs , 0 , & errorfs , NULL ) ; if ( res > 0 ) { recvpacket ( sockfd , 0 , siocgstamp , siocgstampns ) ; } } }
@brief      Receive Timestamps
@param argc Number of arguments
@param argv Pointer to the arguments array
@brief Receive Timestamps @param argc Number of arguments @param argv Pointer to the arguments array
/* get ip addr */ /* Get interface name */ /* Header structures */ /* Open PF_PACKET socket, listening for EtherType ETHER_TYPE */ /* Get the index of the interface to receive on */ /* Get the MAC address of the interface to receive on */ /* Allow the socket to be reused - incase connection is closed prematurely */ /* Bind to device */