www.pudn.com > Net_apps.rar > ethernetif.asm


;******************************************************************************************************** 
; Copyright 2005 Rico Technology CO., LTD. 
; ALL RIGHTS RESERVED. 
; This software is provided under license and contains proprietary 
; and confidential material which is the property of Rico tech. 
; 
; 
; Description   : asm edition of ethernetif_input() function 
; FileName      : ETHERNETIF_INPUT.ASM 
; Revision      : 0.1, Date : 11/28/05, by jgy 
;******************************************************************************************************** 
 
;******************************************************************************************************** 
;                                    PUBLIC and EXTERNAL REFERENCES 
;******************************************************************************************************** 
 
            PUBLIC _ethernetif_input 
            PUBLIC _FilterPortArr 
            PUBLIC _sqif 
 
            EXTRN  _netif_low_level_input:FAR 
            EXTRN  _netif_low_level_output:FAR 
            EXTRN  _pbuf_header:FAR 
            EXTRN  _PPPoEDiscoveryReceive:FAR 
            EXTRN  _pbuf_free:FAR 
            EXTRN  _PPPReceive:FAR 
            EXTRN  _etharp_ip_input:FAR 
            EXTRN  _etharp_arp_input:FAR 
            EXTRN  _memcmp:FAR 
            EXTRN  _PLC_input:FAR 
 
            EXTRN  _pppoe_cfg:BYTE:3 
            EXTRN  _Searchport:FAR 
 
.MODEL      LARGE 
.CODE 
.186 
 
DGROUP      group DATA, BSS 
            PAGE                                  ; /*$PAGE*/ 
 
ethernetif  segment byte public 'CODE' use16 
            assume cs:ethernetif 
            assume es:nothing, ss:nothing, ds:DGROUP  ; fs:nothing, gs:nothing 
 
_ethernetif_input  PROC FAR 
 
ethtype  = word ptr -14h 
var_12   = word ptr -12h 
var_10   = word ptr -10h 
var_e    = word ptr -0eh 
pbuf     = dword ptr -0ch 
payload  = dword ptr -8 
state    = dword ptr -4 
netif    = dword ptr 6 
 
         enter   14h, 0 
         push    si 
         push    di 
 
         les     bx, [bp + netif] 
         mov     dx, es:[bx + 1eh] 
         mov     ax, es:[bx + 1ch] 
         mov     word ptr [bp + state + 2], dx 
         mov     word ptr [bp + state], ax 
         push    word ptr [bp + state + 2] 
         push    word ptr [bp + state] 
         call    far ptr _netif_low_level_input 
         add     sp, 4 
         mov     word ptr [bp + pbuf + 2], dx 
         mov     word ptr [bp + pbuf], ax 
         mov     ax, word ptr [bp + pbuf] 
         or      ax, word ptr [bp + pbuf + 2] 
         jnz     short loc_1f3 
         jmp     loc_83e 
 
loc_1f3: mov     [bp + var_e], 0 
         mov     [bp + var_10], 0 
         les     bx, [bp + pbuf] 
         mov     dx, es:[bx + 6] 
         mov     ax, es:[bx + 4] 
         mov     word ptr [bp + payload+2], dx 
         mov     word ptr [bp + payload], ax 
         les     bx, [bp + payload] 
         mov     ax, es:[bx + 0Ch] 
         and     ax, 0FFh 
         shl     ax, 8 
         les     bx, [bp + payload] 
         mov     dx, es:[bx + 0Ch] 
         and     dx, 0FF00h 
         shr     dx, 8 
         or      ax, dx 
         mov     [bp + ethtype], ax 
         mov     cx, 5           ; switch 5 cases 
         mov     bx, offset switch_tbl 
 
loc_234: mov     ax, cs:[bx] 
         cmp     ax, [bp + ethtype] 
         jz      short loc_244 
         add     bx, 2 
         loop    loc_234 
         jmp     loc_7f0         ; default 
 
loc_244: jmp     word ptr cs:[bx + 0ah]    ;switch jump 
 
