Subversion Repositories Kolibri OS

Rev

Rev 1514 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1196 hidnplayr 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                                 ;;
1514 hidnplayr 3
;; Copyright (C) KolibriOS team 2004-2010. All rights reserved.    ;;
1196 hidnplayr 4
;; Distributed under terms of the GNU General Public License       ;;
5
;;                                                                 ;;
6
;;  ARP.INC                                                        ;;
7
;;                                                                 ;;
8
;;  Part of the tcp/ip network stack for KolibriOS                 ;;
9
;;                                                                 ;;
10
;;  Based on the work of [Johnny_B] and [smb]                      ;;
11
;;                                                                 ;;
12
;;    Written by hidnplayr@kolibrios.org                           ;;
13
;;                                                                 ;;
14
;;          GNU GENERAL PUBLIC LICENSE                             ;;
1514 hidnplayr 15
;;             Version 2, June- 1991                                ;;
1196 hidnplayr 16
;;                                                                 ;;
17
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1159 hidnplayr 18
 
1196 hidnplayr 19
 
1206 hidnplayr 20
$Revision: 1519 $
1159 hidnplayr 21
 
22
 
23
ARP_NO_ENTRY		equ  0
24
ARP_VALID_MAPPING	equ  1
25
ARP_AWAITING_RESPONSE	equ  2
26
ARP_RESPONSE_TIMEOUT	equ  3
27
 
1196 hidnplayr 28
ARP_REQUEST_TTL 	= 20 ; in seconds
1206 hidnplayr 29
ARP_ENTRY_TTL		= 600 ; in seconds
1196 hidnplayr 30
 
1159 hidnplayr 31
ETHER_ARP		equ  0x0608
32
 
33
ARP_REQ_OPCODE		equ  0x0100  ; request
34
ARP_REP_OPCODE		equ  0x0200  ; reply
35
 
36
ARP_TABLE_SIZE		equ  20      ; Size of table
37
 
38
struct ARP_ENTRY
39
       .IP		dd  ?
40
       .MAC		dp  ?
41
       .Status		dw  ?
42
       .TTL		dw  ?  ; in seconds
43
       .size:
44
ends
45
 
46
struct ARP_Packet
47
       .HardwareType	dw  ?
48
       .ProtocolType	dw  ?
49
       .HardwareSize	db  ?
50
       .ProtocolSize	db  ?
51
       .Opcode		dw  ?
52
       .SenderMAC	dp  ?
53
       .SenderIP	dd  ?
54
       .TargetMAC	dp  ?
55
       .TargetIP	dd  ?
56
ends
57
 
58
 
59
; The TTL field is decremented every second, and is deleted when it
60
; reaches 0. It is refreshed every time a packet is received
61
; If the TTL field is 0xFFFF it is a static entry and is never deleted
62
; The status field can be the following values:
63
; 0x0000  entry not used
64
; 0x0001  entry holds a valid mapping
65
; 0x0002  entry contains an IP address, awaiting ARP response
66
; 0x0003  No response received to ARP request.
67
; The last status value is provided to allow the network layer to delete
68
; a packet that is queued awaiting an ARP response
69
 
70
align 4
71
uglobal
72
 
73
	NumARP		dd ?
1258 hidnplayr 74
 
1159 hidnplayr 75
	ARPTable	rb ARP_ENTRY.size * ARP_TABLE_SIZE
76
 
77
	ARP_PACKETS_TX	rd  MAX_NET_DEVICES
78
	ARP_PACKETS_RX	rd  MAX_NET_DEVICES
79
 
80
 
81
endg
82
 
83
 
84
 
1196 hidnplayr 85
;-----------------------------------------------------------------
86
;
87
; ARP_init
88
;
89
;  This function resets all ARP variables
90
;
91
;  IN:  /
92
;  OUT: /
93
;
94
;-----------------------------------------------------------------
95
align 4
1159 hidnplayr 96
ARP_init:
97
 
98
	xor	eax, eax
99
 
100
	mov	[NumARP], eax
101
 
102
	mov	edi, ARP_PACKETS_TX
103
	mov	ecx, 2*MAX_NET_DEVICES
