Subversion Repositories Kolibri OS

Rev

Rev 3556 | Rev 3601 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;                                                                 ;;
  3. ;; Copyright (C) KolibriOS team 2004-2010. All rights reserved.    ;;
  4. ;; Distributed under terms of the GNU General Public License       ;;
  5. ;;                                                                 ;;
  6. ;;  loopback.inc                                                   ;;
  7. ;;                                                                 ;;
  8. ;;  LoopBack device for KolibriOS                                  ;;
  9. ;;                                                                 ;;
  10. ;;    Written by hidnplayr@kolibrios.org                           ;;
  11. ;;                                                                 ;;
  12. ;;          GNU GENERAL PUBLIC LICENSE                             ;;
  13. ;;             Version 2, June 1991                                ;;
  14. ;;                                                                 ;;
  15. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  16.  
  17. $Revision: 2891 $
  18.  
  19. iglobal
  20.  
  21. LOOPBACK_DEVICE:
  22.  
  23.         .device_type     dd NET_DEVICE_LOOPBACK
  24.         .mtu             dd 4096
  25.         .name            dd .namestr
  26.  
  27.         .unload          dd .dummy_fn
  28.         .reset           dd .dummy_fn
  29.         .transmit        dd LOOP_input
  30.  
  31.         .bytes_tx        dq 0
  32.         .bytes_rx        dq 0
  33.         .packets_tx      dd 0
  34.         .packets_rx      dd 0
  35.  
  36.         .namestr         db 'loopback', 0
  37.  
  38.         .dummy_fn:
  39.                 ret
  40.  
  41. endg
  42.  
  43. ;-----------------------------------------------------------------
  44. ;
  45. ; LOOP_input
  46. ;
  47. ;  IN:  [esp+4] = Pointer to buffer
  48. ;       [esp+8] = size of buffer
  49. ;
  50. ;  OUT: /
  51. ;
  52. ;-----------------------------------------------------------------
  53. align 4
  54. LOOP_input:
  55.         pop     ebx
  56.         pop     eax
  57.         pop     ecx
  58.  
  59.         push    ebx
  60.         push    ecx
  61.         push    eax
  62.  
  63.         DEBUGF  DEBUG_NETWORK_VERBOSE, "LOOP_input: size=%u\n", ecx
  64.         lea     edx, [eax + 4]
  65.         mov     eax, dword[eax]
  66.         mov     ebx, LOOPBACK_DEVICE
  67.  
  68.         cmp     eax, AF_INET4
  69.         je      IPv4_input
  70.  
  71.         DEBUGF  DEBUG_NETWORK_VERBOSE, "LOOP_input: Unknown packet type=%x\n", ax
  72.  
  73.   .dump:
  74.         DEBUGF  DEBUG_NETWORK_VERBOSE, "LOOP_input: dumping\n"
  75.         call    kernel_free
  76.         add     esp, 4
  77.         ret
  78.  
  79. ;-----------------------------------------------------------------
  80. ;
  81. ; LOOP_output
  82. ;
  83. ; IN:
  84. ;     ecx = packet size
  85. ;      di = protocol
  86. ;
  87. ; OUT: edi = 0 on error, pointer to buffer otherwise
  88. ;      eax = buffer start
  89. ;      ebx = to device structure
  90. ;      ecx = unchanged (packet size of embedded data)
  91. ;      edx = size of complete buffer
  92. ;
  93. ;-----------------------------------------------------------------
  94. align 4
  95. LOOP_output:
  96.  
  97.         DEBUGF  DEBUG_NETWORK_VERBOSE, "LOOP_output\n"
  98.  
  99.         push    ecx
  100.         push    edi
  101.  
  102.         add     ecx, 4
  103.         cmp     ecx, [LOOPBACK_DEVICE.mtu]
  104.         ja      .out_of_ram
  105.         stdcall kernel_alloc, ecx
  106.         test    eax, eax
  107.         jz      .out_of_ram
  108.         mov     edi, eax
  109.         pop     eax
  110.         stosd
  111.  
  112.         lea     eax, [edi - 4]  ; Set eax to buffer start
  113.         pop     ecx
  114.         lea     edx, [ecx + 4]  ; Set edx to complete buffer size
  115.         mov     ebx, LOOPBACK_DEVICE
  116.  
  117.   .done:
  118.         DEBUGF  DEBUG_NETWORK_VERBOSE, "LOOP_output: ptr=%x size=%u\n", eax, edx
  119.         ret
  120.  
  121.   .out_of_ram:
  122.         DEBUGF  DEBUG_NETWORK_VERBOSE, "LOOP_output: failed\n"
  123.         add     esp, 4+4
  124.         xor     edi, edi
  125.         ret
  126.  
  127.  
  128.