⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ppp.asm

📁 Application sources:A084.ZIP
💻 ASM
📖 第 1 页 / 共 4 页
字号:
;
;    PPP.ASM
;
;    Compile with FASM for Menuet
;    This program dials into an ISP and establishes a PPP connection
;
;    Version 11    26th January 2004
;
;    This code is a port of the PPP dialer program by Microchip, from
;    their application note AN724
;    It has been ported by Mike Hibbett mikeh@oceanfree.net for Menuet
;
;    26/1/04 - Mike Hibbett - added support for com port selected by
;                             stackcfg
;    2/5/03 - Shrirang - Added Abort Strings To sendwait to get out early
;                        if modem sends abort strings like NO CARRIER etc.
;
;    The original copyright statement follows
;//////////////////////////////////////////////////////////////////////////
;//
;//PING.C  version 1.10  July 29/99 (C)opyright by Microchip Technology Inc
;//
;//////////////////////////////////////////////////////////////////////////

FALSE               equ 0
TRUE                equ 1
DEBUG_OUTPUT        equ FALSE       ; If FALSE, not debugging info outputted
DEBUG_PPP_OUTPUT    equ FALSE        ; write PPP status msgs to debug board?
DEBUG_PORT2_OUTPUT  equ FALSE       ; write debug data also to com2


BAUD_9600       equ         12
BAUD_57600      equ         2
; The next line sets the baud rate of the connection to the modem
BAUDRATE        equ         BAUD_57600


LINE_END        equ         0x0D        ; End of input data character


; Defines for Internet constants
REQ         equ      1   ; Request options list for PPP negotiations
PPP_ACK     equ      2   ; Acknowledge options list for PPP negotiations
PPP_NAK     equ      3   ; Not acknowledged options list for PPP neg
REJ         equ      4   ; Reject options list for PPP negotiations
TERM            equ  5   ; Termination packet for LCP to close connectio
LCP_ECHO_REQ    equ  9
LCP_ECHO_REP    equ  10
IP        equ    0x0021   ; Internet Protocol packet
IPCP      equ    0x8021   ; Internet Protocol Configure Protocol packet
CCP       equ    0x80FD   ; Compression Configure Protocol packet
LCP       equ    0xC021   ; Link Configure Protocol packet
PAP       equ    0xC023   ; Password Authenication Protocol packet


MaxRx           equ         1500
MaxTx           equ         1500




use32

     org     0x0

     db      'MENUET00'      ; 8 byte id
     dd      38              ; required os
     dd      STARTAPP        ; program start
     dd      I_END           ; program image size
     dd      0x100000        ; required amount of memory
        ; esp = 0x7FFF0
     dd      0x00000000      ; reserved=no extended header


include "CHAT.INC"                  ; Hosts modem chatting routine


STARTAPP:
;    mov     eax, 0x3f8
;    mov     [comport], eax
;    mov     eax, 4
;    mov     [comirq], eax

    ; Get the com port & IRQ to use from the kernel stack config option

    mov   eax, 52                 ; Stack Interface
    mov   ebx, 0     ; read configuration word
    int   0x40
    mov  ecx, eax
    shr  ecx, 16     ; get the port address
    mov  [comport], ecx
    shr  eax, 8
    and  eax, 0x000000FF   ; get the irq
 mov  [comirq], eax


 mov  eax, [comport]
 add  eax, 0x01000000
 mov [irqtable], eax


    call    enable_port

appdsp:
    mov     eax, welcomep
    mov     [prompt], eax               ; set up prompt to display
    mov     al, [welcomep_len]
    mov     [prompt_len], al

    call    draw_window                 ; at first, draw the window


apploop:
    mov     eax, 23                     ; wait here for event
    mov     ebx, 20
    int     0x40

    cmp     eax, 1                      ; redraw request ?
    je      red
    cmp     eax, 2                      ; key in buffer ?
    je      key
    cmp     eax, 3                      ; button in buffer ?
    je      button
    mov     ebx, [comirq]
    add     ebx, 16
    cmp     eax, ebx
    je      flush_input                 ; Dont want serial data yet
    jmp     apploop

red:                                    ; redraw
    call    draw_window
    jmp     apploop

key:                                    ; key - ignore
    mov     eax, 2                      ; just read it
    int     0x40
    jmp     apploop

button:                                 ; button
    mov     eax, 17                     ; get id
    int     0x40

    cmp     ah, 1                       ; close program ?
    jne     noclose

    mov     esi, hangupWait
    mov     edi, hangupSend
    mov     edx, 1000                   ; Allow sendwait 10s
    call    sendwait

    call    disable_port

    mov     eax, -1                     ; close this program
    int     0x40
    jmp     apploop

