home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / archives / packetdrivers.tar.gz / pd.tar / src / pktaddr.asm < prev    next >
Assembly Source File  |  1995-06-25  |  5KB  |  227 lines

  1. version    equ    1
  2.  
  3. ;  Copyright, 1989-1992, Russell Nelson, Crynwr Software
  4.  
  5. ;   This program is free software; you can redistribute it and/or modify
  6. ;   it under the terms of the GNU General Public License as published by
  7. ;   the Free Software Foundation, version 1.
  8. ;
  9. ;   This program is distributed in the hope that it will be useful,
  10. ;   but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. ;   GNU General Public License for more details.
  13. ;
  14. ;   You should have received a copy of the GNU General Public License
  15. ;   along with this program; if not, write to the Free Software
  16. ;   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17.  
  18.     include    defs.asm
  19.  
  20. code    segment word public
  21.     assume    cs:code, ds:code
  22.  
  23.     org    80h
  24. phd_dioa    label    byte
  25.  
  26.     org    100h
  27. start:
  28.     jmp    start_1
  29.  
  30. copyleft_msg    label    byte
  31.  db "Packet address version ",'0'+(majver / 10),'0'+(majver mod 10),".",'0'+version," copyright 1990, Russell Nelson.",CR,LF
  32.  db "This program is free software; see the file COPYING for details.",CR,LF
  33.  db "NO WARRANTY; see the file COPYING for details.",CR,LF
  34. crlf_msg    db    CR,LF,'$'
  35.  
  36. their_isr    dd    ?
  37. entry_point    db    ?,?,?,?
  38. ether_bdcst    db    EADDR_LEN dup(-1)    ;ethernet broadcast address.
  39. brd_ether_addr    db    EADDR_LEN dup(-1)    ;board's ethernet address
  40. our_ether_addr    db    EADDR_LEN dup(-1)    ;our ethernet address
  41.  
  42. errorlevel    db    0        ;result to return when we quit.
  43. check_switch    db    0        ;=1 if to compare against a given address.
  44.  
  45. handle        dw    ?
  46.  
  47. bogus_type    db    0,0        ;totally bogus type code.
  48.  
  49. signature    db    'PKT DRVR',0
  50. signature_len    equ    $-signature
  51. no_signature_msg    db    "No packet driver at that address",'$'
  52. usage_msg    db    "usage: pktaddr [-c] <packet_int_no> [<addr>]",'$'
  53.  
  54. eaddr_msg    db    "My Ethernet address is ",'$'
  55. mismatch_msg    db    "Address mismatch",CR,LF,'$'
  56.  
  57. usage_error:
  58.     mov    dx,offset usage_msg
  59. error:
  60.     mov    ah,9
  61.     int    21h
  62.     int    20h
  63.  
  64. start_1:
  65.     cld
  66.  
  67.     mov    dx,offset copyleft_msg
  68.     mov    ah,9
  69.     int    21h
  70.  
  71.     mov    si,offset phd_dioa+1
  72.     cmp    byte ptr [si],CR    ;end of line?
  73.     je    usage_error
  74.  
  75. another_switch:
  76.     call    skip_blanks
  77.     cmp    al,'-'            ;did they specify a switch?
  78.     je    have_switch
  79.     jmp    not_switch
  80. have_switch:
  81.     cmp    byte ptr [si+1],'c'    ;did they specify '-c'?
  82.     je    got_check_switch
  83.     jmp    usage_error        ;no, must be an error.
  84. got_check_switch:
  85.     mov    check_switch,1
  86.     add    si,2
  87.     jmp    another_switch
  88. not_switch:
  89.  
  90.     mov    di,offset entry_point
  91.     call    get_number
  92.  
  93.     mov    di,offset our_ether_addr
  94.     movseg    es,ds
  95.     call    get_eaddr
  96.  
  97.     mov    ah,35h            ;get their packet interrupt.
  98.     mov    al,entry_point
  99.     int    21h
  100.     mov    their_isr.offs,bx
  101.     mov    their_isr.segm,es
  102.  
  103.     lea    di,3[bx]
  104.     mov    si,offset signature
  105.     mov    cx,signature_len
  106.     repe    cmpsb
  107.     je    have_signature
  108.     mov    dx,offset no_signature_msg
  109.     jmp    error
  110. have_signature:
  111.  
  112.     cmp    check_switch,0        ;in check mode, we get the address,
  113.     jne    get_mode        ;  then compare.
  114.  
  115.     movseg    es,ds
  116.     mov    cx,EADDR_LEN
  117.     mov    si,offset our_ether_addr
  118.     mov    di,offset ether_bdcst
  119.     repe    cmpsb
  120.     je    get_mode        ;no address specified.
  121.  
  122.     mov    ah,25            ;set the ethernet address.
  123.     mov    di,offset our_ether_addr
  124.     mov    cx,EADDR_LEN
  125.     call    int_pkt
  126.     call    fatal_error
  127.     jmp    okay
  128. get_mode:
  129.     mov    ah,2            ;access all packets.
  130.     mov    al,1            ;Ethernet class.
  131.     mov    bx,-1            ;generic type.
  132.     mov    dl,0            ;generic number.
  133.     mov    cx,2            ;use a type length of 2
  134.     mov    si,offset bogus_type
  135.     movseg    es,cs
  136.     mov    di,offset our_recv
  137.     call    int_pkt
  138.     call    fatal_error
  139.     mov    handle,ax
  140.  
  141.     mov    ah,6            ;get the ethernet address.
  142.     mov    di,offset brd_ether_addr
  143.     mov    cx,EADDR_LEN
  144.     mov    bx,handle
  145.     call    int_pkt
  146.     jc    bad
  147.  
  148.     mov    dx,offset eaddr_msg
  149.     mov    ah,9
  150.     int    21h
  151.  
  152.     mov    si,offset brd_ether_addr
  153.     call    print_ether_addr
  154.  
  155.     mov    dx,offset crlf_msg    ;can't depend on DOS to newline for us.
  156.     mov    ah,9
  157.     int    21h
  158.  
  159.     cmp    check_switch,0
  160.     je    now_close
  161.  
  162.     movseg    es,ds
  163.     mov    cx,EADDR_LEN
  164.     mov    si,offset our_ether_addr
  165.     mov    di,offset brd_ether_addr
  166.     repe    cmpsb
  167.     je    now_close        ;yes, addresses are equal, return zero.
  168.  
  169.     mov    errorlevel,1        ;different - return 1.
  170.  
  171.     mov    dx,offset mismatch_msg
  172.     mov    ah,9
  173.     int    21h
  174.  
  175.     jmp    short now_close
  176. bad:
  177.     call    print_error
  178.     mov    errorlevel,2
  179. now_close:
  180.     mov    ah,3            ;release_type
  181.     mov    bx,handle
  182.     call    int_pkt
  183.     call    fatal_error
  184.  
  185. okay:
  186.     mov    ah,4ch
  187.     mov    al,errorlevel
  188.     int    21h
  189.  
  190. our_recv:
  191.     or    ax,ax            ;first or second call?
  192.     jne    our_recv_1        ;second -- we ignore the packet
  193.     movseg    es,cs
  194.     mov    di,offset our_buffer
  195. our_recv_1:
  196.     retf
  197.  
  198.  
  199. int_pkt:
  200.     push    ds
  201.     push    es
  202.     pushf
  203.     cli
  204.     call    their_isr
  205.     pop    es
  206.     pop    ds
  207.     ret
  208.  
  209.     include    printea.asm
  210.  
  211.     assume    ds:code
  212.  
  213.     include    pkterr.asm
  214.     include    getea.asm
  215.     include    getnum.asm
  216.     include    skipblk.asm
  217.     include    getdig.asm
  218.     include    digout.asm
  219.     include    chrout.asm
  220.  
  221.     align    4
  222. our_buffer    label    byte
  223.  
  224. code    ends
  225.  
  226.     end    start
  227.