Subversion Repositories Kolibri OS

Rev

Rev 1200 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1200 Rev 1206
Line 15... Line 15...
15
;;             Version 2, June 1991                                ;;
15
;;             Version 2, June 1991                                ;;
16
;;                                                                 ;;
16
;;                                                                 ;;
17
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 18... Line 18...
18
 
18
 
Line 19... Line 19...
19
 
19
 
20
$Revision: 983 $
20
$Revision: 1206 $
21
 
21
 
22
 
22
 
Line 23... Line 23...
23
ARP_NO_ENTRY		equ  0
23
ARP_NO_ENTRY		equ  0
24
ARP_VALID_MAPPING	equ  1
24
ARP_VALID_MAPPING	equ  1
Line 25... Line 25...
25
ARP_AWAITING_RESPONSE	equ  2
25
ARP_AWAITING_RESPONSE	equ  2
Line 26... Line 26...
26
ARP_RESPONSE_TIMEOUT	equ  3
26
ARP_RESPONSE_TIMEOUT	equ  3
27
 
27
 
Line 133... Line 133...
133
 
133
 
Line 134... Line 134...
134
	xor	edx, edx ; TODO: find device num in edx
134
	xor	edx, edx ; TODO: find device num in edx
135
 
135
 
-
 
136
	mov	ebx, [IP_LIST+edx]
136
	mov	ebx, [IP_LIST+edx]
137
	and	ebx, [SUBNET_LIST+edx]
137
	and	ebx, [SUBNET_LIST+edx]
138
 
-
 
139
	mov	ecx, eax
138
	mov	ecx, eax
140
	and	ecx, [SUBNET_LIST+edx]
139
	and	ecx, [SUBNET_LIST+edx]
141
 
Line 140... Line 142...
140
	cmp	ecx, ebx
142
	cmp	ecx, ebx
141
	je	.local
143
	je	.local
Line 142... Line 144...
142
 
144
 
143
	mov	eax, [GATEWAY_LIST+edx]
145
	mov	eax, [GATEWAY_LIST+edx]
144
	DEBUGF 1,"requested IP is not on subnet, using gateway\n"
146
	DEBUGF 1,"requested IP is not on subnet, using gateway\n"
-
 
147
 
145
 
148
  .local:
146
  .local:
149
   ; try to find it on the list
147
   ; try to find it on the list
150
	mov	ecx, [NumARP]
148
	mov	ecx, [NumARP]
151
	test	ecx, ecx
149
	jz	.not_in_list
152
	jz	.not_in_list
150
	mov	esi, ARPTable + ARP_ENTRY.IP
153
	mov	esi, ARPTable + ARP_ENTRY.IP
151
  .scan_loop:
154
  .scan_loop:
152
	scasd
155
	cmp	[esi], eax
Line 153... Line 156...
153
	jz	.found_it
156
	je	.found_it
Line 175... Line 178...
175
	call	ARP_create_request
178
	call	ARP_create_request
Line 176... Line 179...
176
 
179
 
Line 177... Line 180...
177
	ret
180
	ret
-
 
181
 
178
 
182
  .found_it:
179
  .found_it:
183
	add    esi, ARP_ENTRY.MAC
180
	DEBUGF 1,"Found MAC! (%u-%u-%u-%u-%u-%u)\n",[esi+0]:2,[esi+1]:2,[esi+2]:2,[esi+3]:2,[esi+4]:2,[esi+5]:2
184
	DEBUGF 1,"Found MAC! (%x-%x-%x-%x-%x-%x)\n",[esi+0]:2,[esi+1]:2,[esi+2]:2,[esi+3]:2,[esi+4]:2,[esi+5]:2
Line 181... Line 185...
181
	movzx  eax, word [esi]
185
	movzx  eax, word [esi]
Line 219... Line 223...
219
	mov	di , ETHER_ARP
223
	mov	di , ETHER_ARP
220
	call	ETH_create_Packet
224
	call	ETH_create_Packet
221
	cmp	edi, -1
225
	cmp	edi, -1
222
	je	.exit
226
	je	.exit
Line -... Line 227...
-
 
227
 
-
 
228
	mov	ecx, eax
223
 
229
 
224
	mov	word [edi + ARP_Packet.HardwareType], 0x0100 ;Ethernet
230
	mov	[edi + ARP_Packet.HardwareType], 0x0100 ;Ethernet
225
	mov	word [edi + ARP_Packet.ProtocolType], 0x0008 ;IP
231
	mov	[edi + ARP_Packet.ProtocolType], 0x0008 ;IP
226
	mov	byte [edi + ARP_Packet.HardwareSize], 6   ;MAC-addr length
232
	mov	[edi + ARP_Packet.HardwareSize], 6   ;MAC-addr length
