Subversion Repositories Kolibri OS

Rev

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

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;                                                                 ;;
  3. ;; Copyright (C) KolibriOS team 2004-2013. 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.         .link_state     dd -1
  37.         .hwacc          dd 0
  38.  
  39.         .namestr        db 'loopback', 0
  40.  
  41.         .dummy_fn:
  42.                 ret
  43.  
  44. endg
  45.  
  46.  
  47. macro   LOOP_init {
  48. local   .fail
  49.  
  50.         mov     ebx, LOOPBACK_DEVICE
  51.         call    NET_add_device
  52.  
  53.         cmp     eax, -1
  54.         je      .fail
  55.  
  56.         mov     [IP_LIST], 127 + 1 shl 24
  57.         mov     [SUBNET_LIST], 255
  58.         mov     [BROADCAST_LIST], 0xffffff00 + 127
  59.  
  60.   .fail:
  61. }
  62.  
  63. ;-----------------------------------------------------------------
  64. ;
  65. ; LOOP_input
  66. ;
  67. ;  IN:  [esp+4] = Pointer to buffer
  68. ;       [esp+8] = size of buffer
  69. ;
  70. ;  OUT: /
  71. ;
  72. ;-----------------------------------------------------------------
  73. align 4
  74. LOOP_input:
  75.         pop     ebx
  76.         pop     eax
  77.         pop     ecx
  78.  
  79.         push    ebx
  80.         push    ecx
  81.         push    eax
  82.  
  83.         inc     [LOOPBACK_DEVICE.packets_rx]
  84.         add     dword[LOOPBACK_DEVICE.bytes_rx], ecx
  85.         adc     dword[LOOPBACK_DEVICE.bytes_rx + 4], 0
  86.  
  87.         DEBUGF  DEBUG_NETWORK_VERBOSE, "LOOP_input: size=%u\n", ecx
  88.         lea     edx, [eax + 4]
  89.         mov     eax, dword[eax]
  90.         mov     ebx, LOOPBACK_DEVICE
  91.  
  92.         cmp     eax, AF_INET4
  93.         je      IPv4_input
  94.  
  95.         DEBUGF  DEBUG_NETWORK_VERBOSE, "LOOP_input: Unknown packet type=%x\n", ax
  96.  
  97.   .dump:
  98.         DEBUGF  DEBUG_NETWORK_VERBOSE, "LOOP_input: dumping\n"
  99.         call    kernel_free
  100.         add     esp, 4
  101.         ret
  102.  
  103. ;-----------------------------------------------------------------
  104. ;
  105. ; LOOP_output
  106. ;
  107. ; IN:
  108. ;       ecx = packet size
  109. ;       edi = address family
  110. ;
  111. ; OUT:  edi = 0 on error, pointer to buffer otherwise
  112. ;       eax = buffer start
  113. ;       ebx = to device structure
  114. ;       ecx = unchanged (packet size of embedded data)
  115. ;       edx = size of complete buffer
  116. ;
  117. ;-----------------------------------------------------------------
  118. align 4
  119. LOOP_output:
  120.  
  121.         DEBUGF  DEBUG_NETWORK_VERBOSE, "LOOP_output\n"
  122.  
  123.         push    ecx
  124.         push    edi
  125.  
  126.         add     ecx, 4
  127.         cmp     ecx, [LOOPBACK_DEVICE.mtu]
  128.         ja      .out_of_ram
  129.         stdcall kernel_alloc, ecx
  130.         test    eax, eax
  131.         jz      .out_of_ram
  132.         mov     edi, eax
  133.         pop     eax
  134.         stosd
  135.  
  136.         lea     eax, [edi - 4]  ; Set eax to buffer start
  137.         pop     ecx
  138.         lea     edx, [ecx + 4]  ; Set edx to complete buffer size
  139.         mov     ebx, LOOPBACK_DEVICE
  140.  
  141.         inc     [LOOPBACK_DEVICE.packets_tx]
  142.         add     dword[LOOPBACK_DEVICE.bytes_tx], ecx
  143.         adc     dword[LOOPBACK_DEVICE.bytes_tx + 4], 0
  144.  
  145.         DEBUGF  DEBUG_NETWORK_VERBOSE, "LOOP_output: ptr=%x size=%u\n", eax, edx
  146.         ret
  147.  
  148.   .out_of_ram:
  149.         DEBUGF  DEBUG_NETWORK_ERROR, "LOOP_output: out of memory\n"
  150.         add     esp, 4+4
  151.         xor     edi, edi
  152.         ret
  153.  
  154.  
  155.