Beispiel #1
0
int ptpd_netif_read_calibration_data(const char *ifaceName, uint64_t *deltaTx,
				     uint64_t *deltaRx)
{
	hexp_port_state_t state;

#ifdef TOMEK
	//read the port state
	halexp_get_port_state(&state, ifaceName);

	// check if the data is available
	if(state.valid)
	{

		//check if tx is calibrated,
		// if so read data
		if(state.tx_calibrated)
			*deltaTx = state.delta_tx;
		else
			return PTPD_NETIF_NOT_FOUND;

		//check if rx is calibrated,
		// if so read data
		if(state.rx_calibrated)
			*deltaRx = state.delta_rx;
		else
			return PTPD_NETIF_NOT_FOUND;

	}
	return PTPD_NETIF_OK;
#else
	return PTPD_NETIF_NOT_FOUND;
#endif

}
Beispiel #2
0
int ptpd_netif_get_port_state(const char *ifaceName)
{
	hexp_port_state_t state;

	//read the port state
	halexp_get_port_state(&state, ifaceName);

	// check if the data is available
	if(state.valid)
	{
		//check if link is UP
		if(state.up > 0)
			return PTPD_NETIF_OK;
		else
		{
//      if(!strcmp(ifaceName,"wru1") || !strcmp(ifaceName,"wru0"))
//	printf("(ptpd_netif) linkdown detected on port: %s\n",ifaceName);
			return PTPD_NETIF_ERROR;
		}

	}
	printf("(ptpd_netif) linkdown detected on port: %s "
	       "[no valid port state data)\n",ifaceName);
	//should not get here
	return PTPD_NETIF_ERROR;
}
Beispiel #3
0
int ptpd_netif_calibrating_poll(int txrx, const char *ifaceName,
				uint64_t *delta)
{
#ifdef TOMEK
	hexp_port_state_t state;

	halexp_get_port_state(&state, ifaceName);

	if(txrx == PTPD_NETIF_TX && state.tx_calibrated)
	{
		*delta = state.delta_tx;
		return PTPD_NETIF_READY;
	}  else if(txrx == PTPD_NETIF_RX && state.rx_calibrated)
	{
		*delta = state.delta_rx;
		return PTPD_NETIF_READY;
	}

	return PTPD_NETIF_NOT_READY;
#else
	if(tmp_calibration_cnt++ > 1)
	{
		*delta = (uint64_t)1<<8; //[ps];

		netif_dbg("(PTPD_NETIF): delta = : %ldd [0x%x]\n",
			  (uint64_t)*delta,(uint64_t)*delta);
		return PTPD_NETIF_READY;
	}
	else
		return PTPD_NETIF_NOT_READY;
#endif
}
Beispiel #4
0
static void update_dmtd(wr_socket_t *sock)
{
	struct my_socket *s = (struct my_socket *) sock;
	hexp_port_state_t pstate;

	if(tmo_expired(&s->dmtd_update_tmo))
	{
		halexp_get_port_state(&pstate, s->bind_addr.if_name);

		// FIXME: ccheck if phase value is ready
		s->dmtd_phase = pstate.phase_val;

		tmo_restart(&s->dmtd_update_tmo);
	}
}
Beispiel #5
0
wr_socket_t *ptpd_netif_create_socket(int sock_type, int flags, wr_sockaddr_t *bind_addr)
{
  int i;
  hexp_port_state_t pstate;
  struct my_socket *sock;

	/* Look for the first available socket. */
	for (sock = NULL, i=0; i<NET_MAX_SOCKETS; i++)
    	if(!socks[i].in_use)
    	{
    		sock = &socks[i];
    		break;
    	}
	
	if (!sock)
	{
	 	TRACE_WRAP("No sockets left.\n");
	 	return NULL;
	}

  if (sock_type != PTPD_SOCK_RAW_ETHERNET)
    return NULL;

  if (halexp_get_port_state(&pstate, bind_addr->if_name) < 0)
    return NULL;

  memcpy (&sock->bind_addr, bind_addr, sizeof(wr_sockaddr_t));

  /*get mac from endpoint*/
  get_mac_addr(&sock->local_mac);

  sock->phase_transition = pstate.t2_phase_transition;
  sock->dmtd_phase = pstate.phase_val;

  /*packet queue*/
  sock->queue.head = sock->queue.tail = 0;
  sock->queue.avail = NET_SKBUF_SIZE;
  sock->queue.n = 0;
  sock->in_use = 1;

  return (wr_socket_t*)(sock);
}
int ptpd_netif_read_calibration_data(const char *ifaceName, uint64_t *deltaTx,
    uint64_t *deltaRx, int32_t *fix_alpha, int32_t *clock_period)
{
  hexp_port_state_t state;

  halexp_get_port_state(&state, ifaceName);

  // check if the data is available
  if(state.valid)
  {

    if(fix_alpha)
      *fix_alpha = state.fiber_fix_alpha;

    if(clock_period)
      *clock_period = state.clock_period;

    //check if tx is calibrated,
    // if so read data
    if(state.tx_calibrated)
    {
      if(deltaTx) *deltaTx = state.delta_tx;
    }
    else
      return PTPD_NETIF_NOT_FOUND;

    //check if rx is calibrated,
    // if so read data
    if(state.rx_calibrated)
    {
      if(deltaRx) *deltaRx = state.delta_rx;
    }
    else
      return PTPD_NETIF_NOT_FOUND;

  }
  return PTPD_NETIF_OK;

}
Beispiel #7
0
wr_socket_t *ptpd_netif_create_socket(int sock_type, int flags,
				      wr_sockaddr_t *bind_addr)
{
	struct my_socket *s;
	struct sockaddr_ll sll;
	struct ifreq f;

	hexp_port_state_t pstate;

	int fd;

	//    fprintf(stderr,"CreateSocket!\n");

	if(sock_type != PTPD_SOCK_RAW_ETHERNET)
		return NULL;

	if(halexp_get_port_state(&pstate, bind_addr->if_name) < 0)
		return NULL;

	fd = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));

	if(fd < 0)
	{
		perror("socket()");
		return NULL;
	}

	fcntl(fd, F_SETFL, O_NONBLOCK);

	// Put the controller in promiscious mode, so it receives everything
	strcpy(f.ifr_name, bind_addr->if_name);
	if(ioctl(fd, SIOCGIFFLAGS,&f) < 0) { perror("ioctl()"); return NULL; }
	f.ifr_flags |= IFF_PROMISC;
	if(ioctl(fd, SIOCSIFFLAGS,&f) < 0) { perror("ioctl()"); return NULL; }

	// Find the inteface index
	strcpy(f.ifr_name, bind_addr->if_name);
	ioctl(fd, SIOCGIFINDEX, &f);


	sll.sll_ifindex = f.ifr_ifindex;
	sll.sll_family   = AF_PACKET;
	sll.sll_protocol = htons(bind_addr->ethertype);
	sll.sll_halen = 6;

	memcpy(sll.sll_addr, bind_addr->mac, 6);

	if(bind(fd, (struct sockaddr *)&sll, sizeof(struct sockaddr_ll)) < 0)
	{
		close(fd);
		perror("bind()");
		return NULL;
	}

	// timestamping stuff:

	int so_timestamping_flags = SOF_TIMESTAMPING_TX_HARDWARE |
		SOF_TIMESTAMPING_RX_HARDWARE |
		SOF_TIMESTAMPING_RAW_HARDWARE;

	struct ifreq ifr;
	struct hwtstamp_config hwconfig;

	strncpy(ifr.ifr_name, bind_addr->if_name, sizeof(ifr.ifr_name));

	hwconfig.tx_type = HWTSTAMP_TX_ON;
	hwconfig.rx_filter = HWTSTAMP_FILTER_PTP_V2_L2_EVENT;

	ifr.ifr_data = &hwconfig;

	if (ioctl(fd, SIOCSHWTSTAMP, &ifr) < 0)
	{
		perror("SIOCSHWTSTAMP");
		return NULL;
	}

	if(setsockopt(fd, SOL_SOCKET, SO_TIMESTAMPING, &so_timestamping_flags,
		      sizeof(int)) < 0)
	{
		perror("setsockopt(SO_TIMESTAMPING)");
		return NULL;
	}

	s=calloc(sizeof(struct my_socket), 1);

	s->if_index = f.ifr_ifindex;

	// get interface MAC address
	if (ioctl(fd, SIOCGIFHWADDR, &f) < 0) {
		perror("ioctl()"); return NULL;
	}

	memcpy(s->local_mac, f.ifr_hwaddr.sa_data, 6);
	memcpy(&s->bind_addr, bind_addr, sizeof(wr_sockaddr_t));

	s->fd = fd;

	// store the linearization parameters
	s->clock_period = pstate.clock_period;
	s->phase_transition = pstate.t2_phase_transition;
	s->dmtd_phase = pstate.phase_val;

	tmo_init(&s->dmtd_update_tmo, DMTD_UPDATE_INTERVAL);

	return (wr_socket_t*)s;
}