104
	rep	stosd
105
 
106
	ret
107
 
108
 
1196 hidnplayr 109
;-----------------------------------------------------------------
1159 hidnplayr 110
;
1196 hidnplayr 111
; ARP_IP_to_MAC
1159 hidnplayr 112
;
1196 hidnplayr 113
;  This function resets all ARP variables
114
;
1519 hidnplayr 115
;  IN:  eax = IPv4 address
1196 hidnplayr 116
;  OUT: eax = -1 on error, else eax = first two bytes of mac
117
;                   ( high 16 bits are zero)
118
;       ebx = last four bytes of mac                                  ; TODO: special eax value for 'request send'
119
;
120
;-----------------------------------------------------------------
1159 hidnplayr 121
align 4
1196 hidnplayr 122
ARP_IP_to_MAC:
1159 hidnplayr 123
 
1196 hidnplayr 124
	DEBUGF 1,"ARP_IP_to_MAC\n"
1159 hidnplayr 125
 
126
    ; first, check destination IP to see if it is on 'this' network.
127
    ; The test is:
128
    ; if ( destIP & subnet_mask == stack_ip & subnet_mask )
129
    ;   destination is local
130
    ; else
131
    ;  destination is remote, so pass to gateway
132
 
1519 hidnplayr 133
	xor	edx, edx ;;; TODO: find device num in edx
1159 hidnplayr 134
 
1519 hidnplayr 135
	mov	ebx, [IP_LIST + edx]
136
	and	ebx, [SUBNET_LIST + edx]
1206 hidnplayr 137
 
1196 hidnplayr 138
	mov	ecx, eax
1519 hidnplayr 139
	and	ecx, [SUBNET_LIST + edx]
1206 hidnplayr 140
 
1196 hidnplayr 141
	cmp	ecx, ebx
142
	je	.local
1159 hidnplayr 143
 
1519 hidnplayr 144
	mov	eax, [GATEWAY_LIST + edx]
1196 hidnplayr 145
	DEBUGF 1,"requested IP is not on subnet, using gateway\n"
1159 hidnplayr 146
 
1196 hidnplayr 147
  .local:
148
   ; try to find it on the list
149
	mov	ecx, [NumARP]
1206 hidnplayr 150
	test	ecx, ecx
1196 hidnplayr 151
	jz	.not_in_list
152
	mov	esi, ARPTable + ARP_ENTRY.IP
153
  .scan_loop:
1206 hidnplayr 154
	cmp	[esi], eax
155
	je	.found_it
156
	add	esi, ARP_ENTRY.size
1196 hidnplayr 157
	loop	.scan_loop
158
  .not_in_list:
1159 hidnplayr 159
 
1196 hidnplayr 160
	DEBUGF 1,"IP not found on list, preparing for ARP request\n"
1159 hidnplayr 161
 
1196 hidnplayr 162
   ; if not, reserve an entry in list and send an ARP request packet
1159 hidnplayr 163
 
1196 hidnplayr 164
	push	eax
1159 hidnplayr 165
 
1258 hidnplayr 166
	pushw	ARP_REQUEST_TTL
167
	pushw	ARP_AWAITING_RESPONSE
168
	pushd	0
169
	pushw	0
170
	pushd	eax
1196 hidnplayr 171
	call	ARP_add_entry
172
	cmp	eax, -1
173
	je	.full
1159 hidnplayr 174
 
1258 hidnplayr 175
	; 
176
 
177
	; This piece of code waits for an ARP reply
178
 
179
	mov	ebx, eax
1196 hidnplayr 180
	pop	eax
1258 hidnplayr 181
	push	ebx
1196 hidnplayr 182
	call	ARP_create_request
1159 hidnplayr 183
 
1258 hidnplayr 184
	push	[timer_ticks]
185
	add	dword[esp], 100*ARP_REQUEST_TTL
186
	DEBUGF 1,"Waiting for ARP reply, time: %x, entry:%u\n",[timer_ticks], [esp + 4]
187
   .dirty_loop:
188
 
189
	call	change_task	; The ARP reply hasnt been received yet, tell the processor to do some other stuff first