loc_248: push    0fff2h          ; case 0x8863 
         push    word ptr [bp + pbuf + 2] 
         push    word ptr [bp + pbuf] 
         call    far ptr _pbuf_header 
         add     sp, 6 
         mov     ax, word ptr [bp + payload] 
         add     ax, 6 
         push    word ptr [bp + payload + 2] 
         push    ax 
         les     bx, [bp + pbuf] 
         push    word ptr es:[bx + 6] 
         push    word ptr es:[bx + 4] 
         call    far ptr _PPPoEDiscoveryReceive 
         add     SP, 8 
         push    word ptr [bp + pbuf + 2] 
         push    word ptr [bp + pbuf] 
         call    far ptr _pbuf_free 
         add     sp, 4 
         jmp     loc_80a 
 
loc_286: push    0fff2h          ; case 0x8864 
         push    word ptr [bp + pbuf + 2] 
         push    word ptr [bp + pbuf] 
         call    far ptr _pbuf_header 
         add     sp, 6 
         les     bx, [bp + pbuf] 
         les     bx, es:[bx + 4] 
         mov     ax, es:[bx + 2] 
         cmp     ax, word ptr ds:_pppoe_cfg + 2 
         jz      short loc_2aa 
         push    word ptr [bp + pbuf + 2] 
         push    word ptr [bp + pbuf] 
         call    far ptr _pbuf_free 
         add     SP, 4 
         jmp     loc_80a 
 
loc_2aa: push    0fffah 
         push    word ptr [bp + pbuf + 2] 
         push    word ptr [bp + pbuf] 
         call    far ptr _pbuf_header 
         add     sp, 6 
         les     bx, [bp + pbuf] 
         les     bx, es:[bx + 4] 
         mov     ax, es:[bx] 
         and     ax, 0ffh 
         shl     ax, 8 
         les     bx, [bp + pbuf] 
         les     bx, es:[bx + 4] 
         mov     dx, es:[bx] 
         and     dx, 0ff00h 
         shr     dx, 8 
         or      ax, dx 
         cmp     ax, 21h 
         jz      short loc_2e5 
         les     bx, [bp + pbuf] 
         push    word ptr es:[bx + 6] 
         push    word ptr es:[bx + 4] 
         call    far ptr _PPPReceive 
         add     sp, 4 
         push    word ptr [bp + pbuf + 2] 
         push    word ptr [bp + pbuf] 
         call    far ptr _pbuf_free 
         add     sp, 4 
         jmp     loc_80a 
 
loc_2e5: push    0fffeh 
         push    word ptr [bp + pbuf + 2] 
         push    word ptr [bp + pbuf] 
         call    far ptr _pbuf_header 
         add     sp, 6 
         les     bx, [bp + pbuf] 
         mov     dx, es:[bx + 6] 
         mov     ax, es:[bx + 4] 
         mov     word ptr dword_900 + 2, dx 
         mov     word ptr dword_900, ax 
         mov     dx, word ptr dword_900 + 2 
         mov     bx, word ptr dword_900 
         add     bx, 16h 
         adc     dx, 0 
         mov     es, dx 
         mov     di, es:[bx] 
         mov     dx, word ptr dword_900 + 2 
         mov     bx, word ptr dword_900 
         add     bx, 14h 
         adc     dx, 0 
         mov     es, dx 
         mov     ax, es:[bx] 
         mov     [bp + var_12], ax 
         les     bx, dword_900 
         mov     ax, es:[bx + 8] 
         and     ax, 0ffh 
         shl     ax, 8 
         mov     dx, es:[bx + 8] 
         and     dx, 0ff00h 
         shr     dx, 8 
         or      ax, dx 
         and     ax, 0ffh 
         cmp     ax, 11h 
         jnz     short loc_390 
         cmp     di, word ptr ds:_Searchport 
         jnz     short loc_362 
         mov     ax, 1 
         jmp     short loc_364 
 