227
	mov	byte [edi + ARP_Packet.ProtocolSize], 4   ;IP-addr length
233
	mov	[edi + ARP_Packet.ProtocolSize], 4   ;IP-addr length
Line 228... Line 234...
228
	mov	word [edi + ARP_Packet.Opcode], ARP_REQ_OPCODE	    ;Request
234
	mov	[edi + ARP_Packet.Opcode], ARP_REQ_OPCODE      ;Request
229
 
235
 
230
	add	edi, ARP_Packet.SenderMAC			; sendermac
236
	add	edi, ARP_Packet.SenderMAC			; sendermac
231
	lea	esi, [edx + ETH_DEVICE.mac]			;
237
	lea	esi, [ebx + ETH_DEVICE.mac]			;
232
	movsw							;
-
 
233
	movsd							;
238
	movsw							;
234
 
239
	movsd							;
235
	pop	eax
-
 
236
	stosd							;
240
	pop	eax						;
237
 
241
	stosd							;
238
	xor	eax, eax					; destmac
242
	mov	eax, -1 					; destmac
239
	movsw							;
-
 
240
	movsw							;
243
	stosd							;
241
 
244
	stosw							;
242
	pop	eax
-
 
243
	movsd							;
-
 
244
 
-
 
245
	DEBUGF 1,"ARP Packet for device %x created successfully\n", edx
-
 
Line 246... Line 245...
246
 
245
	pop	eax
Line 247... Line 246...
247
	call	esi
246
	stosd							;
-
 
247
 
Line 248... Line 248...
248
 
248
	DEBUGF 1,"ARP Packet for device %x created successfully\n", ebx
249
	inc	[ARP_PACKETS_TX+4*edi]
249
 
250
 
250
	push	edx ecx
251
	ret
251
	jmp	ETH_Sender
Line 276... Line 276...
276
 
276
 
Line 277... Line 277...
277
	mov	ebx, ARPTable
277
	mov	ebx, ARPTable
Line 278... Line 278...
278
 
278
 
279
.timer_loop:
-
 
280
 
279
.timer_loop:
Line 281... Line 280...
281
	movsx	esi, word [ebx + ARP_ENTRY.TTL]
280
 
282
	cmp	esi, 0xFFFFFFFF
281
	cmp	[ebx + ARP_ENTRY.TTL], 0xFFFF
Line 283... Line 282...
283
	je	.timer_loop_end  ;if TTL==0xFFFF then it's static entry
282
	je	.timer_loop_end  ;if TTL==0xFFFF then it's static entry
284
 
283
 
285
	test	esi, esi
284
	cmp	[ebx + ARP_ENTRY.TTL], 0
286
	jnz	.timer_loop_end_with_dec  ;if TTL!=0
285
	jnz	.timer_loop_end_with_dec  ;if TTL!=0
287
 
286
 
Line 288... Line 287...
288
	; Ok, TTL is 0
287
	; Ok, TTL is 0
289
	;if Status==AWAITING_RESPONSE and TTL==0
288
	;if Status==AWAITING_RESPONSE and TTL==0
290
	;then we have to change it to ARP_RESPONSE_TIMEOUT
289
	;then we have to change it to ARP_RESPONSE_TIMEOUT
Line 291... Line 290...
291
	cmp	word [ebx + ARP_ENTRY.Status], ARP_AWAITING_RESPONSE
290
	cmp	[ebx + ARP_ENTRY.Status], ARP_AWAITING_RESPONSE
292
	jne	@f
291
	jne	@f
293
 
292
 
294
	mov	word [ebx + ARP_ENTRY.Status], ARP_RESPONSE_TIMEOUT
293
	mov	[ebx + ARP_ENTRY.Status], ARP_RESPONSE_TIMEOUT
295
	mov	word [ebx + ARP_ENTRY.TTL], word 0x000A   ;10 sec
294
	mov	[ebx + ARP_ENTRY.TTL], word 0x000A   ;10 sec
Line -... Line 295...
-
 
295
	jmp	.timer_loop_end
296
	jmp	.timer_loop_end
296
 
-
 
297
  @@:
Line 297... Line 298...
297
 
298
	;if TTL==0 and Status==VALID_MAPPING, we have to delete it
Line 298... Line 299...
298
  @@:
299
	;if TTL==0 and Status==RESPONSE_TIMEOUT, delete too
Line 299... Line 300...
299
	;if TTL==0 and Status==VALID_MAPPING, we have to delete it
300
	mov	esi, [NumARP]
Line 300... Line 301...
300
	;if TTL==0 and Status==RESPONSE_TIMEOUT, delete too
301
	sub	esi, ecx	  ;esi=index of entry, will be deleted
Line 301... Line 302...
301
	mov	esi, dword[NumARP]
302
 
