Subversion Repositories Kolibri OS

Rev

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

Rev 3626 Rev 3725
Line 53... Line 53...
53
        TargetMAC       dp ?
53
        TargetMAC       dp ?
54
        TargetIP        dd ?
54
        TargetIP        dd ?
Line 55... Line 55...
55
 
55
 
Line 56... Line -...
56
ends
-
 
57
 
56
ends
58
align 4
57
 
Line 59... Line 58...
59
uglobal
58
uglobal
Line 60... Line 59...
60
 
59
align 4
61
 
60
 
Line 174... Line 173...
174
; Check validity and print some debug info
173
; Check validity and print some debug info
Line 175... Line 174...
175
 
174
 
176
        cmp     ecx, sizeof.ARP_header
175
        cmp     ecx, sizeof.ARP_header
Line 177... Line 176...
177
        jb      .exit
176
        jb      .exit
178
 
177
 
179
        call    NET_ptr_to_num
178
        call    NET_ptr_to_num4
Line 180... Line 179...
180
        cmp     edi, -1
179
        cmp     edi, -1
Line 181... Line 180...
181
        jz      .exit
180
        jz      .exit
182
 
181
 
183
        inc     [ARP_PACKETS_RX + 4*edi]        ; update stats
182
        inc     [ARP_PACKETS_RX + edi]          ; update stats
Line 184... Line 183...
184
 
183
 
185
        DEBUGF  DEBUG_NETWORK_VERBOSE, "ARP_input: got packet from %u.%u.%u.%u through device %u\n",\
184
        DEBUGF  DEBUG_NETWORK_VERBOSE, "ARP_input: got packet from %u.%u.%u.%u (device*4=%u)\n",\
Line 186... Line 185...
186
        [edx + ARP_header.SenderIP]:1, [edx + ARP_header.SenderIP + 1]:1,\
185
        [edx + ARP_header.SenderIP]:1, [edx + ARP_header.SenderIP + 1]:1,\
187
        [edx + ARP_header.SenderIP + 2]:1, [edx + ARP_header.SenderIP + 3]:1, edi
186
        [edx + ARP_header.SenderIP + 2]:1, [edx + ARP_header.SenderIP + 3]:1, edi
188
 
187
 
Line 189... Line 188...
189
;------------------------------
188
;------------------------------
190
; First, check for IP collision
189
; First, check for IP collision
Line 191... Line 190...
191
 
190
 
192
        mov     eax, [edx + ARP_header.SenderIP]
191
        mov     eax, [edx + ARP_header.SenderIP]
Line 193... Line 192...
193
        cmp     eax, [IP_LIST + 4*edi]
192
        cmp     eax, [IP_LIST + edi]
Line 194... Line 193...
194
        je      .collision
193
        je      .collision
195
 
194
 
196
;---------------------
195
;---------------------
Line 197... Line 196...
197
; Handle reply packets
196
; Handle reply packets
198
 
197
 
199
        cmp     [edx + ARP_header.Opcode], ARP_REP_OPCODE
198
        cmp     [edx + ARP_header.Opcode], ARP_REP_OPCODE
200
        jne     .maybe_request
199
        jne     .maybe_request
201
 
200
 
202
        DEBUGF  DEBUG_NETWORK_VERBOSE, "ARP_input: It's a reply\n"
201
        DEBUGF  DEBUG_NETWORK_VERBOSE, "ARP_input: It's a reply\n"
203
 
202
 
Line 243... Line 242...
243
        cmp     [edx + ARP_header.Opcode], ARP_REQ_OPCODE
242
        cmp     [edx + ARP_header.Opcode], ARP_REQ_OPCODE
244
        jne     .exit
243
        jne     .exit
Line 245... Line 244...
245
 
244
 
Line 246... Line 245...
246
        DEBUGF  DEBUG_NETWORK_VERBOSE, "ARP_input: its a request\n"
245
        DEBUGF  DEBUG_NETWORK_VERBOSE, "ARP_input: its a request\n"
247
 
246
 
248
        mov     eax, [IP_LIST + 4*edi]
247
        mov     eax, [IP_LIST + edi]
Line 249... Line 248...
249
        cmp     eax, [edx + ARP_header.TargetIP]                ; Is it looking for my IP address?
248
        cmp     eax, [edx + ARP_header.TargetIP]                ; Is it looking for my IP address?
250
        jne     .exit
249
        jne     .exit
Line 260... Line 259...
260
        movsd                                                   ; Move Sender Mac to Dest MAC
259
        movsd                                                   ; Move Sender Mac to Dest MAC
261
        movsw                                                   ;
260
        movsw                                                   ;
262
        movsd                                                   ; Move sender IP to Dest IP
261
        movsd                                                   ; Move sender IP to Dest IP
Line 263... Line 262...
263
 