loc_362: xor     ax, ax 
loc_364: push    ax 
         cmp     di, 0a00fh 
         jnz     short loc_370 
         mov     ax, 1 
         jmp     short loc_372 
 
loc_370: xor     ax, ax 
loc_372: pop     dx 
         or      dx, ax 
         jz      short loc_390 
         push    word ptr [bp + netif + 2] 
         push    word ptr [bp + netif] 
         push    word ptr [bp + pbuf + 2] 
         push    word ptr [bp + pbuf] 
         les     bx, [bp + netif] 
         call    dword ptr es:[bx + 10h] 
         add     sp, 8 
         jmp     loc_80a 
 
loc_390: xor     si, si 
         jmp     loc_42a 
 
loc_395: les     bx, dword_900 
         mov     ax, es:[bx + 8] 
         and     ax, 0ffh 
         shl     ax, 8 
         les     bx, dword_900 
         mov     dx, es:[bx + 8] 
         and     dx, 0ff00h 
         shr     dx, 8 
         or      ax, dx 
         and     ax, 0ffh 
         mov     bx, si 
         imul    bx, 6 
         mov     dl, _FilterPortArr[bx] 
         mov     dh, 0 
         cmp     ax, dx 
         jnz     short loc_429 
         mov     bx, si 
         imul    bx, 6 
         mov     ax, word_8e2[bx] 
         and     ax, 0ffh 
         shl     ax, 8 
         mov     bx, si 
         imul    bx, 6 
         mov     dx, word_8e2[bx] 
         and     dx, 0ff00h 
         shr     dx, 8 
         or      ax, dx 
         cmp     ax, di 
         jz      short loc_411 
         mov     bx, si 
         imul    bx, 6 
         mov     ax, word_8e4[bx] 
         and     ax, 0ffh 
         shl     ax, 8 
         mov     bx, si 
         imul    bx, 6 
         mov     dx, word_8e4[bx] 
         and     dx, 0ff00h 
         shr     dx, 8 
         or      ax, dx 
         cmp     ax, [bp + var_12] 
         jnz     short loc_429 
 
loc_411: push    word ptr [bp + netif + 2] 
         push    word ptr [bp + netif] 
         push    word ptr [bp + pbuf + 2] 
         push    word ptr [bp + pbuf] 
         les     bx, [bp + netif] 
         call    dword ptr es:[bx + 10h] 
         add     SP, 8 
         jmp     short loc_432 
 
loc_429: inc     si 
 
loc_42a: cmp     si, 3 
         jge     short loc_432 
         jmp     loc_395 
 
loc_432: les     bx, dword_900 
         mov     ax, es:[bx + 8] 
         and     ax, 0ffh 
         shl     ax, 8 
         mov     dx, es:[bx + 8] 
         and     dx, 0ff00h 
         shr     dx, 8 
         or      ax, dx 
         and     ax, 0ffh 
         cmp     ax, 6 
         jnz     short loc_472 
         push    word ptr [bp + netif + 2] 
         push    word ptr [bp + netif] 
         push    word ptr [bp + pbuf + 2] 
         push    word ptr [bp + pbuf] 
         les     bx, [bp + netif] 
         call    dword ptr es:[bx + 10h] 
         add     sp, 8 
         jmp     loc_80a 
 
loc_472: les     bx, dword_900 
         mov     ax, es:[bx + 8] 
         and     ax, 0ffh 
         shl     ax, 8 
         mov     dx, es:[bx + 8] 
         and     dx, 0ff00h 
         shr     dx, 8 
         or      ax, dx 
         and     ax, 0ffh 
         cmp     ax, 0aah 
         jnz     short loc_49e 
         mov     ax, 1 
         jmp     short loc_4a0 
 
loc_49e: xor     ax, ax 
 
loc_4a0: push    ax 
         les     bx, dword_900 
         mov     ax, es:[bx + 8] 
         and     ax, 0ffh 
         shl     ax, 8 
         mov     dx, es:[bx + 8] 
         and     dx, 0ff00h 
         shr     dx, 8 
         or      ax, dx 
         and     ax, 0ffh 
         cmp     ax, 1 
         jnz     short loc_4cd 
         mov     ax, 1 
         jmp     short loc_4cf 
 
