Example #1
0
void nicInit(void)
{
	uint8_t macaddr[6];

	W51_init();
	macaddr[0] = ETHADDR0;
	macaddr[1] = ETHADDR1;
	macaddr[2] = ETHADDR2;
	macaddr[3] = ETHADDR3;
	macaddr[4] = ETHADDR4;
	macaddr[5] = ETHADDR5;
	nicSetMacAddress(macaddr);
	socket(MACRAW_SOCKET, W5100_SKT_MR_MACRAW, 0x00, 0x00);
}
Example #2
0
int main(void){
	init_uart();
	
	uint16_t packet_length, rxstat;
	
	uart_puts("beginning startup procedure\r\n");    
	/*ENC Initialisieren*/
	enc28j60Init();
	uart_puts("initialization finished\r\n");
	//Mac Adresse setzen(stack.h, dort wird auch die Ip festgelegt)
	nicSetMacAddress(mymac);
	uart_puts("mac address set\r\n");
	/*	Leds konfigurieren
		LEDA : Link status
		LEDB : Receive activity
		Led Settings : enc28j60 datasheet, page 11*/
	
	enc28j60PhyWrite(0x14,0b0000010000100000);
	
	/*	Leds konfigurieren
		LEDA : Link status
		LEDB : Blink Fast
		Led Settings : enc28j60 datasheet, page 11
		Auskommentieren, wenn mans lieber blinken sieht ;-)		*/
	
	//enc28j60PhyWrite(0x14,0b0000010000100000);

	
	while(1) {
		// Buffer des Enc's abhohlen :-)
		packet_length = enc28j60PacketReceive(BUFFER_SIZE, buffer, &rxstat);

		// Wenn ein Packet angekommen ist, ist packet_length =! 0
		if(packet_length) {
			packet_length -= 4;
			struct ETH_frame *frame = (struct ETH_frame *) buffer;
			frame->type_length = ntohs(frame->type_length);
			// arping uses unicast after the first by default, but we don't care because performance
			if(/*(*/rxstat&BROADCAST_BIT /*|| compare_macs(frame->destMac, (uint8_t *) mymac))*/ && frame->type_length == TYPE_ARP) {
				struct ARP_packet *arp_pkt = (struct ARP_packet *) frame->payload;
				if(compare_ips(arp_pkt->destIp, (uint8_t *) myip)) {
					arp(packet_length, buffer);
				}
				continue;
			}

			if(compare_macs(frame->destMac, (uint8_t *) mymac)) {
				if(frame->type_length == TYPE_IP4) {
					struct IP_segment *ip = (struct IP_segment *) frame->payload;
					if(ip->protocol == TYPE_ICMP) {
						icmp(packet_length, buffer);
						continue;
					} else if(ip->protocol == TYPE_UDP) {
						struct UDP_packet *pkt = (struct UDP_packet *) ip->payload;
						pkt->destPort = pkt->destPort;
						pkt->sourcePort = pkt->sourcePort;

						if(pkt->destPort == ntohs(7)) {
							udp(htons(pkt->length), buffer);
							continue;
						}

						if(pkt->destPort == ntohs(85) && compare(pkt->data, "test")) {
							printinbuffer(pkt->data, "Test erfolgreich!", TERMINATE);
							udp(18, buffer);
							continue;
						}

						if(pkt->destPort == ntohs(86)) {
							uart_puts((char*) pkt->data);
							uart_puts("\r\n");
							continue;
						}
					} else if(ip->protocol == TYPE_TCP) {
						uart_puts("received tcp package!\r\n");
						#if DEBUG
						hexdump(ip, 256);
						#endif
						struct TCP_segment *tcp = (struct TCP_segment *) ip->payload;
						if(tcp->sourcePort == ntohs(7)) {

						}
					}
				}
			}
		}
	}
	
	return 1;
}
Example #3
0
int main(void)
{
  unsigned int num_bytes                             ;
  WDTCTL   = WDTPW + WDTHOLD                         ;
  Init_CLK()                                         ;
  Init_PSPI()                                        ;
 
  P9DIR   |= IrDA_OUT;
  P9OUT   &=~IrDA_OUT;
  
  MAIN_POWER_ON                                      ;
/*  
  for(;;){
  for(i=0;i<40;i++)
  {
  P9OUT   |= IrDA_OUT;
  __delay_cycles(20000);
  P9OUT   &=~IrDA_OUT;
  __delay_cycles(20000);  
  
  }
  __delay_cycles(5000000);
  }
  
*/  
  
/*  
  for(;;){
  for(j=0;j<40;j++){
  for(i=0;i<50;i++)
  {
  P9OUT   &=~IrDA_OUT;
  __delay_cycles(270);  
  P9OUT   |= IrDA_OUT;
  __delay_cycles(270);
  }
  __delay_cycles(20000);
  }
  __delay_cycles(5000000);
  }
*/  
  myNode.node.ip     = IP4_ADDR(103,1,168,192)       ;
  myNode.node.mask   = IP4_ADDR(0,255,255,255)       ;
  myNode.node.gate   = IP4_ADDR(1,1,168,192)         ;
  myNode.node.mac[0] = 0x00                          ;
  myNode.node.mac[1] = 0x60                          ;
  myNode.node.mac[2] = 0x97                          ;
  myNode.node.mac[3] = 0x48                          ;
  myNode.node.mac[4] = 0xF4                          ;
  myNode.node.mac[5] = 0xAB                          ;
  encInit()                                          ;
  nicSetMacAddress()                                 ;
  encPhyWrite(0x14,0x0470)                           ;
  arptab_init()                                      ;
  ENC_SLEEP() ;// TEST
  ENC_WAKEUP();// TEST
  
  while(1)
  {
    num_bytes = encPacketReceive(&rxdnetbuf);
    if(num_bytes > 0)
    {
      if(rxdnetbuf.etherframe.protocal==ARP_PACKET)    // 收到一个AR请求包
      {			
	if(rxdnetbuf.arpframe.operation==0x0100)
	  arp_answer()                               ; // ARP request,处理arp数据包
	else if(rxdnetbuf.arpframe.operation==0x0200)
	  arp_process()                              ; // ARP answer
      }
      else if(   (rxdnetbuf.etherframe.protocal == IP_PACKET)	// 收到一个IP包
	     && ((rxdnetbuf.ipframe.verandihl&0xf0) == 0x40)	// IP V4
             && (rxdnetbuf.ipframe.destip[0] == myNode.nodebytes.ipbytes[0])
	     && (rxdnetbuf.ipframe.destip[1] == myNode.nodebytes.ipbytes[1])
	     && (rxdnetbuf.ipframe.destip[2] == myNode.nodebytes.ipbytes[2])
             && (rxdnetbuf.ipframe.destip[3] == myNode.nodebytes.ipbytes[3]))	
      {
        arp_ip_mac()                                 ;
	if(rxdnetbuf.ipframe.protocal == 1)		//	ICMP
	{
          if(rxdnetbuf.icmpframe.type == 8)		//	ECHO
            ping_answer()                            ;
        }
        else if(rxdnetbuf.ipframe.protocal == 17)	//	UDP
        {
//          net_udp_rcv()                              ;
          _NOP();
//          Clear_UPD_Buf()                            ;
        }
/*        
	else if(rxdnetbuf.ipframe.protocal == 6)	//	TCP
          tcp_rcve(&rxdnetbuf)                       ;
        updatearptab()                               ;
*/        
      }
    }
  }
}