262
 
264
        pop     esi
263
        pop     esi
265
        mov     esi, [NET_DRV_LIST + 4*esi]
264
        mov     esi, [NET_DRV_LIST + esi]
266
        lea     esi, [esi + ETH_DEVICE.mac]
265
        lea     esi, [esi + ETH_DEVICE.mac]
267
        lea     edi, [edx + ARP_header.SenderMAC]
266
        lea     edi, [edx + ARP_header.SenderMAC]
268
        movsd                                                   ; Copy MAC address from in MAC_LIST
267
        movsd                                                   ; Copy MAC address from in MAC_LIST
269
        movsw                                                   ;
268
        movsw                                                   ;
Line 288... Line 287...
288
 
287
 
289
        call    [ebx + NET_DEVICE.transmit]
288
        call    [ebx + NET_DEVICE.transmit]
Line 290... Line 289...
290
        ret
289
        ret
291
 
290
 
292
  .collision:
291
  .collision:
Line 293... Line 292...
293
        inc     [ARP_CONFLICTS + 4*edi]
292
        inc     [ARP_CONFLICTS + edi]
294
        DEBUGF  DEBUG_NETWORK_VERBOSE, "ARP_input: IP address conflict detected!\n"
293
        DEBUGF  DEBUG_NETWORK_VERBOSE, "ARP_input: IP address conflict detected!\n"
295
 
294
 
Line 335... Line 334...
335
        add     edi, ARP_header.SenderMAC
334
        add     edi, ARP_header.SenderMAC
336
        lea     esi, [ebx + ETH_DEVICE.mac]     ; SenderMac
335
        lea     esi, [ebx + ETH_DEVICE.mac]     ; SenderMac
337
        movsw                                   ;
336
        movsw                                   ;
338
        movsd                                   ;
337
        movsd                                   ;
Line 339... Line -...
339
 
-
 
340
;        mov     esi, [ebx + NET_DEVICE.number]
338
 
341
        xor     esi, esi        ;;;; FIXME
339
        push    edi
342
        inc     esi ;;;;;;;;;
340
        call    NET_ptr_to_num4
343
        inc     [ARP_PACKETS_TX + 4*esi]        ; assume we will succeed
341
        inc     [ARP_PACKETS_TX + edi]          ; assume we will succeed
-
 
342
        lea     esi, [IP_LIST + edi]            ; SenderIP
344
        lea     esi, [IP_LIST + 4*esi]          ; SenderIP
343
        pop     edi
Line 345... Line 344...
345
        movsd
344
        movsd
346
 
345
 
347
        mov     esi, ETH_BROADCAST              ; DestMac
346
        mov     esi, ETH_BROADCAST              ; DestMac
Line 362... Line 361...
362
;-----------------------------------------------------------------
361
;-----------------------------------------------------------------
363
;
362
;
364
; ARP_add_entry (or update)
363
; ARP_add_entry (or update)
365
;
364
;
366
; IN:  esi = ptr to entry (can easily be made on the stack)
365
; IN:  esi = ptr to entry (can easily be made on the stack)
367
;      edi = device num
366
;      edi = device num*4
368
; OUT: eax = entry #, -1 on error
367
; OUT: eax = entry #, -1 on error
369
;      esi = ptr to newly created entry
368
;      esi = ptr to newly created entry
370
;
369
;
371
;-----------------------------------------------------------------      ; TODO: use a mutex
370
;-----------------------------------------------------------------      ; TODO: use a mutex
372
align 4
371
align 4
373
ARP_add_entry:
372
ARP_add_entry:
Line 374... Line 373...
374
 
373
 
Line 375... Line 374...
375
        DEBUGF  DEBUG_NETWORK_VERBOSE, "ARP_add_entry: device=%u\n", edi
374
        DEBUGF  DEBUG_NETWORK_VERBOSE, "ARP_add_entry: device=%u\n", edi
376
 
375
 
377
        mov     ecx, [ARP_entries_num + 4*edi]
376
        mov     ecx, [ARP_entries_num + edi]
Line 378... Line 377...
378
        cmp     ecx, ARP_TABLE_SIZE                                     ; list full ?
377
        cmp     ecx, ARP_TABLE_SIZE                                     ; list full ?
Line 379... Line 378...
379
        jae     .full
378
        jae     .full
Line 380... Line 379...
380
 
379
 
381
; From this point on, we can only fail if IP has a static entry, or if table is corrupt.
380
; From this point on, we can only fail if IP has a static entry, or if table is corrupt.
382
 
381
 
383
        inc     [ARP_entries_num + 4*edi]                               ; assume we will succeed
382
        inc     [ARP_entries_num + edi]                                 ; assume we will succeed
384
 
383
 
385
        push    edi
384
        push    edi
386
        xor     ecx, ecx