noclose:
    cmp     ah, 2                       ; Dial Button pressed?
    jne     apploop

    mov     eax, conp
    mov     [prompt], eax               ; set up prompt to display
    mov     al,[conp_len]
    mov     [prompt_len], al
    call    draw_window

    jmp     dialloop                    ; connect to the host


    ; Data received, so get it, and throw it away at this point
flush_input:
    mov  eax,42
    mov  ebx, [comirq]
    int  0x40

    mov  eax,11                     ; This will return 0 most of the time
    int  0x40
    mov     ebx, [comirq]
    add     ebx, 16
    cmp     eax, ebx
   je   flush_input
    jmp  apploop


dialloop:
    call    modem_chat                  ; Try chatting with the modem

    cmp     eax, 1                      ; Did it work? ( = 1)
    jne     appdsp

    ; OK, we are now connected.

    mov     eax, pppOnp
    mov     [prompt], eax               ; set up prompt to display
    mov     al,[pppOnp_len]
    mov     [prompt_len], al
    call    draw_window

    mov     eax, 23
    mov     ebx, 100
    int     0x40                        ; wait for 1s to display message

    call    PPPStateMachine         ; This is the main code

    jmp     appdsp




;****************************************************************************
;    Function
;       PPPStateMachine
;
;   Description
;       Handles PPP link establishment
;
;****************************************************************************
PPPStateMachine:
    ; Start the timer
    xor     eax, eax
    call    settimer

PPPLoop:

    mov     eax, 11                 ; check event
    int     0x40
    cmp     eax, 3
    jne     PPPLred
        ; button pressed
    mov     eax, 17                     ; get id
    int     0x40


    mov     eax, hangp
    mov     [prompt], eax               ; set up prompt to display
    mov     al,[hangp_len]
    mov     [prompt_len], al
    call    draw_window

    mov     esi, hangupWait
    mov     edi, hangupSend
    mov     edx, 1000                   ; Allow sendwait 10s
    call    sendwait

    call    disable_port
    mov     eax, -1                     ; close this program
    int     0x40
    jmp     PPPLoop

PPPLred:
    cmp     eax, 1                      ; redraw request ?
    jne     PPPLoop0

    call    draw_window
    jmp     PPPLoop

PPPLoop0:
    mov     ebx, [comirq]
    add     ebx, 16
    cmp     eax, ebx
    jne     ppp_002                    ; check for tx to send


    ; we have data in the rx buffer, get it

    mov     eax, 42
    mov     ebx, [comirq]      ; ecx will return 0 =data read, 1 =no data
    int     0x40               ; or 2 =not irq owner

    inc     dword [rxbytes]

    cmp     bl, 0x7E
    jne     ppp_001a

    mov     eax, [rx_ptr]
    cmp     eax, 0
    jz      ppp_001
    mov     eax, [checksum1]
    cmp     eax, 0xf0b8
    jne     ppp_001


    movzx   eax, byte [rx_str + 3]
    mov     ah, [rx_str + 2]
    mov     [packet], eax

ppp_001:
    mov     eax, [extended]
    and     eax, 0x7e
    mov     [extended], eax
    xor     eax, eax
    mov     [rx_ptr], eax

    mov     eax, 0xffff
    mov     [checksum1], eax
    jmp     ppp_003

ppp_001a:
    cmp     bl, 0x7D
    jne     ppp_001b

    mov     eax, [extended]
    or      eax, 0x01
    mov     [extended], eax
    jmp     ppp_003

ppp_001b:
    mov     eax, [extended]
    test    eax, 0x01
    jz      ppp_001c

    xor     bl, 0x20
    and     eax, 0xFE
    mov     [extended], eax

ppp_001c:
    mov     edx, [rx_ptr]
    cmp     edx, 0
    jnz     ppp_001d
    cmp     bl, 0xff
    je      ppp_001d

    mov     [rx_str + edx], byte 0xff
    inc     edx

ppp_001d:
    cmp     edx, 1
    jnz     ppp_001e
    cmp     bl, 0x03
    je      ppp_001e

    mov     [rx_str + edx], byte 0x03
    inc     edx

ppp_001e:
    cmp     edx, 2
    jnz     ppp_001f
    test    bl, 0x01
    jz      ppp_001f

    mov     [rx_str + edx], byte 0
    inc     edx

ppp_001f:
    mov     [rx_str + edx], bl
    inc     edx
    mov     [rx_ptr], edx

    cmp     edx, MaxRx
    jle     ppp_001g
    mov     edx, MaxRx
    mov     [rx_ptr], edx