190
 
191
	mov	eax, [esp + 4]
192
	imul	eax, ARP_ENTRY.size
193
	add	eax, ARPTable
194
	cmp	[eax + ARP_ENTRY.Status], ARP_VALID_MAPPING
195
	je	.gogogo
196
 
197
	mov	eax, [esp]	; Check if the reply hasnt timed-out yet
198
	cmp	[timer_ticks], eax
199
	jl	.dirty_loop
200
 
201
	; 
202
	or	eax, -1
203
	add	esp, 8
1196 hidnplayr 204
	ret
1159 hidnplayr 205
 
1196 hidnplayr 206
  .found_it:
1258 hidnplayr 207
	DEBUGF 1,"found MAC in ARPTable\n"
208
	movzx  eax, word [esi+ARP_ENTRY.MAC]
209
	mov    ebx, dword[esi+ARP_ENTRY.MAC+2]
1196 hidnplayr 210
	ret
1159 hidnplayr 211
 
1196 hidnplayr 212
  .full:
213
	add	esp, 4
214
	mov	eax, -1
215
	ret
1159 hidnplayr 216
 
1258 hidnplayr 217
  .gogogo:
218
	DEBUGF 1,"got ARP reply, time: %x\n",[timer_ticks]
219
	mov    ebx, dword[eax+ARP_ENTRY.MAC+2]
220
	movzx  eax, word [eax+ARP_ENTRY.MAC]
221
	add    esp, 8
222
	ret
1196 hidnplayr 223
 
1258 hidnplayr 224
 
1196 hidnplayr 225
;---------------------------------------------------------------------------
1159 hidnplayr 226
;
1258 hidnplayr 227
; ARP_create_request
1159 hidnplayr 228
;
1196 hidnplayr 229
; IN:  ip in eax
1159 hidnplayr 230
;
1196 hidnplayr 231
; OUT: /
232
;
233
;---------------------------------------------------------------------------
234
align 4
235
ARP_create_request:
1159 hidnplayr 236
 
1196 hidnplayr 237
	DEBUGF 1,"Create ARP Packet\n"
1159 hidnplayr 238
 
1196 hidnplayr 239
	call	IPv4_dest_to_dev
1159 hidnplayr 240
 
1196 hidnplayr 241
	push	eax						; DestIP
242
	mov	eax, [IP_LIST+4*edi]				; senderIP
243
	push	eax
1159 hidnplayr 244
 
1514 hidnplayr 245
	mov	edi, [NET_DRV_LIST + 4*edi]
1196 hidnplayr 246
	lea	eax, [edi + ETH_DEVICE.mac]
247
	mov	ebx, ETH_BROADCAST
248
	mov	ecx, 60 ; minimum packet size
249
	mov	edx, edi ;;;
250
	mov	di , ETHER_ARP
1249 hidnplayr 251
	call	ETH_create_packet
1514 hidnplayr 252
	jz	.exit
1159 hidnplayr 253
 
1206 hidnplayr 254
	mov	ecx, eax
1159 hidnplayr 255
 
1206 hidnplayr 256
	mov	[edi + ARP_Packet.HardwareType], 0x0100 ;Ethernet
257
	mov	[edi + ARP_Packet.ProtocolType], 0x0008 ;IP
258
	mov	[edi + ARP_Packet.HardwareSize], 6   ;MAC-addr length
259
	mov	[edi + ARP_Packet.ProtocolSize], 4   ;IP-addr length
260
	mov	[edi + ARP_Packet.Opcode], ARP_REQ_OPCODE      ;Request
261
 
1196 hidnplayr 262
	add	edi, ARP_Packet.SenderMAC			; sendermac
1206 hidnplayr 263
	lea	esi, [ebx + ETH_DEVICE.mac]			;
1196 hidnplayr 264
	movsw							;
265
	movsd							;
1206 hidnplayr 266
	pop	eax						;
267
	stosd							;
268
	mov	eax, -1 					; destmac
269
	stosd							;
270
	stosw							;
1196 hidnplayr 271
	pop	eax
272
	stosd							;
1159 hidnplayr 273
 