385
        xor     ecx, ecx
387
        imul    edi, ARP_TABLE_SIZE*sizeof.ARP_entry
386
        imul    edi, ARP_TABLE_SIZE*sizeof.ARP_entry/4
Line 417... Line 416...
417
 
416
 
Line 418... Line 417...
418
        ret
417
        ret
419
 
418
 
420
  .error:
419
  .error:
421
        pop     edi
420
        pop     edi
422
        dec     [ARP_entries_num + 4*edi]
421
        dec     [ARP_entries_num + edi]
423
        DEBUGF  DEBUG_NETWORK_ERROR, "ARP_add_entry_failed\n"
422
        DEBUGF  DEBUG_NETWORK_ERROR, "ARP_add_entry_failed\n"
424
  .full:
423
  .full:
Line 473... Line 472...
473
; ARP_IP_to_MAC
472
; ARP_IP_to_MAC
474
;
473
;
475
;  This function translates an IP address to a MAC address
474
;  This function translates an IP address to a MAC address
476
;
475
;
477
;  IN:  eax = IPv4 address
476
;  IN:  eax = IPv4 address
478
;       edi = device number
477
;       edi = device number * 4
479
;  OUT: eax = -1 on error, -2 means request send
478
;  OUT: eax = -1 on error, -2 means request send
480
;      else, ax = first two bytes of mac (high 16 bits of eax will be 0)
479
;      else, ax = first two bytes of mac (high 16 bits of eax will be 0)
481
;       ebx = last four bytes of mac
480
;       ebx = last four bytes of mac
482
;       edi = unchanged
481
;       edi = unchanged
483
;
482
;
Line 485... Line 484...
485
align 4
484
align 4
486
ARP_IP_to_MAC:
485
ARP_IP_to_MAC:
Line 487... Line 486...
487
 
486
 
488
        DEBUGF  DEBUG_NETWORK_VERBOSE, "ARP_IP_to_MAC: %u.%u", al, ah
487
        DEBUGF  DEBUG_NETWORK_VERBOSE, "ARP_IP_to_MAC: %u.%u", al, ah
489
        rol     eax, 16
488
        rol     eax, 16
490
        DEBUGF  DEBUG_NETWORK_VERBOSE, ".%u.%u device: %u\n", al, ah, edi
489
        DEBUGF  DEBUG_NETWORK_VERBOSE, ".%u.%u device*4: %u\n", al, ah, edi
Line 491... Line 490...
491
        rol     eax, 16
490
        rol     eax, 16
492
 
491
 
Line 493... Line 492...
493
        cmp     eax, 0xffffffff
492
        cmp     eax, 0xffffffff
494
        je      .broadcast
493
        je      .broadcast
Line 495... Line 494...
495
 
494
 
496
;--------------------------------
495
;--------------------------------
497
; Try to find the IP in ARP_table
496
; Try to find the IP in ARP_table
498
 
497
 
499
        mov     ecx, [ARP_entries_num + 4*edi]
498
        mov     ecx, [ARP_entries_num + edi]
500
        test    ecx, ecx
499
        test    ecx, ecx
501
        jz      .not_in_list
500
        jz      .not_in_list
502
        mov     esi, edi
501
        mov     esi, edi
503
        imul    esi, sizeof.ARP_entry * ARP_TABLE_SIZE
502
        imul    esi, (sizeof.ARP_entry * ARP_TABLE_SIZE)/4
504
        add     esi, ARP_table + ARP_entry.IP
503
        add     esi, ARP_table + ARP_entry.IP
Line 536... Line 535...
536
 
535
 
537
; Now send a request packet on the network
536
; Now send a request packet on the network
Line 538... Line 537...
538
        pop     edi eax                 ; IP in eax, device number in ebx, for ARP_output_request
537
        pop     edi eax                 ; IP in eax, device number in ebx, for ARP_output_request
539
 
538
 
540
        push    esi edi
539
        push    esi edi
541
        mov     ebx, [NET_DRV_LIST + 4*edi]
540
        mov     ebx, [NET_DRV_LIST + edi]
542
        call    ARP_output_request
541
        call    ARP_output_request
543
        pop     edi esi
542
        pop     edi esi
544
  .found_it:
543
  .found_it:
Line 653... Line 652...
653
        ret
652
        ret
Line 654... Line 653...
654
 
653
 
655
  .write:
654
  .write:
656
        ; esi = pointer to buffer
655
        ; esi = pointer to buffer
657
        mov     edi, eax
-
 
658
        shr     edi, 2
656
        mov     edi, eax
659
        call    ARP_add_entry           ; out: eax = entry number, -1 on error
657
        call    ARP_add_entry           ; out: eax = entry number, -1 on error
Line 660... Line 658...
660
        ret
658
        ret
661
 
659