ppp_001g:
    ; do checksum calc
    mov     eax, [checksum1]
    xor     bh, bh
    xor     ax, bx
    call    calc
    mov     ebx, [checksum1]
    and     ebx, 0xffff
    shr     ebx, 8
    xor     eax, ebx
    mov     [checksum1], eax
    jmp     ppp_003

ppp_002:
    mov     eax, [tx_end]
    cmp     eax, 0
    jz      ppp_003

    mov     ebx, [tx_ptr]
    mov     cl, [tx_str + ebx]

    cmp     ebx, eax
    jne     ppp_002a
    mov     [tx_end], dword 0
    mov     cl, '~'
    jmp     ppp_002d

ppp_002a:
    mov     eax, [extended]
    and     eax, 0x02
    jz      ppp_002b

    xor     cl, 0x20
    mov     eax, [extended]
    and     eax, 0xFD
    mov     [extended], eax
    inc     [tx_ptr]
    jmp     ppp_002d

ppp_002b:
    cmp     cl, 0x20
    jl      ppp_002b1
    cmp     cl, 0x7d
    je      ppp_002b1
    cmp     cl, 0x7e
    je      ppp_002b1
    jmp     ppp_002c

ppp_002b1:
    mov     eax, [extended]
    or      eax, 0x02
    mov     [extended], eax
    mov     cl, 0x7d
    jmp     ppp_002d

ppp_002c:
    mov     eax, [tx_ptr]
    cmp     eax, 0
    jnz     ppp_002c1
    mov     cl, '~'

ppp_002c1:
    inc     [tx_ptr]

ppp_002d:
    ; Test for tx ready.

    push    ecx

wait_txd2:
    mov     eax,43
    mov     ecx, [comport]
    add     ecx, 0x80000000 + 5
    int     0x40
    and     bl, 0x40
    cmp     bl, 0
    jz      wait_txd2                  ; loop until free

    pop     ebx


    ; send the character

    inc     dword [txbytes]

    mov     ecx, [comport]
    mov     eax, 43
    int     0x40

ppp_003:
    mov     eax, [packet]
    cmp     eax, LCP
    jne     ppp_004

    mov     al, [rx_str + 4]
    cmp     al, REQ
    jne     ppp_003b

    ; Debugging output to debug board
    pusha
    mov     esi, RX_LCP_REQ
    call    debug_output
    popa

    mov     eax, [state]
    and     eax, 0xfd
    mov     [state], eax

    mov     ebx, 0xc6
    push    eax
    call    TestOptions
    pop     eax
    cmp     edx, 0
    jz      ppp_003g

    cmp     edx, 1
    jle     ppp_003h

    mov     edx, PPP_ACK
    cmp     eax, 3
    jge     ppp_003i

    or      eax, 0x02
    mov     [state], eax
    jmp     ppp_003i

ppp_003h:
    mov     bl, 0xc0
    mov     [rx_str + 10], bl
    mov     edx, PPP_NAK
    jmp     ppp_003i

ppp_003g:
    mov     edx, REJ

ppp_003i:

    mov     ebx, LCP
    mov     ecx, edx
    movzx   edx, byte [rx_str + 5]
    mov     esi, rx_str + 7
    call    MakePacket

    mov     eax, 0
    call    settimer
    jmp     ppp_003a

ppp_003b:
    cmp     al, PPP_ACK
    jne     ppp_003c

    ; Debugging output to debug board
    pusha
    mov     esi, RX_LCP_ACK
    call    debug_output
    popa

    mov     eax, [number]
    cmp     al, [rx_str+5]
    jne     ppp_003a

    mov     eax, [state]
    cmp     eax, 3
    jge     ppp_003a
    or      eax, 0x01
    mov     [state], eax
    jmp     ppp_003a

ppp_003c:
    cmp     al, PPP_NAK
    jne     ppp_003d

    ; Debugging output to debug board
    pusha
    mov     esi, RX_LCP_NAK
    call    debug_output
    popa

    mov     eax, [state]
    and     eax, 0xfe
    mov     [state], eax
    jmp     ppp_003a

ppp_003d:
    cmp     al, REJ
    jne     ppp_003e

    ; Debugging output to debug board
    pusha
    mov     esi, RX_LCP_REJ
    call    debug_output
    popa

    mov     eax, [state]
    and     eax, 0xfe
    mov     [state], eax
    jmp     ppp_003a

ppp_003e:
    cmp     al, TERM
    jne     ppp_003j
    jmp     ppp_003a

ppp_003j:
    cmp     al, LCP_ECHO_REQ
    jne     ppp_003a

    ; Debugging output to debug board
    pusha

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -