home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / lan / driver6s / pktstat.asm < prev    next >
Assembly Source File  |  1990-03-14  |  5KB  |  257 lines

  1. version    equ    0
  2.  
  3. ;  Russell Nelson, Clarkson University.  September 14, 1989
  4. ;  Copyright, 1989, Russell Nelson
  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 byte 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 statistics version ",'0'+majver,".",'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
  38.     pushf
  39.     cli
  40.     call    their_isr
  41.     endm
  42.  
  43. their_isr    dd    ?
  44. packet_int_no    db    60h,0,0,0
  45. packet_int_end    db    7fh,0,0,0
  46.  
  47. handle        dw    ?
  48.  
  49. bogus_type    db    1,2,3,4,5,6,7,8        ;totally bogus type code.
  50.  
  51. signature    db    'PKT DRVR',0
  52. signature_len    equ    $-signature
  53. usage_msg    db    "usage: pktstat <packet_int_no> [packet_int_no_end]",'$'
  54.  
  55. stat_names    db    "    pkt_in    pkt_out    byt_in    byt_out    err_in    err_out    pk_drop",CR,LF,'$'
  56. printed_names    db    0        ;haven't printed the names yet.
  57.  
  58. statistics_list    label    dword
  59. packets_in    dw    ?,?
  60. packets_out    dw    ?,?
  61. bytes_in    dw    ?,?
  62. bytes_out    dw    ?,?
  63. errors_in    dw    ?,?
  64. errors_out    dw    ?,?
  65. packets_dropped    dw    ?,?        ;dropped due to no type handler.
  66. statistics_count    equ    $ - statistics_list
  67.  
  68. check_packet_no:
  69.     or    word ptr [di+2],0
  70.     jne    usage_error
  71.     cmp    word ptr [di],60h
  72.     jb    usage_error
  73.     cmp    word ptr [di],7fh
  74.     ja    usage_error
  75.     ret
  76.  
  77.  
  78. usage_error:
  79.     mov    dx,offset usage_msg
  80. error:
  81.     mov    ah,9
  82.     int    21h
  83.     int    20h
  84.  
  85. start_1:
  86.     mov    dx,offset copyleft_msg
  87.     mov    ah,9
  88.     int    21h
  89.  
  90.     mov    si,offset phd_dioa+1
  91.  
  92.     mov    di,offset packet_int_no
  93.     call    get_number
  94.     jc    start_2            ;if they entered a number, change the default.
  95.     mov    word ptr packet_int_end+0,cx
  96.     mov    word ptr packet_int_end+2,bx
  97. start_2:
  98.     call    check_packet_no
  99.  
  100.     mov    di,offset packet_int_end
  101.     call    get_number
  102.  
  103.     call    check_packet_no
  104.  
  105.     call    skip_blanks
  106.     cmp    al,CR
  107.     jne    usage_error
  108.  
  109.     mov    al,packet_int_no    ;make sure they're in the right order.
  110.     cmp    al,packet_int_end
  111.     ja    usage_error
  112.  
  113. chk_loop:
  114.     call    chk_int
  115.     mov    al,packet_int_no
  116.     cmp    al,packet_int_end
  117.     jz    done
  118.     inc    packet_int_no        ; increment
  119.     jmp    chk_loop
  120. done:
  121.     mov    al,0
  122.     mov    ah,04ch
  123.     int    21h            ; exit with errorlevel 0
  124.  
  125. chk_int:
  126. ;check packet_int_no for a packet driver.  If there's one there, print
  127. ;the statistics and return nc.  If not, return cy.
  128.     mov    ah,35h            ;get their packet interrupt.
  129.     mov    al,packet_int_no
  130.     int    21h
  131.     mov    their_isr.offs,bx
  132.     mov    their_isr.segm,es
  133.  
  134.     lea    di,3[bx]
  135.     mov    si,offset signature
  136.     mov    cx,signature_len
  137.     repe    cmpsb
  138.     je    have_signature
  139.     stc
  140.     ret
  141. have_signature:
  142.  
  143.     push    ds
  144.     mov    ax,1ffh            ;driver_info
  145.     int_pkt
  146.     pop    ds
  147.     call    fatal_error
  148.  
  149.     mov    ah,2            ;access_type
  150.     mov    al,ch            ;their class from driver_info().
  151.     mov    bx,dx            ;their type from driver_info().
  152.     mov    dl,cl            ;their number from driver_info().
  153.     mov    cx,MAX_P_LEN        ;use the max type length.
  154.     mov    si,offset bogus_type
  155.     push    cs            ;es:di -> our receiver.
  156.     pop    es
  157.     mov    di,offset our_recv
  158.     int_pkt
  159.     call    fatal_error
  160.     mov    handle,ax
  161.  
  162.     mov    ah,24            ;get the statistics
  163.     mov    bx,handle
  164.     int_pkt
  165.     jc    bad
  166.     assume    ds:nothing
  167. ;ds:si now points to the statistics list.
  168.     mov    cx,statistics_count/2
  169.     mov    ax,cs
  170.     mov    es,ax
  171.     mov    di,offset statistics_list
  172.     rep    movsw
  173.     mov    ds,ax            ;restore ds to cs.
  174.  
  175.     cmp    printed_names,0        ;have we printed the names yet?
  176.     jne    did_print_names
  177.  
  178.     inc    printed_names
  179.     mov    dx,offset stat_names
  180.     mov    ah,9
  181.     int    21h
  182. did_print_names:
  183.  
  184.     mov    al,packet_int_no    ;print the packet interrupt number.
  185.     call    byteout
  186.     mov    al,'I'-40h        ;tab over.
  187.     call    chrout
  188.  
  189.     mov    bx,offset statistics_list
  190.     mov    cx,statistics_count/4
  191. print_stats:
  192.     mov    ax,[bx]
  193.     mov    dx,[bx+2]
  194.     push    bx
  195.     push    cx
  196.     call    decout
  197.     pop    cx
  198.     pop    bx
  199.     add    bx,4
  200.     mov    al,'I'-40h        ;tab over.
  201.     call    chrout
  202.     loop    print_stats
  203.  
  204.     mov    dx,offset crlf_msg
  205.     mov    ah,9
  206.     int    21h
  207.  
  208.     mov    ah,3            ;release_type
  209.     mov    bx,handle
  210.     int_pkt
  211.     call    fatal_error
  212.  
  213.     clc
  214.     ret
  215.  
  216.  
  217. bad:
  218.     push    cs
  219.     pop    ds
  220.     call    print_error
  221.  
  222.     mov    ah,3            ;release_type
  223.     mov    bx,handle
  224.     int_pkt
  225.     call    fatal_error
  226.  
  227.     int    20h
  228.  
  229.  
  230. our_recv:
  231.     or    ax,ax            ;first or second call?
  232.     jne    our_recv_1        ;second -- we ignore the packet
  233.     push    cs
  234.     pop    es
  235.     mov    di,offset our_buffer
  236. our_recv_1:
  237.     db    0cbh            ;masm 4.0 doesn't grok "retf"
  238.  
  239.  
  240.     include    printea.asm
  241.  
  242.     assume    ds:code
  243.  
  244.     include    pkterr.asm
  245.     include    getnum.asm
  246.     include    skipblk.asm
  247.     include    getdig.asm
  248.     include    decout.asm
  249.     include    digout.asm
  250.     include    chrout.asm
  251.  
  252. our_buffer    label    byte
  253.  
  254. code    ends
  255.  
  256.     end    start
  257.