Esempio n. 1
0
void
dumppkt(void)
{
  uint8_t *a = uip_buf;

  DC('e');DC(' ');
  DU(uip_len,5);

  display_channel &= ~DISPLAY_TCP;
  uint8_t ole = log_enabled;
  log_enabled = 0;
  DC(' '); DC('d'); DC(' '); display_mac(a); a+= sizeof(struct uip_eth_addr);
  DC(' '); DC('s'); DC(' '); display_mac(a); a+= sizeof(struct uip_eth_addr);
  DC(' '); DC('t'); DH2(*a++); DH2(*a++);
  DNL();

  if(eth_debug > 2)
    dumpmem(a, uip_len - sizeof(struct uip_eth_hdr));
  display_channel |= DISPLAY_TCP;
  log_enabled = ole;
}
Esempio n. 2
0
void
eth_func(char *in)
{
  if(in[1] == 'i') {
    ethernet_init();

  } else if(in[1] == 'c') {
    display_ip4((uint8_t *)uip_hostaddr); DC(' ');
    display_mac((uint8_t *)uip_ethaddr.addr);
    DNL();

  } else if(in[1] == 'd') {
    eth_debug = (eth_debug+1) & 0x3;
    DH2(eth_debug);
    DNL();

  } else if(in[1] == 'n') {
    ntp_sendpacket();

  }
}
Esempio n. 3
0
/**
 *  @brief Send data to the interface
 *
 *  Writes data to be sent to network.
 */
void rtl8029_write (pok_port_id_t port_id, const void* data, uint32_t len)
{
  uint32_t        nbdest;
  uint32_t        tmp;
  uint32_t        dest;
  pok_ret_t       ret;
  char            node2[6] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
  pok_packet_t    packet;
  const char*     d;
  size_t          cpylen = 0;
  size_t          sndlen = 0;
  unsigned char	  state; // ISR state

  ret = pok_port_virtual_nb_destinations (port_id, &nbdest);
  if (ret != POK_ERRNO_OK)
  {
    return;
  }

  for (tmp = 0 ; tmp < nbdest ; tmp++)
  {
    ret = pok_port_virtual_destination (port_id, tmp, &dest);
    if (ret == POK_ERRNO_OK)
    {
      uint32_t msg_len = len;
      memcpy(packet.eth.src, dev.mac, ETH_MAC_LEN);
#ifdef POK_NEEDS_MAC_ADDR
      uint8_t node_id = 0;
      pok_port_virtual_node(dest, &node_id);
      pok_node_mac_addr(&node_id, node2);
#endif

#ifdef POK_NEEDS_DEBUG
      printf ("[RTL8029] SEND DATA THROUGH NETWORK FROM LOCAL PORT %d "
	      "TO GLOBAL PORT %d, size=%d\n", port_id, dest, len);
      printf("[RTL8029] DESTINATION MAC ADDR: ");
      display_mac(node2);
#endif
      
      memcpy(packet.eth.dst, node2, ETH_MAC_LEN);
      packet.eth.ethertype = 0x4242;
      packet.udp.src = port_id;
      packet.udp.dst = dest;

      for (d = data; msg_len != 0; msg_len -= cpylen, d += cpylen)
      {
	// too short; let's cut
	if (msg_len <= NET_DATA_MINLEN)
	{
	  cpylen = msg_len;
	  sndlen = ETH_DATA_MINLEN + sizeof(eth_hdr_t);
	}
	else
	{
	  // too big; let's pad
	  if (msg_len >= NET_DATA_MAXLEN)
	  {
	    cpylen = NET_DATA_MAXLEN;
	    sndlen = ETH_DATA_MAXLEN + sizeof(eth_hdr_t);
	  }
	  // normal
	  else
	  {
	    cpylen = msg_len;
	    sndlen = sizeof(eth_hdr_t) + sizeof(udp_hdr_t) + cpylen;
	  }
	}

	packet.udp.len = cpylen;
	memcpy(&(packet.data), d, cpylen);

	ne2000_write(&dev, &packet, sndlen, NE2000_TXBUF * 256);

	do
	{
	  state = inb(dev.addr + NE2000_ISR);
	}
	while ((state & NE2000_ISR_RDC) != NE2000_ISR_RDC);

	/* This register sets the start page address of
	   the packet to the transmitted. */
	outb(dev.addr + NE2000_TPSR, NE2000_TXBUF); //?

	/* These two registers set the byte counts of
	   the packet to be transmitted. */
	outb(dev.addr + NE2000_TBCR0, sndlen);
	outb(dev.addr + NE2000_TBCR1, sndlen >> 8);

	/* This bit must be set to transmit a packet. */
	outb(dev.addr + NE2000_CR,
	      inb(dev.addr + NE2000_CR) | NE2000_CR_TXP);

	outb(dev.addr + NE2000_ISR,
	     NE2000_ISR_RDC); // Clear RDC bit
      }
    }
  }