1206 hidnplayr 274
	DEBUGF 1,"ARP Packet for device %x created successfully\n", ebx
1159 hidnplayr 275
 
1206 hidnplayr 276
	push	edx ecx
1519 hidnplayr 277
	call	[ebx + NET_DEVICE.transmit]
278
	ret
1159 hidnplayr 279
 
1196 hidnplayr 280
  .exit:
281
	add	esp, 8
282
	DEBUGF 1,"Create ARP Packet - failed\n"
283
	mov	eax, -1
284
	ret
1159 hidnplayr 285
 
286
 
287
 
1185 hidnplayr 288
;---------------------------------------------------------------------------
289
;
290
; ARP_decrease_entry_ttls
291
;
292
; IN: /
293
; OUT: /
294
;
295
;---------------------------------------------------------------------------
296
align 4
297
ARP_decrease_entry_ttls:
298
 
299
	mov	ecx, [NumARP]
300
	test	ecx, ecx
301
	jz	.exit
302
 
303
	mov	ebx, ARPTable
304
 
305
.timer_loop:
306
 
1206 hidnplayr 307
	cmp	[ebx + ARP_ENTRY.TTL], 0xFFFF
1185 hidnplayr 308
	je	.timer_loop_end  ;if TTL==0xFFFF then it's static entry
309
 
1206 hidnplayr 310
	cmp	[ebx + ARP_ENTRY.TTL], 0
1185 hidnplayr 311
	jnz	.timer_loop_end_with_dec  ;if TTL!=0
312
 
313
	; Ok, TTL is 0
314
	;if Status==AWAITING_RESPONSE and TTL==0
315
	;then we have to change it to ARP_RESPONSE_TIMEOUT
1206 hidnplayr 316
	cmp	[ebx + ARP_ENTRY.Status], ARP_AWAITING_RESPONSE
1185 hidnplayr 317
	jne	@f
318
 
1206 hidnplayr 319
	mov	[ebx + ARP_ENTRY.Status], ARP_RESPONSE_TIMEOUT
320
	mov	[ebx + ARP_ENTRY.TTL], word 0x000A   ;10 sec
1185 hidnplayr 321
	jmp	.timer_loop_end
322
 
323
  @@:
324
	;if TTL==0 and Status==VALID_MAPPING, we have to delete it
325
	;if TTL==0 and Status==RESPONSE_TIMEOUT, delete too
1206 hidnplayr 326
	mov	esi, [NumARP]
1185 hidnplayr 327
	sub	esi, ecx	  ;esi=index of entry, will be deleted
328
 
1206 hidnplayr 329
	push	ebx ecx
1185 hidnplayr 330
	call	ARP_del_entry
1206 hidnplayr 331
	pop	ecx ebx
1185 hidnplayr 332
 
333
	jmp	.timer_loop_end
334
 
335
 
336
.timer_loop_end_with_dec:
337
 
1206 hidnplayr 338
	dec	[ebx + ARP_ENTRY.TTL]  ;decrease TTL
1185 hidnplayr 339
 
340
.timer_loop_end:
341
 
342
	add	ebx, ARP_ENTRY.size
343
	loop	.timer_loop
344
 
345
.exit:
346
 
347
	ret
348
 
1257 hidnplayr 349
;-----------------------------------------------------------------
1196 hidnplayr 350
;
351
; ARP_add_entry (or update)
352
;
353
; IN: arp entry in stack: esp     .IP
354
;                         esp+4   .MAC
355
;                         esp+10  .Status
356
;                         esp+12  .TTL
357
;                         esp+14
358
;
359
; OUT: eax = entry #, -1 on error
360
;
1257 hidnplayr 361
;-----------------------------------------------------------------   ; TODO: use a mutex
1196 hidnplayr 362
align 4
363
ARP_add_entry:
364
 
1206 hidnplayr 365
	DEBUGF 1,"ARP add entry: "
366
 
1196 hidnplayr 367
	mov	ecx, [NumARP]
368
	test	ecx, ecx
369
	jz	.add
370
 
1251 clevermous 371
	mov	eax, dword[esp + 4 + ARP_ENTRY.MAC]