302
	sub	esi, ecx	  ;esi=index of entry, will be deleted
303
	push	ebx ecx
Line 336... Line 337...
336
; TODO: use a mutex
337
; TODO: use a mutex
Line 337... Line 338...
337
 
338
 
338
align 4
339
align 4
Line -... Line 340...
-
 
340
ARP_add_entry:
-
 
341
 
339
ARP_add_entry:
342
	DEBUGF 1,"ARP add entry: "
340
 
343
 
341
	mov	ecx, [NumARP]
344
	mov	ecx, [NumARP]
Line 342... Line 345...
342
	test	ecx, ecx
345
	test	ecx, ecx
Line 353... Line 356...
353
	jne	.maybe_next
356
	jne	.maybe_next
Line 354... Line 357...
354
 
357
 
355
	cmp	dword[esi + ARP_ENTRY.TTL], 0xFFFF ; static entry
358
	cmp	dword[esi + ARP_ENTRY.TTL], 0xFFFF ; static entry
356
	jne	.notstatic
359
	jne	.notstatic
357
	cmp	dword[esp + ARP_ENTRY.TTL], 0xFFFF
360
	cmp	dword[esp + ARP_ENTRY.TTL], 0xFFFF
358
	jne	.exit
361
	jne	.error
Line 359... Line 362...
359
.notstatic:
362
.notstatic:
360
 
363
 
361
	mov	ebx, [NumARP]
364
	mov	ebx, [NumARP]
Line 367... Line 370...
367
	add	esi, ARP_ENTRY.size
370
	add	esi, ARP_ENTRY.size
368
	loop	.loop
371
	loop	.loop
Line 369... Line 372...
369
 
372
 
370
	mov	ecx, [NumARP]
373
	mov	ecx, [NumARP]
371
	cmp	ecx, ARP_TABLE_SIZE
374
	cmp	ecx, ARP_TABLE_SIZE
Line 372... Line 375...
372
	jge	.full
375
	jge	.error
373
 
-
 
374
.add:
376
 
375
 
377
.add:
376
	push	ecx
378
	push	ecx
377
	imul	ecx, ARP_ENTRY.size
379
	imul	ecx, ARP_ENTRY.size
378
	lea	edi, [ecx + ARPTable]
380
	lea	edi, [ecx + ARPTable]
379
	lea	esi, [esp + 4]
381
	lea	esi, [esp + 8]
Line 380... Line 382...
380
	mov	ecx, ARP_ENTRY.size/2
382
	mov	ecx, ARP_ENTRY.size/2
381
	repz	movsw
383
	repz	movsw
Line 382... Line 384...
382
 
384
 
-
 
385
	inc	[NumARP]
-
 
386
	pop	eax
-
 
387
 
-
 
388
.exit:
Line 383... Line -...
383
	inc	[NumARP]
-
 
384
	pop	eax
389
	pop	ebx    ; return addr
Line 385... Line 390...
385
 
390
	add	esp, ARP_ENTRY.size
Line 386... Line 391...
386
.exit:
391
	DEBUGF 1,"Exiting\n"
387
 
392
	jmp	ebx
Line 388... Line -...
388
	add	esp, 14
-
 
389
	ret
393
 
390
 
394
.error:
391
.full:
395
 
392
 
396
	DEBUGF 1,"error! \n"
393
	mov	eax, -1
397
 
Line 405... Line 409...
405
;---------------------------------------------------------------------------
409
;---------------------------------------------------------------------------
Line 406... Line 410...
406
 
410
 
407
align 4
411
align 4
Line -... Line 412...
-
 
412
ARP_del_entry:
-
 
413
 
-
 
414
	DEBUGF 1,"ARP del entry %u, total entrys: %u\n", esi, [NumARP]
-
 
415
 
-
 
416
	cmp	esi, [NumARP]
-
 
417
	jge	.error
-
 
418
 
408
ARP_del_entry:
419
	DEBUGF 1,"deleting the entry..\n"
Line 409... Line 420...
409
 
420
 
410
	imul	esi, ARP_ENTRY.size
421
	imul	esi, ARP_ENTRY.size
Line 411... Line 422...
411
 
422
 
412
	mov	ecx, (ARP_TABLE_SIZE - 1) * ARP_ENTRY.size
423
	mov	ecx, (ARP_TABLE_SIZE - 1) * ARP_ENTRY.size
Line 413... Line 424...
413
	sub	ecx, esi
424
	sub	ecx, esi
414
 
-
 
415
	lea	edi, [ebx + esi]	    ;edi=ptr to entry that should be deleted
425
 
Line 416... Line 426...
416
	lea	esi, [edi + ARP_ENTRY.size] ;esi=ptr to next entry
426
	lea	edi, [ebx + esi]	    ;edi=ptr to entry that should be deleted
