Exemplo n.º 1
0
InetServer::InetServer (Layer3 * la3, Trace * tr, int port):
Server (la3, tr)
{
  struct sockaddr_in addr;
  int reuse = 1;
  TRACEPRINTF (tr, 8, this, "OpenInetSocket %d", port);
  memset (&addr, 0, sizeof (addr));
  addr.sin_family = AF_INET;
  addr.sin_port = htons (port);
  addr.sin_addr.s_addr = htonl (INADDR_ANY);

  fd = socket (AF_INET, SOCK_STREAM, 0);
  if (fd == -1)
    return;

  setsockopt (fd, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof (reuse));

  if (bind (fd, (struct sockaddr *) &addr, sizeof (addr)) == -1)
    {
      close (fd);
      fd = -1;
      return;
    }

  if (listen (fd, 10) == -1)
    {
      close (fd);
      fd = -1;
      return;
    }

  TRACEPRINTF (tr, 8, this, "InetSocket opened");
  Start ();
}
Exemplo n.º 2
0
bool
Layer3::registerBusmonitor (L_Busmonitor_CallBack * c)
{
  TRACEPRINTF (t, 3, this, "registerBusmontior %08X", c);
  if (individual ())
    return 0;
  if (group ())
    return 0;
  if (broadcast ())
    return 0;
  if (mode == 0)
    {
      layer2->Close ();
      if (!layer2->enterBusmonitor ())
	{
	  layer2->Open ();
	  return 0;
	}
    }
  mode = 1;
  busmonitor.resize (busmonitor () + 1);
  busmonitor[busmonitor () - 1].cb = c;
  TRACEPRINTF (t, 3, this, "registerBusmontior %08X = 1", c);
  return 1;
}
Exemplo n.º 3
0
bool
  Layer3::registerIndividualCallBack (L_Data_CallBack * c,
				      Individual_Lock lock, eibaddr_t src,
				      eibaddr_t dest)
{
  unsigned i;
  TRACEPRINTF (t, 3, this, "registerIndividual %08X %d", c, lock);
  if (mode == 1)
    return 0;
  for (i = 0; i < individual (); i++)
    if (lock == Individual_Lock_Connection &&
	individual[i].src == src &&
	individual[i].lock == Individual_Lock_Connection)
      {
	TRACEPRINTF (t, 3, this, "registerIndividual locked %04X %04X",
		     individual[i].src, individual[i].dest);
	return 0;
      }

  for (i = 0; i < individual (); i++)
    {
      if (individual[i].dest == dest)
	break;
    }
  if (i == individual () && dest)
    if (!layer2->addAddress (dest))
      return 0;
  individual.resize (individual () + 1);
  individual[individual () - 1].cb = c;
  individual[individual () - 1].dest = dest;
  individual[individual () - 1].src = src;
  individual[individual () - 1].lock = lock;
  TRACEPRINTF (t, 3, this, "registerIndividual %08X = 1", c);
  return 1;
}
Exemplo n.º 4
0
FT12LowLevelDriver::FT12LowLevelDriver (const char *dev, Trace * tr)
{
  struct termios t1;
  t = tr;
  pth_sem_init (&in_signal);
  pth_sem_init (&out_signal);
  pth_sem_init (&send_empty);
  pth_sem_set_value (&send_empty, 1);
  getwait = pth_event (PTH_EVENT_SEM, &out_signal);

  TRACEPRINTF (t, 1, this, "Open");

  fd = open (dev, O_RDWR | O_NOCTTY | O_NDELAY | O_SYNC);
  if (fd == -1)
    return;
  set_low_latency (fd, &sold);

  close (fd);

  fd = open (dev, O_RDWR | O_NOCTTY);
  if (fd == -1)
    return;
  if (tcgetattr (fd, &old))
    {
      restore_low_latency (fd, &sold);
      close (fd);
      fd = -1;
      return;
    }

  if (tcgetattr (fd, &t1))
    {
      restore_low_latency (fd, &sold);
      close (fd);
      fd = -1;
      return;
    }
  t1.c_cflag = CS8 | PARENB | CLOCAL | CREAD;
  t1.c_iflag = IGNBRK | INPCK | ISIG;
  t1.c_oflag = 0;
  t1.c_lflag = 0;
  t1.c_cc[VTIME] = 1;
  t1.c_cc[VMIN] = 0;
  cfsetospeed (&t1, B19200);
  cfsetispeed (&t1, 0);

  if (tcsetattr (fd, TCSAFLUSH, &t1))
    {
      restore_low_latency (fd, &sold);
      close (fd);
      fd = -1;
      return;
    }
  sendflag = 0;
  recvflag = 0;
  repeatcount = 0;
  mode = 0;
  Start ();
  TRACEPRINTF (t, 1, this, "Opened");
}
Exemplo n.º 5
0
bool
  Layer3::deregisterIndividualCallBack (L_Data_CallBack * c, eibaddr_t src,
					eibaddr_t dest)
{
  unsigned i;
  for (i = 0; i < individual (); i++)
    if (individual[i].cb == c && individual[i].src == src
	&& individual[i].dest == dest)
      {
	individual[i] = individual[individual () - 1];
	individual.resize (individual () - 1);
	TRACEPRINTF (t, 3, this, "deregisterIndividual %08X = 1", c);
	for (i = 0; i < individual (); i++)
	  {
	    if (individual[i].dest == dest)
	      return 1;
	  }
	if (dest)
          for (i = 0; i < layer2 (); i++)
	    layer2[i].l2->removeAddress (dest);
	return 1;
      }
  TRACEPRINTF (t, 3, this, "deregisterIndividual %08X = 0", c);
  return 0;
}
Exemplo n.º 6
0
bool
Layer3::registerBroadcastCallBack (L_Data_CallBack * c)
{
  TRACEPRINTF (t, 3, this, "registerBroadcast %08X", c);
  if (mode == 1)
    return 0;
  broadcast.resize (broadcast () + 1);
  broadcast[broadcast () - 1].cb = c;
  TRACEPRINTF (t, 3, this, "registerBroadcast %08X = 1", c);
  return 1;
}
Exemplo n.º 7
0
void
EIBNetIPRouter::Run (pth_sem_t * stop1)
{
  pth_event_t stop = pth_event (PTH_EVENT_SEM, stop1);
  while (pth_event_status (stop) != PTH_STATUS_OCCURRED)
    {
      EIBNetIPPacket *p = sock->Get (stop);
      if (p)
	{
	  if (p->service != ROUTING_INDICATION)
	    {
	      delete p;
	      continue;
	    }
	  if (p->data () < 2 || p->data[0] != 0x29)
	    {
              if (p->data () < 2)
                {
	          TRACEPRINTF (t, 2, this, "No payload (%d)", p->data ());
                }
              else
                {
	          TRACEPRINTF (t, 2, this, "Payload not L_Data.ind (%02x)", p->data[0]);
                }
	      delete p;
	      continue;
	    }
	  const CArray data = p->data;
	  delete p;
	  L_Data_PDU *c = CEMI_to_L_Data (data, this);
	  if (c)
	    {
	      TRACEPRINTF (t, 2, this, "Recv %s", c->Decode ()());
	      if (mode & BUSMODE_UP)
		{
		  if (mode == BUSMODE_VMONITOR)
		    {
		      L_Busmonitor_PDU *l2 = new L_Busmonitor_PDU (this);
		      l2->pdu.set (c->ToPacket ());
		      l3->recv_L_Data (l2);
		    }
		  l3->recv_L_Data (c);
		  continue;
		}
	      L_Busmonitor_PDU *p1 = new L_Busmonitor_PDU (this);
	      p1->pdu = c->ToPacket ();
	      delete c;
	      l3->recv_L_Data (p1);
	      continue;
	    }
	}
    }
  pth_event_free (stop, PTH_FREE_THIS);
}
Exemplo n.º 8
0
Layer7_Broadcast::Layer7_Broadcast (Layer3 * l3, Trace * tr)
{
  t = tr;
  TRACEPRINTF (t, 5, this, "L7Broadcast Open");
  l4 = new T_Broadcast (l3, tr, 0);
  if (!l4->init ())
    {
      TRACEPRINTF (t, 5, this, "L7Broadcast init bad");
      delete l4;
      l4 = 0;
    }
}
Exemplo n.º 9
0
bool
Layer3::registerVBusmonitor (L_Busmonitor_CallBack * c)
{
  TRACEPRINTF (t, 3, this, "registerVBusmonitor %08X", c);
  if (!vbusmonitor () && !layer2->openVBusmonitor ())
    return 0;

  vbusmonitor.resize (vbusmonitor () + 1);
  vbusmonitor[vbusmonitor () - 1].cb = c;
  TRACEPRINTF (t, 3, this, "registerVBusmontior %08X = 1", c);
  return 1;
}
Exemplo n.º 10
0
Layer7_Connection::Layer7_Connection (Layer3 * l3, Trace * tr, eibaddr_t d)
{
  t = tr;
  TRACEPRINTF (t, 5, this, "L7Connection open");
  dest = d;
  l4 = new T_Connection (l3, tr, d);
  if (!l4->init ())
    {
      TRACEPRINTF (t, 5, this, "L7Connection init bad");
      delete l4;
      l4 = 0;
    }
}
Exemplo n.º 11
0
Layer7_Individual::Layer7_Individual (Layer3 * l3, Trace * tr, eibaddr_t d)
{
  TRACEPRINTF (t, 5, this, "L7Individual open");
  t = tr;
  dest = d;
  l4 = new T_Individual (l3, tr, d, false);
  if (!l4->init ())
    {
      TRACEPRINTF (t, 5, this, "L7Individual init bad");
      delete l4;
      l4 = 0;
    }
}
Exemplo n.º 12
0
void
Layer3::deregisterServer (BaseServer * s)
{
  unsigned i;
  for (i = 0; i < servers (); i++)
    if (servers[i] == s)
      {
	servers[i] = servers[servers () - 1];
	servers.resize (servers () - 1);
	TRACEPRINTF (t, 3, this, "deregisterServer %08X = 1", s);
	return;
      }
  TRACEPRINTF (t, 3, this, "deregisterServer %08X = 0", s);
}
Exemplo n.º 13
0
EIBNetIPTunnel::EIBNetIPTunnel (const char *dest, int port, int sport,
				const char *srcip, int Dataport, int flags,
				Trace * tr)
{
  t = tr;
  TRACEPRINTF (t, 2, this, "Open");
  pth_sem_init (&insignal);
  pth_sem_init (&outsignal);
  getwait = pth_event (PTH_EVENT_SEM, &outsignal);
  noqueue = flags & FLAG_B_TUNNEL_NOQUEUE;
  sock = 0;
  if (!GetHostIP (&caddr, dest))
    return;
  caddr.sin_port = htons (port);
  if (!GetSourceAddress (&caddr, &raddr))
    return;
  raddr.sin_port = htons (sport);
  NAT = false;
  dataport = Dataport;
  sock = new EIBNetIPSocket (raddr, 0, t);
  if (!sock->init ())
    {
      delete sock;
      sock = 0;
      return;
    }
  if (srcip)
    {
      if (!GetHostIP (&saddr, srcip))
	{
	  delete sock;
	  sock = 0;
	  return;
	}
      saddr.sin_port = htons (sport);
      NAT = true;
    }
  else
    saddr = raddr;
  sock->sendaddr = caddr;
  sock->recvaddr = caddr;
  sock->recvall = 0;
  mode = 0;
  vmode = 0;
  support_busmonitor = 1;
  connect_busmonitor = 0;
  Start ();
  TRACEPRINTF (t, 2, this, "Opened");
}
Exemplo n.º 14
0
void
Layer3::recv_L_Data (LPDU * l)
{
  if (running)
    {
      TRACEPRINTF (t, 3, this, "Enqueue %s", l->Decode ()());
      buf.put (l);
      pth_sem_inc (&bufsem, 0);
    }
  else
    {
      TRACEPRINTF (t, 3, this, "Discard(not running) %s", l->Decode ()());
      delete l;
    }
}
Exemplo n.º 15
0
bool
Layer3::registerLayer2 (Layer2 * l2)
{
  TRACEPRINTF (t, 3, this, "registerLayer2 %08X", l2);
  if (! busmonitor () || ! l2->enterBusmonitor ())
    if (! l2->Open ())
      {
        TRACEPRINTF (t, 3, this, "registerLayer2 %08X = 0", l2);
        return 0;
      }
  layer2.resize (layer2() + 1);
  layer2[layer2 () - 1] = l2;
  TRACEPRINTF (t, 3, this, "registerLayer2 %08X = 1", l2);
  return 1;
}
Exemplo n.º 16
0
bool
Layer3::deregisterLayer2 (Layer2 * l2)
{
  unsigned i;
  for (i = 0; i < layer2 (); i++)
    if (layer2[i] == l2)
      {
	layer2[i] = layer2[layer2 () - 1];
	layer2.resize (layer2 () - 1);
	TRACEPRINTF (t, 3, this, "deregisterLayer2 %08X = 1", l2);
	return 1;
      }
  TRACEPRINTF (t, 3, this, "deregisterLayer2 %08X = 0", l2);
  return 0;
}
Exemplo n.º 17
0
void Layer2Runner::Run(pth_sem_t * stop1)
{
  pth_event_t stop = pth_event (PTH_EVENT_SEM, stop1);
  unsigned i;

  TRACEPRINTF (l2->t, 3, this, "L2r running: %08X", l2);
  while (pth_event_status (stop) != PTH_STATUS_OCCURRED)
    {
      LPDU *l = l2->Get_L_Data (stop);
      if (!l)
	continue;
      l3->recv_L_Data(l);
    }
  TRACEPRINTF (l2->t, 3, this, "L2r stopped: %08X", l2);
}
Exemplo n.º 18
0
bool
Layer3::deregisterBroadcastCallBack (L_Data_CallBack * c)
{
  unsigned i;
  for (i = 0; i < broadcast (); i++)
    if (broadcast[i].cb == c)
      {
	broadcast[i] = broadcast[broadcast () - 1];
	broadcast.resize (broadcast () - 1);
	TRACEPRINTF (t, 3, this, "deregisterBroadcast %08X = 1", c);
	return 1;
      }
  TRACEPRINTF (t, 3, this, "deregisterBroadcast %08X = 0", c);
  return 0;
}
Exemplo n.º 19
0
void
TPUARTLayer2Driver::Send_L_Data (LPDU * l)
{
  TRACEPRINTF (t, 2, this, "Send %s", l->Decode ()());
  inqueue.put (l);
  pth_sem_inc (&in_signal, 1);
}
Exemplo n.º 20
0
USBLoop::USBLoop (libusb_context * c, Trace * tr)
{
  t = tr;
  context = c;
  TRACEPRINTF (t, 10, this, "USBLoop-Create");
  Start ();
}
Exemplo n.º 21
0
EIBNetIPRouter::~EIBNetIPRouter ()
{
  TRACEPRINTF (t, 2, this, "Destroy");
  Stop ();
  if (sock)
    delete sock;
}
Exemplo n.º 22
0
USBLayer2::USBLayer2 (LowLevelDriver * i, Layer3 * l3,
                      L2options *opt) : Layer2 (l3, opt)
{
  emi = 0;
  LowLevelDriver *iface = initUSBDriver (i, t);
  if (!iface)
    return;

  switch (iface->getEMIVer ())
    {
    case LowLevelDriver::vEMI1:
      emi = new EMI1Layer2 (iface, l3, opt);
      break;
    case LowLevelDriver::vEMI2:
      emi = new EMI2Layer2 (iface, l3, opt);
      break;
    case LowLevelDriver::vCEMI:
      emi = new CEMILayer2 (iface, l3, opt);
      break;
    default:
      TRACEPRINTF (t, 2, this, "Unsupported EMI");
      delete iface;
      return;
    }
}
Exemplo n.º 23
0
void
Layer3::recv_L_Data (LPDU * l)
{
  TRACEPRINTF (t, 3, this, "Recv %s", l->Decode ()());
  buf.put (l);
  pth_sem_inc (&bufsem, 0);
}
Exemplo n.º 24
0
TPUARTwrap::~TPUARTwrap ()
{
  TRACEPRINTF (t, 2, "Close");

  timer.stop();
  sendtimer.stop();
}
Exemplo n.º 25
0
GroupCache::~GroupCache ()
{
  TRACEPRINTF (t, 4, this, "GroupCacheDestroy");
  if (enable)
    layer3->deregisterGroupCallBack (this, 0);
  Clear ();
}
Exemplo n.º 26
0
USBLayer2Interface::USBLayer2Interface (LowLevelDriverInterface * i,
					Trace * tr, int flags) : Layer2Interface (tr)
{
  emi = 0;
  LowLevelDriverInterface *iface = initUSBDriver (i, tr);
  if (!iface)
    return;

  switch (iface->getEMIVer ())
    {
    case LowLevelDriverInterface::vEMI1:
      emi = new EMI1Layer2Interface (iface, tr, flags);
      break;
    case LowLevelDriverInterface::vEMI2:
      emi = new EMI2Layer2Interface (iface, tr, flags);
      break;
    case LowLevelDriverInterface::vCEMI:
      emi = new CEMILayer2Interface (iface, tr, flags);
      break;
    default:
      TRACEPRINTF (tr, 2, this, "Unsupported EMI");
      delete iface;
      return;
    }
}
Exemplo n.º 27
0
bool
Layer3::registerLayer2 (Layer2Interface * l2)
{
  TRACEPRINTF (t, 3, this, "registerLayer2 %08X", l2);
  if (!(mode ? l2->enterBusmonitor () : l2->Open ()))
    {
      TRACEPRINTF (t, 3, this, "registerLayer2 %08X = 0", l2);
      return 0;
    }
  layer2.resize (layer2() + 1);
  layer2[layer2 () - 1].l2 = l2;
  layer2[layer2 () - 1].l3 = this;
  if (running)
    layer2[layer2 () - 1].Start ();
  TRACEPRINTF (t, 3, this, "registerLayer2 %08X = 1", l2);
  return 1;
}
Exemplo n.º 28
0
SystemdServer::SystemdServer (Layer3 * la3, Trace * tr, int systemd_fd):
Server (la3, tr)
{
  TRACEPRINTF (tr, 8, this, "OpenSystemdSocket");

  fd = systemd_fd;
  if (listen (fd, 10) == -1)
    {
      ERRORPRINTF (tr, E_ERROR | 18, this, "OpenSystemdSocket: listen: %s", strerror(errno));
      close (fd);
      fd = -1;
      return;
    }

  TRACEPRINTF (tr, 8, this, "SystemdSocket opened");
  Start ();
}
Exemplo n.º 29
0
void
Layer3::send_L_Data (L_Data_PDU * l)
{
  TRACEPRINTF (t, 3, this, "Send %s", l->Decode ()());
  if (l->source == 0)
    l->source = layer2->getDefaultAddr ();
  layer2->Send_L_Data (l);
}
Exemplo n.º 30
0
EIBnetDriver::~EIBnetDriver ()
{
  TRACEPRINTF (t, 8, "CloseD");
  EIBnetServer &parent = *std::static_pointer_cast<EIBnetServer>(server);
  EIBNetIPSocket *ps = parent.sock;
  if (sock && ps && ps != sock)
    delete sock;
}