372
	mov	bx , word[esp + 4 + ARP_ENTRY.MAC + 4]
1196 hidnplayr 373
	mov	esi, ARPTable
374
 
375
.loop:
376
	cmp	dword [esi + ARP_ENTRY.MAC], eax
377
	jne	.maybe_next
378
	cmp	word [esi + ARP_ENTRY.MAC + 4], bx
379
	jne	.maybe_next
380
 
381
	cmp	dword[esi + ARP_ENTRY.TTL], 0xFFFF ; static entry
382
	jne	.notstatic
1251 clevermous 383
	cmp	dword[esp + 4 + ARP_ENTRY.TTL], 0xFFFF
1206 hidnplayr 384
	jne	.error
1196 hidnplayr 385
.notstatic:
386
 
387
	mov	ebx, [NumARP]
388
	xchg	ebx, ecx
389
	sub	ecx, ebx
390
	jmp	.add
391
 
392
.maybe_next:
393
	add	esi, ARP_ENTRY.size
394
	loop	.loop
395
 
396
	mov	ecx, [NumARP]
397
	cmp	ecx, ARP_TABLE_SIZE
1206 hidnplayr 398
	jge	.error
1196 hidnplayr 399
 
400
.add:
401
	push	ecx
402
	imul	ecx, ARP_ENTRY.size
403
	lea	edi, [ecx + ARPTable]
1206 hidnplayr 404
	lea	esi, [esp + 8]
1196 hidnplayr 405
	mov	ecx, ARP_ENTRY.size/2
406
	repz	movsw
407
 
408
	inc	[NumARP]
409
	pop	eax
1258 hidnplayr 410
	DEBUGF 1,"New entry created: %u\n", eax
1196 hidnplayr 411
.exit:
1206 hidnplayr 412
	DEBUGF 1,"Exiting\n"
1251 clevermous 413
	ret	ARP_ENTRY.size
1196 hidnplayr 414
 
1206 hidnplayr 415
.error:
1196 hidnplayr 416
 
1206 hidnplayr 417
	DEBUGF 1,"error! \n"
1196 hidnplayr 418
 
419
	mov	eax, -1
420
	jmp	.exit
421
 
422
 
1257 hidnplayr 423
;-----------------------------------------------------------------
1185 hidnplayr 424
;
425
; ARP_del_entry
426
;
427
; IN: entry # in esi
428
; OUT: /
429
;
1257 hidnplayr 430
;-----------------------------------------------------------------
1185 hidnplayr 431
align 4
432
ARP_del_entry:
433
 
1206 hidnplayr 434
	DEBUGF 1,"ARP del entry %u, total entrys: %u\n", esi, [NumARP]
435
 
436
	cmp	esi, [NumARP]
437
	jge	.error
438
 
1185 hidnplayr 439
	imul	esi, ARP_ENTRY.size
440
 
441
	mov	ecx, (ARP_TABLE_SIZE - 1) * ARP_ENTRY.size
442
	sub	ecx, esi
443
 
1485 hidnplayr 444
	lea	edi, [ARPTable + esi]		 ;edi=ptr to entry that should be deleted
1185 hidnplayr 445
	lea	esi, [edi + ARP_ENTRY.size] ;esi=ptr to next entry
446
 
447
	shr	ecx,1	   ;ecx/2 => ARP_ENTRY_SIZE MUST BE EVEN NUMBER!
448
	rep	movsw
449
 
1196 hidnplayr 450
	dec	[NumARP] ;decrease arp-entries counter
1485 hidnplayr 451
	DEBUGF 1,"ARP entry deleted\n"
1206 hidnplayr 452
.error:
1185 hidnplayr 453
	ret
454
 
455
 
456
 
457
 
1257 hidnplayr 458
;-----------------------------------------------------------------
1159 hidnplayr 459
;
460
; ARP_Handler:
461
;
462
;  This function handles ARP protocol over ethernet
463
;  (other protocols may follow in the future)
464
;
465
;  IN:  Pointer to buffer in [esp]
466
;       size of buffer in [esp+4]
467
;       packet size (without ethernet header) in ecx
468
;  OUT: /
469
;
1257 hidnplayr 470
;-----------------------------------------------------------------
1159 hidnplayr 471
align 4
1196 hidnplayr 472
ARP_handler:
1159 hidnplayr 473
 
