martes, 22 de enero de 2013

ethernet

/*-----------------------------------------------------
Author:  --<>
Date: 28/Oct/2012
Description:

-----------------------------------------------------*/
#include <ethernet/ip_arp_udp.h>
#define BUFFER_MAX    224

static u8 buf[BUFFER_MAX+1]; // the received message
u16 len; // the length of the received messages

void setup() {
 // put your setup code here, to run once:
 // this is the enc28j60 ip address
 u8 myip[4] = { 192, 168, 2, 2 };
 // this is the enc28j60 mac address
 u8 mymac[6] = { 0x02, 0x04, 0x08, 0x10, 0x12, 0x14 };
 init_ip_arp_udp (mymac, myip);
 enc28j60Init (mymac);
 }

void loop() {
 len = enc28j60PacketReceive(BUFFER_MAX, buf);
 CDC.printf("received! len: %d\n", len);
   
 if (len == 0) {
  return;
  }
 if(eth_type_is_arp_and_my_ip(buf, len)) {
  make_arp_answer_from_request(buf, len);
  return;
  }
 if(eth_type_is_ip_and_my_ip(buf, len)==0) {
                return;
                }

 if(buf[IP_PROTO_P]==IP_PROTO_ICMP_V && buf[ICMP_TYPE_P]==ICMP_TYPE_ECHOREQUEST_V) {
  // the ping reply
  make_echo_reply_from_request(buf, len);
  return;
  }
 }

No hay comentarios:

Publicar un comentario