home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / archives / packetdrivers.tar.gz / pd.tar / src / pktring.asm < prev    next >
Assembly Source File  |  1992-02-10  |  11KB  |  565 lines

  1. version    equ    0
  2. ;History:4,1
  3.  
  4. ;  Copyright, 1989-1992, Russell Nelson, Crynwr Software
  5.  
  6. ;   This program is free software; you can redistribute it and/or modify
  7. ;   it under the terms of the GNU General Public License as published by
  8. ;   the Free Software Foundation, version 1.
  9. ;
  10. ;   This program is distributed in the hope that it will be useful,
  11. ;   but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ;   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. ;   GNU General Public License for more details.
  14. ;
  15. ;   You should have received a copy of the GNU General Public License
  16. ;   along with this program; if not, write to the Free Software
  17. ;   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  
  19.     include    defs.asm
  20.  
  21. code    segment word public
  22.     assume    cs:code, ds:code
  23.  
  24.     org    80h
  25. phd_dioa    label    byte
  26.  
  27.     org    100h
  28. start:
  29.     jmp    start_1
  30.  
  31. copyleft_msg    label    byte
  32.  db "Packet ringer version ",'0'+(majver / 10),'0'+(majver mod 10),".",'0'+version," copyright 1990, Russell Nelson.",CR,LF
  33.  db "This program is free software; see the file COPYING for details.",CR,LF
  34.  db "NO WARRANTY; see the file COPYING for details.",CR,LF
  35. crlf_msg    db    CR,LF,'$'
  36.  
  37. int_pkt    macro    num
  38.     pushf
  39.     cli
  40.     call    their_isr_&num
  41.     endm
  42.  
  43. their_isr_1    dd    ?
  44. their_isr_2    dd    ?
  45. packet_int_1    db    ?,?,?,?
  46. packet_int_2    db    ?,?,?,?
  47. send_count    dw    RUNT
  48. handle        dw    ?
  49. transmit_count    dw    ?
  50. receive_count    dw    ?
  51. packet_mode    dw    ?
  52. this_mode    dw    ?
  53.  
  54. signature    db    'PKT DRVR',0
  55. signature_len    equ    $-signature
  56.  
  57. no_signature_msg    db    "No packet driver at that address",'$'
  58. usage_msg    db    "usage: pktring [-m] <packet_int_1> <packet_int_2>",'$'
  59. sending_msg    db    "Sending from ",'$'
  60. to_msg        db    " to ",'$'
  61.  
  62. not_implemented    db    "xx ",'$'
  63. current_mode    db    "-> ",'$'
  64. two_spaces    db    "   ",'$'
  65.  
  66. test_modes    db    ?        ;nonzero if we should test the modes.
  67.  
  68. mode_names    dw    mode_1_msg,mode_2_msg,mode_3_msg,mode_4_msg
  69.         dw    mode_5_msg,mode_6_msg
  70.  
  71. mode_1_msg    db    "1) Turn off receiver",'$'
  72. mode_2_msg    db    "2) Receive only packets sent to this interface",'$'
  73. mode_3_msg    db    "3) Mode 2 plus broadcast",'$'
  74. mode_4_msg    db    "4) Mode 3 plus limited multicast",'$'
  75. mode_5_msg    db    "5) Mode 3 plus all multicast",'$'
  76. mode_6_msg    db    "6) All packets",'$'
  77.  
  78. mode_code    dw    mode_1_tester,mode_2_tester,mode_3_tester,mode_4_tester
  79.         dw    mode_5_tester,mode_6_tester
  80.  
  81. mode_good_msg    db    " passed",CR,LF,'$'
  82. mode_bad_msg    db    " FAILED!",7,CR,LF,'$'
  83.  
  84. usage_error:
  85.     mov    dx,offset usage_msg
  86. error:
  87.     mov    ah,9
  88.     int    21h
  89.     int    20h
  90.  
  91. start_1:
  92.     cld
  93.  
  94.     mov    dx,offset copyleft_msg
  95.     mov    ah,9
  96.     int    21h
  97.  
  98.     mov    si,offset phd_dioa+1
  99.     cmp    byte ptr [si],CR    ;end of line?
  100.     je    usage_error
  101.  
  102. another_switch:
  103.     call    skip_blanks
  104.  
  105.     cmp    al,'-'            ;did they specify a switch?
  106.     jne    not_switch
  107.     cmp    byte ptr [si+1],'m'    ;did they specify '-m'?
  108.     je    got_mode_switch
  109.     jmp    usage_error        ;no, must be an error.
  110. got_mode_switch:
  111.     mov    test_modes,1
  112.     add    si,2
  113.     jmp    another_switch
  114.  
  115. not_switch:
  116.     mov    di,offset packet_int_1
  117.     call    get_number
  118.     mov    di,offset packet_int_2
  119.     call    get_number
  120.  
  121.     call    skip_blanks        ;check for the end of the line.
  122.     cmp    al,CR
  123.     jne    usage_error
  124.  
  125.     mov    sp,offset start        ;now that we're finished with
  126.                     ;the parameters, put our stack there.
  127.  
  128.     mov    ah,35h            ;get their packet interrupt.
  129.     mov    al,packet_int_1
  130.     int    21h
  131.     mov    their_isr_1.offs,bx
  132.     mov    their_isr_1.segm,es
  133.  
  134.     lea    di,3[bx]
  135.     mov    si,offset signature
  136.     mov    cx,signature_len
  137.     repe    cmpsb
  138.     je    signature_1_ok
  139.     jmp    no_signature_err
  140. signature_1_ok:
  141.  
  142.     mov    ah,35h            ;get their packet interrupt.
  143.     mov    al,packet_int_2
  144.     int    21h
  145.     mov    their_isr_2.offs,bx
  146.     mov    their_isr_2.segm,es
  147.  
  148.     lea    di,3[bx]
  149.     mov    si,offset signature
  150.     mov    cx,signature_len
  151.     repe    cmpsb
  152.     je    signature_2_ok
  153.     jmp    no_signature_err
  154. signature_2_ok:
  155.  
  156.     mov    dx,offset sending_msg
  157.     mov    ah,9
  158.     int    21h
  159.  
  160.     push    ds
  161.     mov    ax,1ffh            ;driver_info
  162.     int_pkt    2
  163.     jc    saying_2_1
  164.     pushf
  165. saying_2:
  166.     lodsb
  167.     call    chrout
  168.     cmp    byte ptr ds:[si],0
  169.     jne    saying_2
  170.  
  171.     popf
  172. saying_2_1:
  173.     pop    ds
  174.     call    fatal_error
  175.  
  176.     mov    dx,offset to_msg
  177.     mov    ah,9
  178.     int    21h
  179.  
  180.     push    ds
  181.     mov    ax,1ffh            ;driver_info
  182.     int_pkt    1
  183.     jc    saying_1_1
  184.     pushf
  185.     push    ax
  186. saying_1:
  187.     lodsb
  188.     call    chrout
  189.     cmp    byte ptr ds:[si],0
  190.     jne    saying_1
  191.  
  192.     pop    ax
  193.     popf
  194. saying_1_1:
  195.     pop    ds
  196.     call    fatal_error
  197.  
  198.     push    ax
  199.     push    dx
  200.     mov    dx,offset crlf_msg
  201.     mov    ah,9
  202.     int    21h
  203.     pop    dx
  204.     pop    ax
  205.  
  206.     mov    ah,2            ;access all packets.
  207.     mov    al,ch            ;their class from driver_info().
  208.     mov    bx,dx            ;their type from driver_info().
  209.     mov    dl,cl            ;their number from driver_info().
  210.     mov    cx,0            ;type length of zero.
  211.     push    cs            ;es:di -> our receiver.
  212.     pop    es
  213.     mov    di,offset our_recv
  214.     int_pkt    1
  215.     call    fatal_error
  216.     mov    handle,ax
  217.  
  218.     cmp    test_modes,0        ;should we test the receive modes?
  219.     je    get_their_address    ;no.
  220.  
  221.     mov    ah,21            ;get the receive mode.
  222.     mov    bx,handle
  223.     int_pkt    1
  224.     jc    bad_1
  225.     mov    packet_mode,ax
  226.  
  227.     mov    this_mode,1        ;start trying with mode 1.
  228. try_mode:
  229.     cmp    this_mode,4        ;skip modes 4 and 5 (don't work yet).
  230.     jne    try_mode_1
  231.     mov    this_mode,6
  232. try_mode_1:
  233.     cmp    this_mode,6        ;have we hit the last mode?
  234.     ja    no_more_modes        ;yes.
  235.  
  236.     mov    ah,20            ;set the receive mode.
  237.     mov    bx,handle
  238.     mov    cx,this_mode
  239.     int_pkt    1
  240.     jc    tried_mode        ;we tried it, and it didn't work.
  241.  
  242.     mov    bx,this_mode        ;print the name of this mode.
  243.     shl    bx,1
  244.     mov    ah,9
  245.     mov    dx,mode_names[bx-2]
  246.     int    21h
  247.  
  248.     mov    bx,this_mode        ;do the test for this mode.
  249.     shl    bx,1
  250.     call    mode_code[bx-2]
  251.     mov    dx,offset mode_good_msg    ;report success.
  252.     jnc    mode_good
  253.     mov    dx,offset mode_bad_msg    ;report failure.
  254. mode_good:
  255.     mov    ah,9
  256.     int    21h
  257.  
  258. tried_mode:
  259.  
  260.     inc    this_mode        ;try the next mode.
  261.     jmp    try_mode
  262.  
  263. no_more_modes:
  264.  
  265.     mov    ah,20            ;set the receive mode.
  266.     mov    bx,handle
  267.     mov    cx,packet_mode
  268.     int_pkt    1
  269. bad_1:
  270.     jnc    get_their_address
  271.     jmp    bad
  272.  
  273. get_their_address:
  274.  
  275.     mov    ah,6            ;get the destination's address.
  276.     mov    bx,handle
  277.     mov    cx,EADDR_LEN
  278.     push    cs            ;es:di -> to address.
  279.     pop    es
  280.     mov    di,offset our_buffer
  281.     int_pkt    1
  282.     jc    bad_1
  283.  
  284. wait_for_key:
  285.     inc    send_count
  286.     cmp    send_count,GIANT    ;too big?
  287.     jbe    length_ok
  288.     mov    transmit_count,0    ;zero the counts.
  289.     mov    receive_count,0
  290.     mov    send_count,RUNT        ;yes, reset it back down again.
  291. length_ok:
  292.  
  293.     mov    cx,send_count
  294.     call    send_packet
  295.     jc    bad
  296.  
  297.     inc    transmit_count
  298.  
  299.     mov    ax,transmit_count
  300.     call    wordout
  301.  
  302.     mov    al,' '
  303.     call    chrout
  304.  
  305.     mov    ax,receive_count
  306.     call    wordout
  307.  
  308.     mov    al,CR
  309.     call    chrout
  310.  
  311.     mov    ah,1            ;check for any key.
  312.     int    16h
  313.     je    wait_for_key        ;no key -- keep waiting.
  314.  
  315.     mov    ah,0            ;read a key.
  316.     int    16h
  317.  
  318.     mov    ah,3            ;release the handle.
  319.     mov    bx,handle
  320.     int_pkt    1
  321.     jc    bad
  322.  
  323.     int    20h
  324.  
  325. all_done:
  326.     xor    bx,bx            ;only release the handle once.
  327.     xchg    bx,handle
  328.     or    bx,bx
  329.     je    all_done_1        ;we've already released it.
  330.     mov    ah,3            ;release_type
  331.     int_pkt    1
  332.     jc    bad
  333. all_done_1:
  334.     int    20h
  335.  
  336. bad:
  337.     call    print_error
  338. okay:
  339.     jmp    all_done
  340.  
  341.  
  342. no_signature_err:
  343.     mov    dx,offset no_signature_msg
  344.     mov    ah,9
  345.     int    21h
  346.     int    20h
  347.  
  348.  
  349.     assume    ds:nothing
  350. our_recv:
  351.     or    ax,ax            ;first or second call?
  352.     jne    our_recv_1        ;second -- we ignore the packet
  353.     push    cs
  354.     pop    es
  355.     mov    di,offset our_buffer + GIANT
  356.     db    0cbh            ;masm 4.0 doesn't grok "retf"
  357. our_recv_1:
  358.     add    si,EADDR_LEN+EADDR_LEN
  359.     lodsw
  360.     mov    cx,ax
  361.     sub    cx,EADDR_LEN+EADDR_LEN+2
  362. our_recv_2:
  363.     lodsb
  364.     cmp    al,cl
  365.     loope    our_recv_2
  366.     jne    our_recv_3        ;if they don't match, don't increment the count.
  367.     inc    receive_count
  368. our_recv_3:
  369.     db    0cbh            ;masm 4.0 doesn't grok "retf"
  370.  
  371. ;two macros to return an error code.
  372.  
  373. rz    macro
  374.     stc
  375.     jne    $+3
  376.     ret
  377.     endm
  378.  
  379. rnz    macro
  380.     stc
  381.     je    $+3
  382.     ret
  383.     endm
  384.  
  385. mode_1_tester:
  386.     call    send_bcast        ;don't receive broadcast,
  387.     rnz
  388.     call    send_to_them        ;don't receive their address,
  389.     rnz
  390.     call    send_random        ;don't receive other addresses,
  391.     rnz
  392.     call    send_multi        ;don't receive multicasts.
  393.     rnz
  394.     clc
  395.     ret
  396. mode_2_tester:
  397.     call    send_bcast        ;don't receive broadcast,
  398.     rnz
  399.     call    send_random        ;don't receive other addresses,
  400.     rnz
  401.     call    send_multi        ;don't receive multicasts.
  402.     rnz
  403.     call    send_to_them        ;do    receive their address,
  404.     rz
  405.     clc
  406.     ret
  407. mode_3_tester:
  408.     call    send_bcast        ;do    receive broadcast,
  409.     rz
  410.     call    send_random        ;don't receive other addresses,
  411.     rnz
  412.     call    send_multi        ;don't receive multicasts.
  413.     rnz
  414.     call    send_to_them        ;do    receive their address,
  415.     rz
  416.     clc
  417.     ret
  418. mode_4_tester:
  419. ;;; set up 01:01:01:01:01:01 in the multicast list.
  420.     call    send_bcast        ;do    receive broadcast,
  421.     rz
  422.     call    send_random        ;don't receive other addresses,
  423.     rnz
  424.     call    send_multi        ;do    receive multicasts.
  425.     rz
  426.     call    send_to_them        ;do    receive their address,
  427.     rz
  428.     clc
  429.     ret
  430. mode_5_tester:
  431. ;;; set up an empty mullticast list.
  432.     call    send_bcast        ;do    receive broadcast,
  433.     rz
  434.     call    send_random        ;don't receive other addresses,
  435.     rnz
  436.     call    send_multi        ;do    receive multicasts.
  437.     rz
  438.     call    send_to_them        ;do    receive their address,
  439.     rz
  440.     clc
  441.     ret
  442. mode_6_tester:
  443.     call    send_bcast        ;do    receive broadcast,
  444.     rz
  445.     call    send_random        ;do    receive other addresses,
  446.     rz
  447.     call    send_multi        ;do    receive multicasts.
  448.     rz
  449.     call    send_to_them        ;do    receive their address,
  450.     rz
  451.     clc
  452.     ret
  453.  
  454. send_bcast:
  455.     mov    dl,'B'
  456.     mov    ah,6
  457.     int    21h
  458.     mov    al,0ffh            ;all-ones is broadcast.
  459.     jmp    short send_fixed_addr
  460. send_random:
  461.     mov    dl,'R'
  462.     mov    ah,6
  463.     int    21h
  464.     mov    al,002h            ;all twos is an okay address.
  465.     jmp    short send_fixed_addr
  466. send_multi:
  467.     mov    dl,'M'
  468.     mov    ah,6
  469.     int    21h
  470.     mov    al,001h            ;first bit set is multicast.
  471. send_fixed_addr:
  472.     push    cs
  473.     pop    es
  474.     mov    di,offset our_buffer
  475.     mov    cx,EADDR_LEN
  476.     rep    stosb
  477.     jmp    short send_to_addr
  478. send_to_them:
  479.     mov    dl,'T'
  480.     mov    ah,6
  481.     int    21h
  482.  
  483.     mov    ah,6            ;get the destination's address.
  484.     mov    bx,handle
  485.     mov    cx,EADDR_LEN
  486.     push    cs            ;es:di -> to address.
  487.     pop    es
  488.     mov    di,offset our_buffer
  489.     int_pkt    1
  490.     jnc    send_to_addr
  491. send_to_addr_bad:
  492.     jmp    bad
  493. send_to_addr:
  494. ;send the packet in our_buffer.
  495. ;return zr if we didn't receive it, and ne if we did.
  496.  
  497. ;we'll know we got a packet if the receive count gets bumped.
  498.     mov    receive_count,0
  499.  
  500.     mov    cx,100
  501.     call    send_packet
  502.     jc    send_to_addr_3
  503.  
  504.     mov    ax,2
  505.     call    set_timeout
  506. send_to_addr_1:
  507.     cmp    receive_count,0        ;did we receive it?
  508.     jne    send_to_addr_2
  509.     call    do_timeout
  510.     jne    send_to_addr_1
  511.     mov    dl,'0'
  512.     mov    ah,6
  513.     int    21h
  514.     xor    al,al
  515.     ret
  516. send_to_addr_2:
  517.     mov    dl,'1'
  518.     mov    ah,6
  519.     int    21h
  520.     or    sp,sp
  521.     ret
  522. send_to_addr_3:
  523.     xor    al,al
  524.     ret
  525.  
  526.  
  527. send_packet:
  528. ;enter with cx = length of packet.
  529. ;stuff the standard contents into our_buffer.
  530. ;return the results of sending the packet.
  531.     push    cx
  532.  
  533.     push    cs            ;es:di -> our buffer.
  534.     pop    es
  535.     mov    di,offset our_buffer+EADDR_LEN+EADDR_LEN
  536.     mov    ax,cx
  537.     stosw
  538.     sub    cx,EADDR_LEN+EADDR_LEN+2
  539. send_packet_1:
  540.     mov    al,cl
  541.     stosb
  542.     loop    send_packet_1
  543.  
  544.     pop    cx
  545.  
  546.     mov    ah,4            ;send_pkt
  547.     mov    si,offset our_buffer    ;ds:si -> buffer.
  548.     int_pkt    2
  549.     ret
  550.  
  551.  
  552.     include    timeout.asm
  553.     include    pkterr.asm
  554.     include    getnum.asm
  555.     include    getdig.asm
  556.     include    skipblk.asm
  557.     include    chrout.asm
  558.     include    digout.asm
  559.  
  560. our_buffer    label    byte
  561.  
  562. code    ends
  563.  
  564.     end    start
  565.