loc_4cd: xor     ax, ax 
 
loc_4cf: pop     dx 
         or      dx, ax 
         push    dx 
         cmp     [bp + var_12], 7b00h 
         jnz     short loc_4df 
         mov     ax, 1 
         jmp     short loc_4e1 
 
loc_4df: xor     ax, ax 
 
loc_4e1: pop     dx 
         or      dx, ax 
         jz      short loc_4ff 
         push    word ptr [bp + netif + 2] 
         push    word ptr [bp + netif] 
         push    word ptr [bp + pbuf + 2] 
         push    word ptr [bp + pbuf] 
         les     bx, [bp + netif] 
         call    dword ptr es:[bx + 10h] 
         add     sp, 8 
         jmp     loc_80a 
 
loc_4ff: push    word ptr [bp + pbuf + 2] 
         push    word ptr [bp + pbuf] 
         call    far ptr _pbuf_free 
         add     sp, 4 
         jmp     loc_80a 
 
loc_546: push    word ptr [bp + pbuf + 2]     ;case 0x800 
         push    word ptr [bp + pbuf] 
         push    word ptr [bp + netif + 2] 
         push    word ptr [bp + netif] 
         call    far ptr _etharp_ip_input 
         add     sp, 8 
         mov     [bp + var_e], dx 
         mov     [bp + var_10], ax 
         push    0fff2h 
         push    word ptr [bp + pbuf + 2] 
         push    word ptr [bp + pbuf] 
         call    far ptr _pbuf_header 
         add     sp, 6 
         les     bx, [bp + pbuf] 
         mov     dx, es:[bx + 6] 
         mov     ax, es:[bx + 4] 
         mov     word ptr dword_900 + 2, dx 
         mov     word ptr dword_900, ax 
         mov     dx, word ptr dword_900 + 2 
         mov     bx, word ptr dword_900 
         add     bx, 16h 
         adc     dx, 0 
         mov     es, dx 
         mov     di, es:[bx] 
         mov     dx, word ptr dword_900 + 2 
         mov     bx, word ptr dword_900 
         add     bx, 14h 
         adc     dx, 0 
         mov     es, dx 
         mov     ax, es:[bx] 
         mov     [bp + var_12], ax 
         les     bx, dword_900 
         mov     ax, es:[bx + 8] 
         and     ax, 0ffh 
         shl     ax, 8 
         les     bx, dword_900 
         mov     dx, es:[bx + 8] 
         and     dx, 0ff00h 
         shr     dx, 8 
         or      ax, dx 
         and     ax, 0ffh 
         cmp     ax, 11h 
         jnz     short loc_60b 
         cmp     di, word ptr ds:_Searchport 
         jnz     short loc_5dd 
         mov     ax, 1 
         jmp     short loc_5df 
 
loc_5dd: xor     ax, ax 
 
loc_5df: push    ax 
         cmp     di, 0a00fh 
         jnz     short loc_5eb 
         mov     ax, 1 
         jmp     short loc_5ed 
 
loc_5eb: xor     ax, ax 
 
loc_5ed: pop     dx 
         or      dx, ax 
         jz      short loc_60b 
         push    word ptr [bp + netif + 2] 
         push    word ptr [bp + netif] 
         push    word ptr [bp + pbuf + 2] 
         push    word ptr [bp + pbuf] 
         les     bx, [bp + netif] 
         call    dword ptr es:[bx + 10h] 
         add     sp, 8 
         jmp     loc_80a 
 
loc_60b: xor     si, si 
         jmp     loc_6a5 
 
