Subversion Repositories Kolibri OS

Rev

Rev 3600 | Rev 3610 | 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.         .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.         DEBUGF  DEBUG_NETWORK_VERBOSE, "LOOP_input: size=%u\n", ecx
  84.         lea     edx, [eax + 4]
  85.         mov     eax, dword[eax]
  86.         mov     ebx, LOOPBACK_DEVICE
  87.  
  88.         cmp     eax, AF_INET4
  89.         je      IPv4_input
  90.  
  91.         DEBUGF  DEBUG_NETWORK_VERBOSE, "LOOP_input: Unknown packet type=%x\n", ax
  92.  
  93.   .dump:
  94.         DEBUGF  DEBUG_NETWORK_VERBOSE, "LOOP_input: dumping\n"
  95.         call    kernel_free
  96.         add     esp, 4
  97.         ret
  98.  
  99. ;-----------------------------------------------------------------
  100. ;
  101. ; LOOP_output
  102. ;
  103. ; IN:
  104. ;     ecx = packet size
  105. ;      di = protocol
  106. ;
  107. ; OUT: edi = 0 on error, pointer to buffer otherwise
  108. ;      eax = buffer start
  109. ;      ebx = to device structure
  110. ;      ecx = unchanged (packet size of embedded data)
  111. ;      edx = size of complete buffer
  112. ;
  113. ;-----------------------------------------------------------------
  114. align 4
  115. LOOP_output:
  116.  
  117.         DEBUGF  DEBUG_NETWORK_VERBOSE, "LOOP_output\n"
  118.  
  119.         push    ecx
  120.         push    edi
  121.  
  122.         add     ecx, 4
  123.         cmp     ecx, [LOOPBACK_DEVICE.mtu]
  124.         ja      .out_of_ram
  125.         stdcall kernel_alloc, ecx
  126.         test    eax, eax
  127.         jz      .out_of_ram
  128.         mov     edi, eax
  129.         pop     eax
  130.         stosd
  131.  
  132.         lea     eax, [edi - 4]  ; Set eax to buffer start
  133.         pop     ecx
  134.         lea     edx, [ecx + 4]  ; Set edx to complete buffer size
  135.         mov     ebx, LOOPBACK_DEVICE
  136.  
  137.   .done:
  138.         DEBUGF  DEBUG_NETWORK_VERBOSE, "LOOP_output: ptr=%x size=%u\n", eax, edx
  139.         ret
  140.  
  141.   .out_of_ram:
  142.         DEBUGF  DEBUG_NETWORK_VERBOSE, "LOOP_output: failed\n"
  143.         add     esp, 4+4
  144.         xor     edi, edi
  145.         ret
  146.  
  147.  
  148.