00001 /******************************************************************************* 00002 enc28j60_eth.c: Linková vrstva modelu TCP/IP 00003 Copyright (C) 2010 Brno University of Technology, 00004 Faculty of Information Technology 00005 Author(s): Martin Musil <xmusil34 AT fit.vutbr.cz> 00006 00007 LICENSE TERMS 00008 00009 Redistribution and use in source and binary forms, with or without 00010 modification, are permitted provided that the following conditions 00011 are met: 00012 1. Redistributions of source code must retain the above copyright 00013 notice, this list of conditions and the following disclaimer. 00014 2. Redistributions in binary form must reproduce the above copyright 00015 notice, this list of conditions and the following disclaimer in 00016 the documentation and/or other materials provided with the 00017 distribution. 00018 3. All advertising materials mentioning features or use of this software 00019 or firmware must display the following acknowledgement: 00020 00021 This product includes software developed by the University of 00022 Technology, Faculty of Information Technology, Brno and its 00023 contributors. 00024 00025 4. Neither the name of the Company nor the names of its contributors 00026 may be used to endorse or promote products derived from this 00027 software without specific prior written permission. 00028 00029 This software or firmware is provided ``as is'', and any express or implied 00030 warranties, including, but not limited to, the implied warranties of 00031 merchantability and fitness for a particular purpose are disclaimed. 00032 In no event shall the company or contributors be liable for any 00033 direct, indirect, incidental, special, exemplary, or consequential 00034 damages (including, but not limited to, procurement of substitute 00035 goods or services; loss of use, data, or profits; or business 00036 interruption) however caused and on any theory of liability, whether 00037 in contract, strict liability, or tort (including negligence or 00038 otherwise) arising in any way out of the use of this software, even 00039 if advised of the possibility of such damage. 00040 00041 $Id$ 00042 00043 *******************************************************************************/ 00044 #include "enc28j60_ip.h" 00045 #include "enc28j60_arp.h" 00046 #include "enc28j60_eth.h" 00047 #include "enc28j60_spi.h" 00048 00049 #include "enc28j60_string.h" 00050 00051 extern unsigned int tx_end_ptr; 00052 extern char enc_initialized; 00053 //defaultni MAC adresa 00054 unsigned char local_mac[MAC_LEN] = {0x00,0x23,0x8B,0x6B,0x38,0x64}; 00055 unsigned char broadcast_mac[MAC_LEN] = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}; 00056 00057 00061 void ENC28J60_idle(){ 00062 00063 if(read_reg8(EIR,NO_DUMMY) & EIR_PKTIF){ //paket v rx bufferu 00064 eth_recv(); 00065 } 00066 00067 return; 00068 } 00069 00070 00074 void eth_recv(){ 00075 00076 struct eth_h eth_header; 00077 00078 if(rx_init() < 0){ 00079 return; 00080 } 00081 00082 rx_read(ð_header, ETH_HEADER_LEN); 00083 00084 switch(eth_header.type_len){ 00085 00086 case HTONS(ETH_PROTO_IP): 00087 ip_recv(); 00088 break; 00089 00090 case HTONS(ETH_PROTO_ARP): 00091 arp_recv(); 00092 break; 00093 } 00094 00095 rx_free(); 00096 00097 return; 00098 } 00099 00103 char eth_send(unsigned char* dest_addr,unsigned int type){ 00104 00105 struct eth_h eth_header; 00106 00107 enc_memcpy(ð_header.dest_addr, dest_addr, MAC_LEN); 00108 enc_memcpy(ð_header.src_addr, &local_mac, MAC_LEN); 00109 eth_header.type_len = HTONS(type); 00110 00111 tx_seek(CTRL); 00112 tx_putc(CTRL_BYTE); 00113 tx_write(ð_header,ETH_HEADER_LEN); 00114 00115 return tx_send(); 00116 } 00117 00122 inline char set_mac(unsigned char* mac_ptr){ 00123 00124 if(enc_initialized == 0){ 00125 enc_memcpy(&local_mac,mac_ptr, MAC_LEN); 00126 return 1; 00127 } 00128 return 0; 00129 } 00130