474
	DEBUGF	1,"ARP_Handler - start\n"
475
	cmp	ecx, 28
476
	jl	.exit
477
 
1196 hidnplayr 478
	cmp	word [edx + ARP_Packet.Opcode], ARP_REP_OPCODE	; Is this a reply packet?
479
	jne	.maybe_request
1159 hidnplayr 480
 
1206 hidnplayr 481
	DEBUGF	1,"ARP_Handler - it's a reply packet from %u.%u.%u.%u\n",\
482
	[edx + ARP_Packet.SenderIP]:1,[edx + ARP_Packet.SenderIP+1]:1,[edx + ARP_Packet.SenderIP+2]:1,[edx + ARP_Packet.SenderIP+3]:1,
483
 
1196 hidnplayr 484
	mov	ecx, [NumARP]
485
	test	ecx, ecx
486
	jz	.exit
1159 hidnplayr 487
 
1206 hidnplayr 488
	mov	eax, [edx + ARP_Packet.SenderIP]
1196 hidnplayr 489
	mov	esi, ARPTable+ARP_ENTRY.IP
490
 
491
  .loop:
1206 hidnplayr 492
	cmp	[esi], eax
493
	je	.gotit
494
	add	esi, ARP_ENTRY.size
1196 hidnplayr 495
	loop	.loop
496
 
497
	jmp	.exit
498
 
499
  .gotit:
1206 hidnplayr 500
 
501
	DEBUGF	1,"ARP_Handler - found matching entry\n"
502
 
503
	cmp	[esi+ARP_ENTRY.Status], 0x0300	 ;if it is a static entry, dont touch it
1196 hidnplayr 504
	je	.exit
505
 
1206 hidnplayr 506
	DEBUGF	1,"ARP_Handler - updating entry\n"
1196 hidnplayr 507
 
1206 hidnplayr 508
	mov	[esi+ARP_ENTRY.Status], ARP_VALID_MAPPING
509
	mov	[esi+ARP_ENTRY.TTL], ARP_ENTRY_TTL
1196 hidnplayr 510
 
1206 hidnplayr 511
	mov	eax, dword [edx + ARP_Packet.SenderMAC]
512
	mov	dword [esi+ARP_ENTRY.MAC], eax
513
	mov	ax , word [edx + ARP_Packet.SenderMAC + 4]
514
	mov	word [esi+ARP_ENTRY.MAC+4], ax
515
 
1196 hidnplayr 516
	jmp	.exit
517
 
518
 
519
;------
520
 
521
 
522
  .maybe_request:
1159 hidnplayr 523
	cmp	word [edx + ARP_Packet.Opcode], ARP_REQ_OPCODE	; Is this a request packet?
524
	jne	.exit
525
 
1514 hidnplayr 526
	call	NET_ptr_to_num
1206 hidnplayr 527
	DEBUGF	1,"ARP Request packet through device: %u\n", edi
1171 hidnplayr 528
	inc	[ARP_PACKETS_RX+4*edi]
1159 hidnplayr 529
	cmp	edi, -1
530
	jz	.exit
531
 
532
	mov	eax, edi
533
	shl	eax, 2
534
	add	eax, IP_LIST
535
	mov	eax, [eax]
536
	cmp	eax, [edx + ARP_Packet.TargetIP]		; Is it looking for my IP address?
537
	jnz	.exit
538
	push	eax
539
	push	edi
540
 
541
; OK, it is a request for one of our MAC addresses. Build the frame and send it
1196 hidnplayr 542
; We can reuse the buffer.  (faster then using ARP_create_packet)
1159 hidnplayr 543
 
544
	cld
545
	lea	esi, [edx + ARP_Packet.SenderMAC]
546
	lea	edi, [edx + ARP_Packet.TargetMAC]
547
	movsd							; Move Sender Mac to Dest MAC
548
	movsw							;
549
	movsd							; Move sender IP to Dest IP