loc_610: les     bx, dword_900 
         mov     ax, es:[bx + 8] 
         and     ax, 0ffh 
         shl     ax, 8 
         les     bx, dword_900 
         mov     dx, es:[bx + 8] 
         and     dx, 0ff00h 
         shr     dx, 8 
         or      ax, dx 
         and     ax, 0ffh 
         mov     bx, si 
         imul    bx, 6 
         mov     dl, _FilterPortArr[bx] 
         mov     dh, 0 
         cmp     ax, dx 
         jnz     short loc_6a4 
         mov     bx, si 
         imul    bx, 6 
         mov     ax, word_8e2[bx] 
         and     ax, 0ffh 
         shl     ax, 8 
         mov     bx, si 
         imul    bx, 6 
         mov     dx, word_8e2[bx] 
         and     dx, 0ff00h 
         shr     dx, 8 
         or      ax, dx 
         cmp     ax, di 
         jz      short loc_68c 
         mov     bx, si 
         imul    bx, 6 
         mov     ax, word_8e4[bx] 
         and     ax, 0ffh 
         shl     ax, 8 
         mov     bx, si 
         imul    bx, 6 
         mov     dx, word_8e4[bx] 
         and     dx, 0ff00h 
         shr     dx, 8 
         or      ax, dx 
         cmp     ax, [bp + var_12] 
         jnz     short loc_6a4 
 
loc_68c: push    word ptr [bp + netif+ 2] 
         push    word ptr [bp + netif] 
         push    word ptr [bp + pbuf + 2] 
         push    word ptr [bp + pbuf] 
         les     bx, [bp + netif] 
         call    dword ptr es:[bx + 10h] 
         add     sp, 8 
         jmp     short loc_6ad 
 
loc_6a4: inc     si 
 
loc_6a5: cmp     si, 3 
         jge     short loc_6ad 
         jmp     loc_610 
 
loc_6ad: les     bx, dword_900 
         mov     ax, es:[bx + 8] 
         and     ax, 0ffh 
         shl     ax, 8 
         les     bx, dword_900 
         mov     dx, es:[bx + 8] 
         and     dx, 0ff00h 
         shr     dx, 8 
         or      ax, dx 
         and     ax, 0ffh 
         cmp     ax, 6 
         jnz     short loc_6d9 
         mov     ax, 1 
         jmp     short loc_6db 
 
loc_6d9: xor     ax, ax 
 
loc_6db: push    ax 
         les     bx, dword_900 
         mov     ax, es:[bx + 8] 
         and     ax, 0ffh 
         shl     ax, 8 
         les     bx, dword_900 
         mov     dx, es:[bx + 8] 
         and     dx, 0ff00h 
         shr     dx, 8 
         or      ax, dx 
         and     ax, 0ffh 
         cmp     ax, 0aah 
         jnz     short loc_708 
         mov     ax, 1 
         jmp     short loc_70a 
 
loc_708: xor     ax, ax 
 
loc_70a: pop     dx 
         or      dx, ax 
         push    dx 
         les     bx, dword_900 
         mov     ax, es:[bx + 8] 
         and     ax, 0ffh 
         shl     ax, 8 
         mov     dx, es:[bx + 8] 
         and     dx, 0ff00h 
         shr     dx, 8 
         or      ax, dx 
         and     ax, 0ffh 
         cmp     ax, 1 
         jnz     short loc_73a 
         mov     ax, 1 
         jmp     short loc_73c 
 
loc_73a: xor     ax, ax 
 
loc_73c: pop     dx 
         or      dx, ax 
         push    dx 
         mov     dx, word ptr dword_900 + 2 
         mov     bx, word ptr dword_900 
         add     bx, 14h 
         adc     dx, 0 
         mov     es, dx 
         cmp     word ptr es:[bx], 7b00h 
         jnz     short loc_75c 
         mov     ax, 1 
         jmp     short loc_75e 
 
loc_75c: xor     ax, ax 
 
loc_75e: pop     dx 
         or      dx, ax 
         jz      short loc_77c 
         push    word ptr [bp + netif + 2] 
         push    word ptr [bp + netif] 
         push    word ptr [bp + pbuf + 2] 
         push    word ptr [bp + pbuf] 
         les     bx, [bp + netif] 
         call    dword ptr es:[bx + 10h] 
         add     sp, 8 
         jmp     loc_80a 
 
