Example #1
0
static err_t rza1_low_level_output(struct netif *netif, struct pbuf *p) {
    struct pbuf *q;
    s32_t       cnt;
    err_t       err        = ERR_MEM;
    s32_t       write_size = 0;

    if ((p->payload != NULL) && (p->len != 0)) {
        /* If the first data can't be written, transmit descriptor is full. */
        for (cnt = 0; cnt < 100; cnt++) {
            write_size = ethernet_write((char *)p->payload, p->len);
            if (write_size != 0) {
                break;
            }
            osDelay(1);
        }
        if (write_size != 0) {
            for (q = p->next; q != NULL; q = q->next) {
                (void)ethernet_write((char *)q->payload, q->len);
            }
            if (ethernet_send() == 1) {
                err = ERR_OK;
            }
        }
    }

    return err;
}
Example #2
0
/*---------------------------------------------------------------------------*/
static void
pollhandler(void)
{
  process_poll(&ethernet_process);
  uip_len = ethernet_poll();

  if(uip_len > 0) {
#if UIP_CONF_IPV6
    if(BUF->type == uip_htons(UIP_ETHTYPE_IPV6)) {
      uip_neighbor_add(&IPBUF->srcipaddr, &BUF->src);
      tcpip_input();
    } else
#endif /* UIP_CONF_IPV6 */
    if(BUF->type == uip_htons(UIP_ETHTYPE_IP)) {
      uip_len -= sizeof(struct uip_eth_hdr);
      tcpip_input();
    } else if(BUF->type == uip_htons(UIP_ETHTYPE_ARP)) {
      uip_arp_arpin();
      /* If the above function invocation resulted in data that
	 should be sent out on the network, the global variable
	 uip_len is set to a value > 0. */
      if(uip_len > 0) {
	ethernet_send();
      }
    }
  }
}
Example #3
0
void arp_process(void) {
   int i;
#if debug_arp
  arp_display();
#endif //debug_arp

  if (differ_subnet(ARPr->senproaddr)==0)	  // only update addresses from local network devices
    arp_update();				  // (the rest will use the Gateway's address)
  if (! memcmp(ARPr->tarproaddr, MyIP, 4)) {	  // is this ARP message for us?
    if (ARPr->opcode == HTONS(ARP_Request)) {	  // is this an ARP Request?
      ARPt->hwtype = HTONS(0x0001);
      ARPt->protype = HTONS(0x0800);
      ARPt->hwaddrlen = 6;
      ARPt->proaddrlen = 4;
      ARPt->opcode= HTONS(ARP_Reply);			      // Opcode for ARP Reply
      memcpy(ARPt->tarhwaddr, ARPr->senhwaddr, 6);	      // use the sender MAC address
      memcpy(ARPt->tarproaddr, ARPr->senproaddr, 4);          // use the sender IP address
      memcpy(ARPt->senhwaddr, MyMAC, 6);		      // use our MAC address
      memcpy(ARPt->senproaddr, MyIP, 4);		      // use our IP address
      for(i=0;i<18;i++)
        tx_buf[42+i] = 0x20;
      ethernet_send(ARP_PROTOCOL, sizeof(struct arp_hdr)+18); // Send frame (Padding)
    }
  }
}
Example #4
0
void arp_handle() {

    //cprintf("receive arp .............................\n");
    int * data = ethernet_rx_data + ETHERNET_HDR_LEN;
    if(data[ARP_TYPE] == ARP_TYPE_REPLY) {
        if(eth_memcmp(data + ARP_TARGET_IP, IP_ADDR, 4) != 0);
            return;

        int i=0;
        for (i=0; i<4; i++)
            cprintf("%d\n", *(data+ARP_SENDER_IP+i));
        //tcp_request();
		
		for (i = 0; i < 6; i++)
			remote_mac[i] = *(data+ARP_SENDER_MAC+i);
		
 
    }
	else if (data[ARP_TYPE] == ARP_TYPE_REQUEST && 
		     data[ARP_TARGET_IP] == IP_ADDR[0] &&
			 data[ARP_TARGET_IP + 1] == IP_ADDR[1] &&
			 data[ARP_TARGET_IP + 2] == IP_ADDR[2] &&
			 data[ARP_TARGET_IP + 3] == IP_ADDR[3]) 
	{
		ethernet_tx_len = ETHERNET_HDR_LEN + ARP_BODY_LEN;
        ethernet_set_tx(ethernet_rx_src, ETHERNET_TYPE_ARP);
		
        int * buf = ethernet_tx_data + ETHERNET_HDR_LEN;
		eth_memcpy(buf, ARP_FIX_HDR, 6 + 1);
		buf[ARP_TYPE] = ARP_TYPE_REPLY;
        eth_memcpy(buf + ARP_SENDER_MAC, MAC_ADDR, 6);
        eth_memcpy(buf + ARP_SENDER_IP, IP_ADDR, 4);
        eth_memcpy(buf + ARP_TARGET_MAC,
               data + ARP_SENDER_MAC, 6);
        eth_memcpy(buf + ARP_TARGET_IP,
               data + ARP_SENDER_IP, 4);
		
		cprintf("send arp response...\n");
		
        ethernet_send();
	}
	else if (data[ARP_TYPE] == ARP_TYPE_REQUEST && 
		     data[ARP_TARGET_IP] == data[ARP_SENDER_IP] &&
			 data[ARP_TARGET_IP + 1] == data[ARP_SENDER_IP + 1] &&
			 data[ARP_TARGET_IP + 2] == data[ARP_SENDER_IP + 2] &&
			 data[ARP_TARGET_IP + 3] == data[ARP_SENDER_IP + 3]) //Is gratuitous = true
	{
		if (data[ARP_TARGET_IP] ==  tcp_dst_addr[0] &&
			 data[ARP_TARGET_IP + 1] == tcp_dst_addr[1] &&
			 data[ARP_TARGET_IP + 2] == tcp_dst_addr[2] &&
			 data[ARP_TARGET_IP + 3] == tcp_dst_addr[3])
		{
			int i;
			for (i = 0; i < 6; i++)
				remote_mac[i] = *(data+ARP_SENDER_MAC+i);
			arp_request();
			tcp_request();
		}
	}
}
Example #5
0
/*---------------------------------------------------------------------------*/
uint8_t
ethernet_output(void)
{
  uip_arp_out();
  ethernet_send();
  
  return 0;
}
Example #6
0
File: main.c Project: jezze/fudge
static void ethernetprotocol_notify(struct ethernet_header *ethernetheader, void *buffer, unsigned int count)
{

    union event_message message;
    struct arp_header *header = buffer;
    unsigned char *data = (unsigned char *)(header + 1);
    unsigned int htype = (header->htype[0] << 8) | header->htype[1];
    unsigned int ptype = (header->ptype[0] << 8) | header->ptype[1];
    unsigned int operation = (header->operation[0] << 8) | header->operation[1];
    unsigned char *sha = data;
    unsigned char *spa = data + header->hlength;
    unsigned char *tha = data + header->hlength + header->plength;
    unsigned char *tpa = data + header->hlength + header->plength + header->hlength;
    struct arp_hook *hook = findhook(htype, header->hlength, ptype, header->plength);

    if (hook)
    {

        switch (operation)
        {

        case ARP_REQUEST:
            hook->save(sha, spa);

            tha = hook->lookup(tpa);

            if (tha)
            {

                unsigned char response[ETHERNET_MTU];
                unsigned char *current = arp_writehead(response, htype, header->hlength, ptype, header->plength, ARP_REPLY, tha, tpa, sha, spa);

                ethernet_send(response, current - response);

            }

            break;

        case ARP_REPLY:
            hook->save(sha, spa);

            break;

        }

    }

    event_create(&message, EVENT_DATA);
    event_append(&message, count, buffer);
    kernel_multicast(EVENT_BROADCAST, &ethernetprotocol.data.states, &message);

}
Example #7
0
void arp_request(char *proaddr) {
  int i;

  ARPt->hwtype = HTONS(0x0001);
  ARPt->protype = HTONS(0x0800);
  ARPt->hwaddrlen = 6;
  ARPt->proaddrlen = 4;
  ARPt->opcode= HTONS(ARP_Request);
  memcpy(ARPt->tarproaddr, proaddr, 4);	
  memset(ARPt->tarhwaddr, 0x00, 6);
  memcpy(ARPt->senproaddr, MyIP, 4);					
  memcpy(ARPt->senhwaddr, MyMAC, 6);					
  for(i=0;i<18;i++)
    tx_buf[42+i] = 0x20;
  ethernet_send(ARP_PROTOCOL, sizeof(struct arp_hdr)+18);	// Send frame (Padding...)
}
Example #8
0
void ip_send(int proto, int length) {
    length += IP_HDR_LEN; // ip header
    ethernet_set_tx(ETHERNET_TYPE_IP);
    int * data = ethernet_tx_data + ETHERNET_HDR_LEN;
    data[IP_VERSION] = IP_VERSION_VAL;
    data[IP_TOTAL_LEN] = MSB(length);
    data[IP_TOTAL_LEN + 1] = LSB(length);
    data[IP_FLAGS] = 0;
    data[IP_FLAGS + 1] = 0;
    data[IP_TTL] = 64;
    data[IP_PROTOCAL] = proto;
    eth_memcpy(data + IP_SRC, IP_ADDR, 4);
    eth_memcpy(data + IP_DST,
        REMOTE_IP_ADDR, 4);
    ethernet_tx_len = ETHERNET_HDR_LEN + length;
    ethernet_send();
}
Example #9
0
void udp_send_packet(int *data, int len)
{
	int * packet = ethernet_tx_data + ETHERNET_HDR_LEN + IP_HDR_LEN;
	int2mem(packet + UDP_SRC_PORT, 2, udp_dst_port);
    int2mem(packet + UDP_DST_PORT, 2, udp_src_port);
	packet[UDP_LENGTH] = MSB(len + 8);
	packet[UDP_LENGTH + 1] = LSB(len + 8);
	packet[UDP_CHECKSUM] = 0;
	packet[UDP_CHECKSUM + 1] = 0;
	int i;
	for (i = 0; i < len; i++) 
		packet[UDP_DATA + i] = data[i];
	
	ip_send_packet(remote_mac, IP_PROTOCAL_UDP, len + 8);
    ethernet_tx_len = ETHERNET_HDR_LEN + IP_HDR_LEN + len + 8;
    ethernet_send();
}
Example #10
0
static void arp_request(struct netdevice * device, uint32_t targetIp) {
    sbuff * buf = ethernet_sbuff_alloc(sizeof(struct arp_packet));
    add_ref(buf);

    struct arp_packet * arp = (struct arp_packet*)buf->head;
    arp->htype = ntos(1);
    arp->ptype = ntos(0x0800);
    arp->hlen = 6;
    arp->plen = 4;
    arp->operation = ntos(1);
    memcpy(arp->senderMac, device->mac, 6);
    arp->senderIp = ntol(device->ip);
    bzero(arp->targetMac, 6);
    arp->targetIp = ntol(targetIp);

    ethernet_send(buf, 0x0806, BROADCAST_MAC, device);
    release_ref(buf, sbuff_free);
}
Example #11
0
void arp_request(){
    ethernet_tx_len = ETHERNET_HDR_LEN + ARP_BODY_LEN;

    ethernet_set_tx(BROADCAST, ETHERNET_TYPE_ARP);

    int * buf = ethernet_tx_data + ETHERNET_HDR_LEN;
    eth_memcpy(buf, ARP_FIX_HDR, 6 + 1);
    buf[ARP_TYPE] = ARP_TYPE_REQUEST;
    eth_memcpy(buf + ARP_SENDER_MAC, MAC_ADDR, 6);
    eth_memcpy(buf + ARP_SENDER_IP, IP_ADDR, 4);
    eth_memcpy(buf + ARP_TARGET_MAC, DEFAULT, 6);
    eth_memcpy(buf + ARP_TARGET_IP,
               tcp_dst_addr, 4);
			   
	intr_disable();
    ethernet_send();
	intr_enable();
    //cprintf("send arp ...........................\n");
}
Example #12
0
static void reply(struct netdevice* dev, mac target, uint32_t ip, int broadcast) {
    sbuff * buf = raw_sbuff_alloc(sizeof(struct ethernet_frame) + sizeof(struct arp_packet));
    add_ref(buf);
    sbuff_push(buf, sizeof(struct ethernet_frame));

    struct arp_packet * arp = (struct arp_packet*)buf->head;
    arp->htype = ntos(1);
    arp->ptype = ntos(0x0800);
    arp->hlen = 6;
    arp->plen = 4;
    arp->operation = ntos(2);
    memcpy(arp->senderMac, dev->mac, 6);
    arp->senderIp = ntol(dev->ip);
    memcpy(arp->targetMac, target, 6);
    arp->targetIp = ntol(ip);

    ethernet_send(buf, 0x0806, broadcast ? BROADCAST_MAC : target, dev);
    release_ref(buf, sbuff_free);
}
Example #13
0
File: arp.c Project: cjld/armcpu
void arp_handle() {
    int * data = ethernet_rx_data + ETHERNET_HDR_LEN;
    if(data[ARP_TYPE] == ARP_TYPE_REQUEST) {
        if(eth_memcmp(data + ARP_TARGET_IP, IP_ADDR, 4) != 0)
            return;
        ethernet_tx_len = ETHERNET_HDR_LEN + ARP_BODY_LEN;
        ethernet_set_tx(ethernet_rx_src, ETHERNET_TYPE_ARP);

        int * buf = ethernet_tx_data + ETHERNET_HDR_LEN;
        eth_memcpy(buf, ARP_FIX_HDR, 6 + 1);
        buf[ARP_TYPE] = ARP_TYPE_REPLY;
        eth_memcpy(buf + ARP_SENDER_MAC, MAC_ADDR, 6);
        eth_memcpy(buf + ARP_SENDER_IP, IP_ADDR, 4);
        eth_memcpy(buf + ARP_TARGET_MAC,
               data + ARP_SENDER_MAC, 6);
        eth_memcpy(buf + ARP_TARGET_IP,
               data + ARP_SENDER_IP, 4);
        ethernet_send();
    }
}
Example #14
0
/* returns number of bytes sent on success, negative on failure */
int ethernet_send_pdu(
    BACNET_ADDRESS * dest,      /* destination address */
    uint8_t * pdu,      /* any data to be sent - may be null */
    unsigned pdu_len    /* number of bytes of data */
    )
{
    int i = 0;  /* counter */
    BACNET_ADDRESS src = { 0 }; /* source address */

    for (i = 0; i < 6; i++) {
        src.mac[i] = Ethernet_MAC_Address[i];
        src.mac_len++;
    }
    /* function to send a packet out the 802.2 socket */
    /* returns 1 on success, 0 on failure */
    return ethernet_send(dest,  /* destination address */
        &src,   /* source address */
        pdu,    /* any data to be sent - may be null */
        pdu_len /* number of bytes of data */
        );
}
Example #15
0
static int ethernet_proc(struct netbuf *buf)
{
    int ret = 0;
    switch (buf->cmd) {
    case ETHERNET_CMD_MACADDR:
        memcpy(my_macaddr, buf->option.common.macaddr.addr, MACADDR_SIZE);
        buf->cmd = ARP_CMD_MACADDR;
        kz_send(MSGBOX_ID_ARPPROC, 0, (char *)buf);
        initialized++;
        ret = 1;
        break;
    case ETHERNET_CMD_RECV:
        ret = ethernet_recv(buf);
        break;
    case ETHERNET_CMD_SEND:
        ret = ethernet_send(buf);
        break;
    default:
        break;
    }
    return ret;
}