550
 
551
	pop	esi
1514 hidnplayr 552
	mov	esi, [NET_DRV_LIST + 4*esi]
1159 hidnplayr 553
	lea	esi, [esi + ETH_DEVICE.mac]
554
	lea	edi, [edx + ARP_Packet.SenderMAC]
555
	movsd							; Copy MAC address from in MAC_LIST
556
	movsw							;
557
	pop	eax
558
	stosd							; Write our IP
559
 
560
	mov	word [edx + ARP_Packet.Opcode], ARP_REP_OPCODE
561
 
562
; Now, Fill in ETHERNET header
563
 
564
	mov	edi, [esp]
565
	lea	esi, [edx + ARP_Packet.TargetMAC]
566
	movsd
567
	movsw
568
	lea	esi, [edx + ARP_Packet.SenderMAC]
569
	movsd
570
	movsw
1196 hidnplayr 571
;        mov     ax , ETHER_ARP
572
;        stosw
1159 hidnplayr 573
 
1206 hidnplayr 574
	DEBUGF	1,"ARP_Handler - Sending reply \n"
575
 
1519 hidnplayr 576
	call	[ebx + NET_DEVICE.transmit]
577
	ret
1159 hidnplayr 578
 
1196 hidnplayr 579
     .exit:
1159 hidnplayr 580
	call	kernel_free
581
	add	esp, 4						; pop (balance stack)
582
 
1206 hidnplayr 583
	DEBUGF 1,"ARP_Handler - exiting\n"
1159 hidnplayr 584
	ret
585
 
586
 
587
 
588
 
1257 hidnplayr 589
;-----------------------------------------------------------------
1159 hidnplayr 590
;
591
; ARP_API
592
;
593
; This function is called by system function 75
594
;
595
; IN:  subfunction number in bl
596
;      device number in bh
597
;      ecx, edx, .. depends on subfunction
598
;
1257 hidnplayr 599
; OUT:  ?
1159 hidnplayr 600
;
1257 hidnplayr 601
;-----------------------------------------------------------------
1159 hidnplayr 602
align 4
603
ARP_API:
604
 
605
	movzx	eax, bh
606
	shl	eax, 2
607
 
608
	test	bl, bl
609
	jz	.packets_tx	; 0
610
	dec	bl
611
	jz	.packets_rx	; 1
612
	dec	bl
613
	jz	.entries	; 2
614
	dec	bl
615
	jz	.read		; 3
616
	dec	bl
617
	jz	.write		; 4
618
	dec	bl
619
	jz	.remove 	; 5
620
	dec	bl
621
 
622
.error:
623
	mov	eax, -1
624
	ret
625
 
626
.packets_tx:
627
	add	eax, ARP_PACKETS_TX
628
	mov	eax, [eax]
629
	ret
630
 
631
.packets_rx:
632
	add	eax, ARP_PACKETS_RX
633
	mov	eax, [eax]
634
	ret
635
 
636
.entries:
637
	mov	eax, [NumARP]
638
	ret
639
 
640
.read:
1200 hidnplayr 641
	cmp	ecx, [NumARP]
642
	jge	.error
643
	; edi = pointer to buffer
644
	; ecx = # entry
645
	imul	ecx, ARP_ENTRY.size
646
	add	ecx, ARPTable
647
	mov	esi, ecx
648
	mov	ecx, ARP_ENTRY.size/2
649
	rep	movsw
650
 
651
	xor	eax, eax
1159 hidnplayr 652
	ret
653
 
654
.write:
1200 hidnplayr 655
	; esi = pointer to buffer
656
	sub	esp, ARP_ENTRY.size
657
	mov	edi, esp
658
	mov	ecx, ARP_ENTRY.size/2
659
	rep	movsw
1251 clevermous 660
	call	ARP_add_entry	     ;out: eax = entry number, -1 on error
661
	ret
1159 hidnplayr 662
 
663
.remove:
1200 hidnplayr 664
	; ecx = # entry
665
	mov	esi, ecx
1196 hidnplayr 666
	call	ARP_del_entry
1159 hidnplayr 667
	ret
668