loc_77c: push    6 
         mov     ax, word ptr [bp + netif] 
         add     ax, 25h 
         push    word ptr [bp + netif + 2] 
         push    ax 
         push    word ptr [bp + payload + 2] 
         push    word ptr [bp + payload] 
         call    far ptr _memcmp 
         add     sp, 0ah 
         push    ax 
         push    6 
         mov     ax, word ptr [bp + netif] 
         add     ax, 25h 
         push    word ptr [bp + netif + 2] 
         push    ax 
         mov     ax, word ptr [bp + payload] 
         add     ax, 6 
         push    word ptr [bp + payload + 2] 
         push    ax 
         call    far ptr _memcmp 
         add     sp, 0ah 
         pop     dx 
         test    dx, ax 
         jz      short loc_7c8 
         push    word ptr [bp + pbuf + 2] 
         push    word ptr [bp + pbuf] 
         call    far ptr _pbuf_free 
         add     sp, 4 
 
loc_7c8: jmp     short loc_80a 
 
loc_7ca: push    word ptr [bp + pbuf + 2]      ; case 0x0806 
         push    word ptr [bp + pbuf] 
         les     bx, [bp + state] 
         push    word ptr es:[bx + 2] 
         push    word ptr es:[bx] 
         push    word ptr [bp + netif + 2] 
         push    word ptr [bp + netif] 
         call    far ptr _etharp_arp_input 
         add     sp, 0Ch 
         mov     [bp + var_e], dx 
         mov     [bp + var_10], ax 
         jmp     short loc_80a 
 
loc_7ce: push    word ptr [bp + pbuf + 2]      ; case 0x887b 
         push    word ptr [bp + pbuf] 
         call    far ptr _PLC_input 
         add     sp, 4 
         push    word ptr [bp + pbuf + 2] 
         push    word ptr [bp + pbuf] 
         call    far ptr _pbuf_free 
         add     sp, 4 
         jmp     short loc_80a 
 
loc_7f0: push    word ptr [bp + pbuf + 2]      ; default 
         push    word ptr [bp + pbuf] 
         call    far ptr _pbuf_free 
         add     sp, 4 
         mov     word ptr [bp + pbuf + 2], 0 
         mov     word ptr [bp + pbuf], 0 
 
loc_80a: mov     ax, [bp + var_10] 
         or      ax, [bp + var_e] 
         jz      short loc_83e 
         push    [bp + var_e] 
         push    [bp + var_10] 
         push    word ptr [bp + state + 2] 
         push    word ptr [bp + state] 
         call    far ptr _netif_low_level_output 
         add     sp, 8 
         push    [bp + var_e] 
         push    [bp + var_10] 
         call    far ptr _pbuf_free 
         add     sp, 4 
         mov     [bp + var_e], 0 
         mov     [bp + var_10], 0 
 
loc_83e: pop     di 
         pop     si 
         leave 
         retf 
_ethernetif_input  endp 
 
            db  0 
switch_tbl  dw  0800h, 0806h, 8863h, 8864h, 887bh 
            dw  offset loc_546 
            dw  offset loc_7ca 
            dw  offset loc_248 
            dw  offset loc_286 
            dw  offset loc_7ce 
 
ethernetif  ends 
 
DATA  segment word public 'DATA' use16 
      assume cs: DATA 
 
_FilterPortArr  db 11h 
                align 2 
word_8e2        dw 44h 
word_8e4        dw 43h 
                db 11h 
                db 0 
                db 0dch 
                db 5 
                db 0dch 
                db 5 
                db 11h 
                db 0 
                db 3fh 
                db 0dh 
                db 35h 
                db 0 
DATA            ends 
 
BSS  segment word public 'BSS' use16 
     assume cs: BSS 
     assume es: nothing, ss: nothing, ds:DGROUP     ; fs: nothing, gs: nothing 
 
dword_900       dd ? 
_sqif           dw ? 
word_906        dw ? 
BSS             ends 
 
                end