-
 
427
	lea	esi, [edi + ARP_ENTRY.size] ;esi=ptr to next entry
417
 
428
 
Line 447... Line 458...
447
	jl	.exit
458
	jl	.exit
Line 448... Line 459...
448
 
459
 
449
	cmp	word [edx + ARP_Packet.Opcode], ARP_REP_OPCODE	; Is this a reply packet?
460
	cmp	word [edx + ARP_Packet.Opcode], ARP_REP_OPCODE	; Is this a reply packet?
Line -... Line 461...
-
 
461
	jne	.maybe_request
-
 
462
 
-
 
463
	DEBUGF	1,"ARP_Handler - it's a reply packet from %u.%u.%u.%u\n",\
450
	jne	.maybe_request
464
	[edx + ARP_Packet.SenderIP]:1,[edx + ARP_Packet.SenderIP+1]:1,[edx + ARP_Packet.SenderIP+2]:1,[edx + ARP_Packet.SenderIP+3]:1,
451
 
465
 
452
	mov	ecx, [NumARP]
466
	mov	ecx, [NumARP]
Line 453... Line -...
453
	test	ecx, ecx
-
 
454
	jz	.exit
467
	test	ecx, ecx
455
 
468
	jz	.exit
Line 456... Line 469...
456
	mov	eax, [esp]
469
 
457
	mov	eax, [eax + ARP_Packet.SenderIP]
470
	mov	eax, [edx + ARP_Packet.SenderIP]
458
	mov	esi, ARPTable+ARP_ENTRY.IP
471
	mov	esi, ARPTable+ARP_ENTRY.IP
459
 
472
 
460
  .loop:
473
  .loop:
Line 461... Line 474...
461
	scasd
474
	cmp	[esi], eax
Line 462... Line 475...
462
	jz	.gotit
475
	je	.gotit
-
 
476
	add	esi, ARP_ENTRY.size
-
 
477
	loop	.loop
-
 
478
 
463
	add	esi, ARP_ENTRY.size-4
479
	jmp	.exit
464
	loop	.loop
480
 
Line 465... Line -...
465
 
-
 
466
	jmp	.exit
481
  .gotit:
Line -... Line 482...
-
 
482
 
467
 
483
	DEBUGF	1,"ARP_Handler - found matching entry\n"
-
 
484
 
468
  .gotit:
485
	cmp	[esi+ARP_ENTRY.Status], 0x0300	 ;if it is a static entry, dont touch it
469
	cmp	[esi-4+ARP_ENTRY.Status], 0x0300   ;if it is a static entry, dont touch it
486
	je	.exit
470
	je	.exit
487
 
471
 
488
	DEBUGF	1,"ARP_Handler - updating entry\n"
Line 472... Line 489...
472
	mov	[esi-4+ARP_ENTRY.Status], ARP_VALID_MAPPING
489
 
Line 473... Line 490...
473
	mov	[esi+ARP_ENTRY.TTL-4], ARP_ENTRY_TTL
490
	mov	[esi+ARP_ENTRY.Status], ARP_VALID_MAPPING
Line 487... Line 504...
487
  .maybe_request:
504
  .maybe_request:
488
	cmp	word [edx + ARP_Packet.Opcode], ARP_REQ_OPCODE	; Is this a request packet?
505
	cmp	word [edx + ARP_Packet.Opcode], ARP_REQ_OPCODE	; Is this a request packet?
489
	jne	.exit
506
	jne	.exit
Line 490... Line 507...
490
 
507
 
491
	call	ETH_struc2dev
508
	call	ETH_struc2dev
492
	DEBUGF	1,"ARP Packet came from device: %u\n", edi
509
	DEBUGF	1,"ARP Request packet through device: %u\n", edi
493
	inc	[ARP_PACKETS_RX+4*edi]
510
	inc	[ARP_PACKETS_RX+4*edi]
494
	cmp	edi, -1
511
	cmp	edi, -1
Line 495... Line 512...
495
	jz	.exit
512
	jz	.exit
Line 534... Line 551...
534
	movsd
551
	movsd
535
	movsw
552
	movsw
536
;        mov     ax , ETHER_ARP
553
;        mov     ax , ETHER_ARP
537
;        stosw
554
;        stosw
Line -... Line 555...
-
 
555
 
-
 
556
	DEBUGF	1,"ARP_Handler - Sending reply \n"
538
 
557
 
Line 539... Line 558...
539
	jmp	ETH_Sender					; And send it!
558
	jmp	ETH_Sender					; And send it!
540
 
559
 
541
     .exit:
560
     .exit:
Line 542... Line 561...
542
	call	kernel_free
561
	call	kernel_free
543
	add	esp, 4						; pop (balance stack)
562
	add	esp, 4						; pop (balance stack)