⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 arp.lst

📁 ENC system full - ENC28J60
💻 LST
📖 第 1 页 / 共 3 页
字号:
   1               		.file	"arp.c"
   2               	__SREG__ = 0x3f
   3               	__SP_H__ = 0x3e
   4               	__SP_L__ = 0x3d
   5               	__CCP__  = 0x34
   6               	__tmp_reg__ = 0
   7               	__zero_reg__ = 1
   8               		.global __do_copy_data
   9               		.global __do_clear_bss
  11               		.text
  12               	.Ltext0:
 116               	.global	arp_init
 118               	arp_init:
   1:net/arp.c     **** /*
   2:net/arp.c     **** ,-----------------------------------------------------------------------------------------.
   3:net/arp.c     **** | net/arp
   4:net/arp.c     **** |-----------------------------------------------------------------------------------------
   5:net/arp.c     **** | this file implements a very basic arp protocol
   6:net/arp.c     **** | - we store the last <ARP_TABLE_SIZE> mac<->ip mapping in an table
   7:net/arp.c     **** | - received arp request & answer with reply
   8:net/arp.c     **** | - send arp request & read replay -> add to table
   9:net/arp.c     **** |
  10:net/arp.c     **** | Author   : Simon Schulz / avr{AT}auctionant.de
  11:net/arp.c     **** |
  12:net/arp.c     **** | 
  13:net/arp.c     **** |
  14:net/arp.c     **** |-----------------------------------------------------------------------------------------
  15:net/arp.c     **** | License:
  16:net/arp.c     **** | This program is free software; you can redistribute it and/or modify it under
  17:net/arp.c     **** | the terms of the GNU General Public License as published by the Free Software
  18:net/arp.c     **** | Foundation; either version 2 of the License, or (at your option) any later
  19:net/arp.c     **** | version.
  20:net/arp.c     **** | This program is distributed in the hope that it will be useful, but
  21:net/arp.c     **** |
  22:net/arp.c     **** | WITHOUT ANY WARRANTY;
  23:net/arp.c     **** |
  24:net/arp.c     **** | without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  25:net/arp.c     **** | PURPOSE. See the GNU General Public License for more details.
  26:net/arp.c     **** |
  27:net/arp.c     **** | You should have received a copy of the GNU General Public License along with
  28:net/arp.c     **** | this program; if not, write to the Free Software Foundation, Inc., 51
  29:net/arp.c     **** | Franklin St, Fifth Floor, Boston, MA 02110, USA
  30:net/arp.c     **** |
  31:net/arp.c     **** | http://www.gnu.de/gpl-ger.html
  32:net/arp.c     **** `-----------------------------------------------------------------------------------------*/
  33:net/arp.c     **** 
  34:net/arp.c     **** #include "arp.h"
  35:net/arp.c     **** #include "net/mynic.h"
  36:net/arp.c     **** 
  37:net/arp.c     **** //ACTIVATE DEBUG by editing this file:
  38:net/arp.c     **** #include "debug.h"
  39:net/arp.c     **** 
  40:net/arp.c     **** struct arp_entry arp_table[ARP_TABLE_SIZE];
  41:net/arp.c     **** volatile int arp_table_pointer;
  42:net/arp.c     **** 
  43:net/arp.c     **** //param initialise arp table:
  44:net/arp.c     **** void arp_init(void){
 119               	BB1
 120               	.LM0:
 121               	.LFBB1:
 122               	/* prologue: function */
 123               	/* frame size = 0 */
 124               	.LBB8:
  45:net/arp.c     **** +){
  46:net/arp.c     **** 		arp_table[i].ip  = 0;
 125               	n	68,0,46,.LM1-.LFBB1
 126               	.LM1:
 127 0000 1092 0000 		sts arp_table,__zero_reg__
 128 0004 1092 0000 		sts (arp_table)+1,__zero_reg__
 129 0008 1092 0000 		sts (arp_table)+2,__zero_reg__
 130 000c 1092 0000 		sts (arp_table)+3,__zero_reg__
 131 0010 1092 0000 		sts arp_table+10,__zero_reg__
 132 0014 1092 0000 		sts (arp_table+10)+1,__zero_reg__
 133 0018 1092 0000 		sts (arp_table+10)+2,__zero_reg__
 134 001c 1092 0000 		sts (arp_table+10)+3,__zero_reg__
 135 0020 1092 0000 		sts arp_table+20,__zero_reg__
 136 0024 1092 0000 		sts (arp_table+20)+1,__zero_reg__
 137 0028 1092 0000 		sts (arp_table+20)+2,__zero_reg__
 138 002c 1092 0000 		sts (arp_table+20)+3,__zero_reg__
 139 0030 1092 0000 		sts arp_table+30,__zero_reg__
 140 0034 1092 0000 		sts (arp_table+30)+1,__zero_reg__
 141 0038 1092 0000 		sts (arp_table+30)+2,__zero_reg__
 142 003c 1092 0000 		sts (arp_table+30)+3,__zero_reg__
 143               	.LBE8:
  47:net/arp.c     **** //arp_table[i].ttl = 0;
  48:net/arp.c     **** 	}
  49:net/arp.c     **** 	arp_table_pointer = 0;
 144               	2-.LFBB1
 145               	.LM2:
 146 0040 1092 0000 		sts (arp_table_pointer)+1,__zero_reg__
 147 0044 1092 0000 		sts arp_table_pointer,__zero_reg__
 148               	/* epilogue start */
  50:net/arp.c     **** //decode arp packet & send reply
 149               	bn	68,0,50,.LM3-.LFBB1
 150               	.LM3:
 151 0048 0895      		ret
 153               	.Lscope1:
 157               	.global	arp_add_mac2ip
 159               	arp_add_mac2ip:
  51:net/arp.c     **** oid arp_packet_in(unsigned char *buffer, unsigned int len){
  52:net/arp.c     **** 	uint32_t src_ip;
  53:net/arp.c     **** 	uint32_t dst_ip;
  54:net/arp.c     **** 	int pos;
  55:net/arp.c     **** 	unsigned char c;
  56:net/arp.c     **** 
  57:net/arp.c     **** 	src_ip = nic_buffer_to_ip(&buffer[ARP_POS_SRC_IP]);
  58:net/arp.c     **** 	dst_ip = nic_buffer_to_ip(&buffer[ARP_POS_DST_IP]);
  59:net/arp.c     **** 
  60:net/arp.c     **** 	//is this an arp request ?
  61:net/arp.c     **** 	if (nic_buffer_to_unsigned_int(buffer) == ARP_OP_REQUEST){
  62:net/arp.c     **** 		//is this arp request for us ?
  63:net/arp.c     **** 		if (dst_ip == nic_ip){
  64:net/arp.c     **** 			//yes -> send ARP REPLY:
  65:net/arp.c     **** 			//reuse buffer for the reply !!!
  66:net/arp.c     **** 			#if ARP_DEBUG
  67:net/arp.c     **** 			softuart_puts_progmem("ARP : who has ");
  68:net/arp.c     **** 			softuart_put_ip(dst_ip);
  69:net/arp.c     **** 			softuart_puts_progmem(" tell ");
  70:net/arp.c     **** 			softuart_put_ip(src_ip);
  71:net/arp.c     **** 			softuart_putnewline();
  72:net/arp.c     **** 			#endif
  73:net/arp.c     **** 			
  74:net/arp.c     **** 			//get entry pos in arp table.
  75:net/arp.c     **** 			pos = arp_search_by_ip(src_ip);
  76:net/arp.c     **** 
  77:net/arp.c     **** 			if (pos < 0){
  78:net/arp.c     **** 				//ip not found -> get next insert id:
  79:net/arp.c     **** 				pos = arp_table_pointer;
  80:net/arp.c     **** 				
  81:net/arp.c     **** 				//update ringbuffer pointer
  82:net/arp.c     **** 				arp_table_pointer++;
  83:net/arp.c     **** 				if (arp_table_pointer >= ARP_TABLE_SIZE)
  84:net/arp.c     **** 					arp_table_pointer=0; 
  85:net/arp.c     **** 			}
  86:net/arp.c     **** 
  87:net/arp.c     **** 			//already known -> update
  88:net/arp.c     **** 			arp_table[pos].ip = src_ip; //not necessary ...
  89:net/arp.c     **** 			for (c=0; c<6; c++){
  90:net/arp.c     **** 				arp_table[pos].mac[c] = buffer[ARP_POS_SRC_MAC+c];
  91:net/arp.c     **** 			}
  92:net/arp.c     **** 
  93:net/arp.c     **** 			//setup the eth packet:
  94:net/arp.c     **** 			//packet source mac:
  95:net/arp.c     **** 			nic_copy_mac_to_buf(&buffer[6]);
  96:net/arp.c     **** 				
  97:net/arp.c     **** 			//packet target mac:
  98:net/arp.c     **** 			for (c=0; c<6; c++){
  99:net/arp.c     **** 				buffer[c] = buffer[ARP_POS_SRC_MAC+c];
 100:net/arp.c     **** 			}
 101:net/arp.c     **** 
 102:net/arp.c     **** 			//now setup the arp packet:
 103:net/arp.c     **** 			//change OP to REPLY
 104:net/arp.c     **** 			buffer[ARP_POS_OP+0] = ARP_OP_REPLY>>8 & 0xFF;
 105:net/arp.c     **** 			buffer[ARP_POS_OP+1] = ARP_OP_REPLY    & 0xFF;
 106:net/arp.c     **** 			
 107:net/arp.c     **** 			//copy src mac address to dst:
 108:net/arp.c     **** 			for(c=0; c<6; c++){
 109:net/arp.c     **** 				buffer[ARP_POS_DST_MAC+c] = buffer[ARP_POS_SRC_MAC+c];
 110:net/arp.c     **** 			}
 111:net/arp.c     **** 
 112:net/arp.c     **** 			//set src mac to our mac
 113:net/arp.c     **** 			nic_copy_mac_to_buf(&buffer[ARP_POS_SRC_MAC]);
 114:net/arp.c     **** 
 115:net/arp.c     **** 			//setup source ip:
 116:net/arp.c     **** 			nic_ip_to_buffer(&buffer[ARP_POS_SRC_IP], nic_ip);
 117:net/arp.c     **** 			//setup target ip:
 118:net/arp.c     **** 			nic_ip_to_buffer(&buffer[ARP_POS_DST_IP], src_ip);
 119:net/arp.c     **** 
 120:net/arp.c     **** 			//send packet
 121:net/arp.c     **** 			nic_send_packet(buffer, len);
 122:net/arp.c     **** 		}	
 123:net/arp.c     **** 	}else if (nic_buffer_to_unsigned_int(buffer) == ARP_OP_REPLY){
 124:net/arp.c     **** 		//handle ARP REPLY:
 125:net/arp.c     **** 	
 126:net/arp.c     **** 		//is this for us ?
 127:net/arp.c     **** 		if (nic_buffer_to_ip(&buffer[ARP_POS_DST_IP]) == nic_ip){
 128:net/arp.c     **** 			#if ARP_DEBUG
 129:net/arp.c     **** 			softuart_puts_progmem("ARP : got reply for us");
 130:net/arp.c     **** 			softuart_putnewline();
 131:net/arp.c     **** 			#endif
 132:net/arp.c     **** 
 133:net/arp.c     **** 			//if unknown -> add
 134:net/arp.c     **** 			if( arp_search_by_ip(nic_buffer_to_ip(&buffer[ARP_POS_SRC_IP])) == -1)
 135:net/arp.c     **** 				arp_add_mac2ip(&buffer[ARP_POS_SRC_MAC], nic_buffer_to_ip(&buffer[ARP_POS_SRC_IP]));
 136:net/arp.c     **** 		}
 137:net/arp.c     **** 		
 138:net/arp.c     **** 		//show tale
 139:net/arp.c     **** 		//arp_print_table();
 140:net/arp.c     **** 	}
 141:net/arp.c     **** }
 142:net/arp.c     **** 
 143:net/arp.c     **** int arp_add_mac2ip(unsigned char *buffer, unsigned long ip){
 144:net/arp.c     **** 	unsigned char c;
 145:net/arp.c     **** 	int res;
 160               	0,145,.LM4-.LFBB2
 161               	.LM4:
 162               	.LFBB2:
 163 004a CF93      		push r28
 164 004c DF93      		push r29
 165               	/* prologue: function */
 166               	/* frame size = 0 */
 167 004e EC01      		movw r28,r24
 146:net/arp.c     **** ts_progmem(" to mac table");
 147:net/arp.c     **** 	softuart_putnewline();
 148:net/arp.c     **** 	#endif	
 149:net/arp.c     **** 
 150:net/arp.c     **** 	//set ip
 151:net/arp.c     **** 	arp_table[arp_table_pointer].ip = ip;
 152:net/arp.c     **** 	
 153:net/arp.c     **** 	//set mac:
 154:net/arp.c     **** 	for (c=0; c<6; c++){
 155:net/arp.c     **** 		arp_table[arp_table_pointer].mac[c] = buffer[c];
 156:net/arp.c     **** 	}
 157:net/arp.c     **** 
 168               	68,0,157,.LM5-.LFBB2
 169               	.LM5:
 170 0050 8091 0000 		lds r24,arp_table_pointer
 171 0054 9091 0000 		lds r25,(arp_table_pointer)+1
 172 0058 FC01      		movw r30,r24
 173 005a B3E0      		ldi r27,3
 174 005c EE0F      	1:	lsl r30
 175 005e FF1F      		rol r31
 176 0060 BA95      		dec r27
 177 0062 01F4      		brne 1b
 178 0064 880F      		lsl r24
 179 0066 991F      		rol r25
 180 0068 E80F      		add r30,r24
 181 006a F91F      		adc r31,r25
 182 006c E050      		subi r30,lo8(-(arp_table))
 183 006e F040      		sbci r31,hi8(-(arp_table))
 184 0070 4083      		st Z,r20
 185 0072 5183      		std Z+1,r21
 186 0074 6283      		std Z+2,r22
 187 0076 7383      		std Z+3,r23
 188 0078 20E0      		ldi r18,lo8(0)
 189 007a 30E0      		ldi r19,hi8(0)
 190               	.L4:
 158:net/arp.c     ****  ip;
 159:net/arp.c     **** 	
 160:net/arp.c     **** 	//set mac:
 161:net/arp.c     **** 	for (c=0; c<6; c++){
 191               	LFBB2
 192               	.LM6:
 193 007c 8091 0000 		lds r24,arp_table_pointer
 194 0080 9091 0000 		lds r25,(arp_table_pointer)+1
 195 0084 FC01      		movw r30,r24
 196 0086 53E0      		ldi r21,3
 197 0088 EE0F      	1:	lsl r30
 198 008a FF1F      		rol r31
 199 008c 5A95      		dec r21
 200 008e 01F4      		brne 1b
 201 0090 880F      		lsl r24
 202 0092 991F      		rol r25
 203 0094 E80F      		add r30,r24
 204 0096 F91F      		adc r31,r25
 205 0098 E050      		subi r30,lo8(-(arp_table))
 206 009a F040      		sbci r31,hi8(-(arp_table))
 207 009c E20F      		add r30,r18
 208 009e F31F      		adc r31,r19
 209 00a0 DE01      		movw r26,r28
 210 00a2 A20F      		add r26,r18
 211 00a4 B31F      		adc r27,r19
 212 00a6 8C91      		ld r24,X
 213 00a8 8483      		std Z+4,r24
 214 00aa 2F5F      		subi r18,lo8(-(1))
 215 00ac 3F4F      		sbci r19,hi8(-(1))
 217               	.LM7:
 218 00ae 2630      		cpi r18,6
 219 00b0 3105      		cpc r19,__zero_reg__
 220 00b2 01F4      		brne .L4
 162:net/arp.c     **** ();
 163:net/arp.c     **** 	#endif	
 164:net/arp.c     **** 
 221               	LM8:
 222               		lds r18,arp_table_pointer
 223 00b4 2091 0000 		lds r19,(arp_table_pointer)+1
 165:net/arp.c     **** ip ");
 166:net/arp.c     **** 	softuart_put_ip(ip);
 167:net/arp.c     **** 	softuart_puts_progmem(" to mac table");
 225               	:
 226               		lds r24,arp_table_pointer
 227 00bc 8091 0000 		lds r25,(arp_table_pointer)+1
 228 00c0 9091 0000 		adiw r24,1
 229 00c4 0196      		sts (arp_table_pointer)+1,r25
 230 00c6 9093 0000 		sts arp_table_pointer,r24
 168:net/arp.c     **** 	softuart_puts_progmem("ARP : adding ip ");
 232               		lds r24,arp_table_pointer
 233               		lds r25,(arp_table_pointer)+1
 234 00ce 8091 0000 		sbiw r24,4
 235 00d2 9091 0000 		brlt .L5
 237 00d8 04F0      	.LM11:
 169:net/arp.c     ****  unsigned long ip){
 238               	arp_table_pointer)+1,__zero_reg__
 239               		sts arp_table_pointer,__zero_reg__
 240 00da 1092 0000 	.L5:
 242               	.LM12:
 170:net/arp.c     **** );
 171:net/arp.c     **** 		}
 172:net/arp.c     **** 		
 243               	 r24,r18
 244               	/* epilogue start */
 245 00e2 C901      		pop r29
 246               		pop r28
 247 00e4 DF91      		ret
 252               	.Lscope2:
 254               	.global	arp_print_table
 256               	arp_print_table:
 258               	.LM13:
 173:net/arp.c     **** RP_POS_SRC_IP])) == -1)
 174:net/arp.c     **** 				arp_add_mac2ip(&buffer[ARP_POS_SRC_MAC], nic_buffer_to_ip(&buffer[ARP_POS_SRC_IP]));

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -