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

  1. version    equ    0
  2.  
  3. ;History:87,1
  4. ;Sun Aug 09 23:13:00 1992 Hans-Juergen Knoblock fixed a bug wherein the wrong traffic counters were being incremented.
  5.  
  6. ;  Copyright 1990-1992, Russell Nelson, Crynwr Software
  7.  
  8. ;   This program is free software; you can redistribute it and/or modify
  9. ;   it under the terms of the GNU General Public License as published by
  10. ;   the Free Software Foundation, version 1.
  11. ;
  12. ;   This program is distributed in the hope that it will be useful,
  13. ;   but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ;   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. ;   GNU General Public License for more details.
  16. ;
  17. ;   You should have received a copy of the GNU General Public License
  18. ;   along with this program; if not, write to the Free Software
  19. ;   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20.  
  21.     include    defs.asm
  22.  
  23. BS    equ    8
  24.  
  25. code    segment word public
  26.     assume    cs:code, ds:code
  27.  
  28.     org    80h
  29. phd_dioa    label    byte
  30.  
  31.     org    100h
  32. start:
  33.     jmp    start_1
  34.  
  35. copyleft_msg    label    byte
  36.  db "Packet traffic version ",'0'+(majver / 10),'0'+(majver mod 10),".",'0'+version," copyright 1990, Russell Nelson.",CR,LF
  37.  db "This program is free software; see the file COPYING for details.",CR,LF
  38.  db "NO WARRANTY; see the file COPYING for details.",CR,LF
  39. crlf_msg    db    CR,LF,'$'
  40.  
  41. their_isr    dd    ?
  42. entry_point    db    ?,?,?,?
  43. handle        dw    ?
  44.  
  45. signature    db    'PKT DRVR',0
  46. signature_len    equ    $-signature
  47. no_signature_msg    db    "No packet driver at that address",'$'
  48. usage_msg    db    "usage: pkttraf <packet_int_no>",'$'
  49. waiting_msg    label    byte
  50. db "Graphically display network traffic.  The Ethernet address of the",CR,LF
  51. db "highlighted node is shown in the lower right corner.  The space key will",CR,LF
  52. db "advance counter-clockwise, backspace will retreat clockwise, escape will",CR,LF
  53. db "exit.",CR,LF
  54. db CR,LF
  55. db "Press any key to continue.",CR,LF,'$'
  56.  
  57.     include    pixel.asm
  58.     include    line.asm
  59.  
  60. MAX_NODES    equ    20
  61.  
  62. xy_pairs    label    word
  63.     dw    100,198
  64.     dw    130,193
  65.     dw    157,179
  66.     dw    179,157
  67.     dw    193,130
  68.     dw    198,100
  69.     dw    193,69
  70.     dw    179,42
  71.     dw    157,20
  72.     dw    130,6
  73.     dw    100,2
  74.     dw    69,6
  75.     dw    42,20
  76.     dw    20,42
  77.     dw    6,69
  78.     dw    2,99
  79.     dw    6,130
  80.     dw    20,157
  81.     dw    42,179
  82.     dw    69,193
  83.  
  84. eaddr_list    db    EADDR_LEN * MAX_NODES dup(0)
  85. eaddr_end    dw    eaddr_list
  86.  
  87. traffic_list    db    MAX_NODES * MAX_NODES dup(0)
  88. traffic_scale    db    0
  89.  
  90. cursor    db    0            ;between 0 and MAX_NODES-1
  91.  
  92. usage_error:
  93.     mov    dx,offset usage_msg
  94. error:
  95.     mov    ah,9
  96.     int    21h
  97.     int    20h
  98.  
  99. start_1:
  100.     mov    dx,offset copyleft_msg
  101.     mov    ah,9
  102.     int    21h
  103.  
  104.     mov    si,offset phd_dioa+1
  105.     cmp    byte ptr [si],CR    ;end of line?
  106.     je    usage_error
  107.  
  108.     mov    di,offset entry_point
  109.     call    get_number
  110.  
  111.     mov    ah,35h            ;get their packet interrupt.
  112.     mov    al,entry_point
  113.     int    21h
  114.     mov    their_isr.offs,bx
  115.     mov    their_isr.segm,es
  116.  
  117.     lea    di,3[bx]
  118.     mov    si,offset signature
  119.     mov    cx,signature_len
  120.     repe    cmpsb
  121.     mov    dx,offset no_signature_msg
  122.     jne    error
  123.  
  124.     mov    ax,1ffh            ;driver_info
  125.     call    int_pkt
  126.     call    fatal_error
  127.  
  128.     mov    ah,2            ;access all packets.
  129.     mov    al,ch            ;their class from driver_info().
  130.     mov    bx,dx            ;their type from driver_info().
  131.     mov    dl,cl            ;their number from driver_info().
  132.     mov    cx,0            ;type length of zero.
  133.     movseg    es,cs
  134.     mov    di,offset our_recv
  135.     call    int_pkt
  136.     call    fatal_error
  137.     mov    handle,ax
  138.  
  139.     mov    ah,20            ;set receive mode.
  140.     mov    bx,handle
  141.     mov    cx,6            ;receive all packets.
  142.     call    int_pkt
  143.     call    fatal_error
  144.  
  145.     mov    dx,offset waiting_msg
  146.     mov    ah,9
  147.     int    21h
  148.  
  149.     mov    ah,0            ;fetch the key.
  150.     int    16h
  151.  
  152.     call    init_vid
  153.  
  154. wait_for_key:
  155.     call    draw_eaddr
  156.  
  157.     cmp    traffic_scale,0        ;do we need to rescale?
  158.     je    no_rescale
  159.     mov    si,offset traffic_list
  160.     mov    cx,MAX_NODES*MAX_NODES
  161. rescale:
  162.     shr    byte ptr [si],1        ;divide all the traffic in half.
  163.     inc    si
  164.     loop    rescale
  165.     mov    traffic_scale,0
  166. no_rescale:
  167.  
  168.     xor    bx,bx
  169.     mov    al,4
  170.     mul    cursor
  171. write_dots:
  172.     mov    cx,xy_pairs[bx].offs    ;get the X and Y coordinate.
  173.     mov    dx,xy_pairs[bx].segm
  174.     push    ax
  175.     push    bx
  176.     cmp    ax,bx            ;at the cursor?
  177.     mov    al,60h            ;use a dim dot.
  178.     jne    write_dots_1
  179.     mov    al,0ffh            ;use a bright dot.
  180. write_dots_1:
  181.     call    draw_dot
  182.     pop    bx
  183.     pop    ax
  184.     add    bx,4
  185.     cmp    bx,MAX_NODES*4
  186.     jb    write_dots
  187.  
  188.   if 0
  189. ;draw the cursor.
  190.     mov    cx,xy_pairs[bx].offs    ;get the X and Y coordinate.
  191.     mov    dx,xy_pairs[bx].segm
  192.     call    draw_bullet
  193.   endif
  194.  
  195.     mov    si,offset traffic_list
  196.     mov    dh,0
  197. write_nodes:
  198.     mov    dl,dh
  199.     inc    dl
  200. write_nodes_1:
  201.   if 0
  202.     mov    al,MAX_NODES
  203.     mul    dh
  204.     add    al,dl
  205.     adc    ah,0
  206.   endif
  207.  
  208.     lodsb                ;get the amount of traffic.
  209.     push    si
  210.     call    write_one_node        ;enter with dh, dl = a pair of nodes,, al = amount of traffic.
  211.     pop    si
  212.     inc    dl
  213.     cmp    dl,MAX_NODES
  214.     jb    write_nodes_1
  215.  
  216.     mov    ah,1            ;check for any key.
  217.     int    16h
  218.     jne    test_for_key        ;got a key - go get it.
  219.  
  220.     inc    dh
  221.     cmp    dh,MAX_NODES - 1
  222.     jb    write_nodes
  223.  
  224. test_for_key:
  225.     mov    ah,1            ;check for any key.
  226.     int    16h
  227.     je    wait_for_key        ;no key -- keep waiting.
  228.  
  229.     mov    ah,0            ;fetch the key.
  230.     int    16h
  231.  
  232.     cmp    al,1bh            ;Escape?
  233.     je    all_done
  234.     cmp    al,'q'            ;Quit?
  235.     je    all_done
  236.     cmp    al,BS
  237.     je    backspace
  238.     cmp    al,' '
  239.     jne    test_for_key
  240.  
  241.     inc    cursor            ;move over by one.
  242.     cmp    cursor,MAX_NODES    ;should we wrap around?
  243.     jb    test_for_key
  244.     mov    cursor,0
  245.     jmp    test_for_key
  246.  
  247. backspace:
  248.     dec    cursor            ;move over by one.
  249.     cmp    cursor,-1        ;should we wrap around?
  250.     jne    test_for_key
  251.     mov    cursor,MAX_NODES-1
  252.     jmp    test_for_key
  253.  
  254.  
  255. all_done:
  256.  
  257.     call    uninit_vid
  258.  
  259.     mov    ah,20            ;set receive mode.
  260.     mov    bx,handle
  261.     mov    cx,3            ;receive ours + broadcasts.
  262.     call    int_pkt
  263.     call    fatal_error
  264.  
  265.     mov    ah,3
  266.     mov    bx,handle
  267.     call    int_pkt
  268.     call    fatal_error
  269.  
  270.     int    20h
  271.  
  272.  
  273. int_pkt:
  274.     push    ds
  275.     push    es
  276.     pushf
  277.     cli
  278.     call    their_isr
  279.     pop    es
  280.     pop    ds
  281.     ret
  282.  
  283.  
  284. write_one_node:
  285. ;enter with dh, dl = a pair of nodes, al = amount of traffic.
  286. ;preserve dx.
  287.     push    dx
  288.  
  289.     mov    bl,dh
  290.     xor    bh,bh
  291.     shl    bx,1
  292.     shl    bx,1
  293.     mov    si,xy_pairs[bx].offs    ;get the X and Y coordinate.
  294.     mov    di,xy_pairs[bx].segm
  295.  
  296.     mov    bl,dl
  297.     xor    bh,bh
  298.     shl    bx,1
  299.     shl    bx,1
  300.     mov    cx,xy_pairs[bx].offs    ;get the X and Y coordinate.
  301.     mov    dx,xy_pairs[bx].segm
  302.  
  303.     call    line
  304.     pop    dx
  305.     ret
  306.  
  307.  
  308. dot_color    db    ?
  309.  
  310. draw_dot:
  311. ;enter with cx, dx = point to draw a dot around, al = color of dot.
  312. ;  ***
  313. ; *   *
  314. ; * X *
  315. ; *   *
  316. ;  ***
  317.     mov    dot_color,al
  318.     call    open_vid
  319.     call    move_left
  320.     call    move_left
  321.     call    move_up
  322.     mov    al,dot_color
  323.     call    set_bit
  324.     call    move_down
  325.     mov    al,dot_color
  326.     call    set_bit
  327.     call    move_down
  328.     mov    al,dot_color
  329.     call    set_bit
  330.     call    move_right
  331.     call    move_down
  332.     mov    al,dot_color
  333.     call    set_bit
  334.     call    move_right
  335.     mov    al,dot_color
  336.     call    set_bit
  337.     call    move_right
  338.     mov    al,dot_color
  339.     call    set_bit
  340.     call    move_right
  341.     call    move_right
  342.     call    move_up
  343.     mov    al,dot_color
  344.     call    set_bit
  345.     call    move_up
  346.     mov    al,dot_color
  347.     call    set_bit
  348.     call    move_up
  349.     mov    al,dot_color
  350.     call    set_bit
  351.     call    move_up
  352.     call    move_left
  353.     mov    al,dot_color
  354.     call    set_bit
  355.     call    move_left
  356.     mov    al,dot_color
  357.     call    set_bit
  358.     call    move_left
  359.     mov    al,dot_color
  360.     call    set_bit
  361.     call    close_vid
  362.     ret
  363.  
  364.  
  365. draw_bullet:
  366. ;enter with cx, dx = point to draw a dot around.
  367. ; HGF
  368. ; A E
  369. ; BCD
  370.     call    open_vid
  371.     call    move_left
  372.     mov    al,0ffh            ;A
  373.     call    set_bit
  374.     call    move_down
  375.     mov    al,0ffh            ;B
  376.     call    set_bit
  377.     call    move_right
  378.     mov    al,0ffh            ;C
  379.     call    set_bit
  380.     call    move_right
  381.     mov    al,0ffh            ;D
  382.     call    set_bit
  383.     call    move_up
  384.     mov    al,0ffh            ;E
  385.     call    set_bit
  386.     call    move_up
  387.     mov    al,0ffh            ;F
  388.     call    set_bit
  389.     call    move_left
  390.     mov    al,0ffh            ;G
  391.     call    set_bit
  392.     call    move_left
  393.     mov    al,0ffh            ;H
  394.     call    set_bit
  395.     call    close_vid
  396.     ret
  397.  
  398. draw_eaddr:
  399.     mov    ah,2            ;set cursor position
  400.     mov    bh,0
  401.     mov    dh,24
  402.     mov    dl,40-EADDR_LEN*3
  403.     int    10h
  404.  
  405.     mov    al,cursor
  406.     mov    ah,EADDR_LEN
  407.     mul    ah
  408.     add    ax,offset eaddr_list
  409.     mov    si,ax
  410.     call    print_ether_addr
  411.     ret
  412.  
  413.  
  414. our_recv:
  415.     or    ax,ax            ;first or second call?
  416.     jne    our_recv_1        ;second -- bump the packet flag.
  417.     movseg    es,cs
  418.     mov    di,offset our_buffer
  419.     retf
  420. our_recv_1:
  421.     push    ax
  422.     push    bx
  423.     push    cx
  424.     push    dx
  425.     push    si
  426.     push    di
  427.     push    bp
  428.     push    ds
  429.     push    es
  430.  
  431.     cld
  432.  
  433.     mov    ax,cs
  434.     mov    ds,ax
  435.     mov    es,ax
  436.  
  437.     call    receive
  438.  
  439.     pop    es
  440.     pop    ds
  441.     pop    bp
  442.     pop    di
  443.     pop    si
  444.     pop    dx
  445.     pop    cx
  446.     pop    bx
  447.     pop    ax
  448.     retf
  449.  
  450. receive:
  451.     mov    si,offset our_buffer    ;get the "to" address.
  452.     call    find_address
  453.     jc    receive_2        ;too many!
  454.     push    ax
  455.     mov    si,offset our_buffer+EADDR_LEN    ;get the "from" address.
  456.     call    find_address
  457.     pop    bx
  458.     jc    receive_2        ;too many!
  459.     mov    bh,MAX_NODES
  460.     mul    bh
  461.     xor    bh,bh
  462.     add    bx,ax
  463.     cmp    bx,MAX_NODES * MAX_NODES
  464.     jae    receive_2
  465.     cmp    traffic_list[bx],255    ;at the maximum already?
  466.     je    receive_1
  467.     inc    traffic_list[bx]    ;increase the amount of traffic.
  468. receive_2:
  469.     ret
  470. receive_1:
  471.     inc    traffic_scale
  472.     ret
  473.  
  474.  
  475. find_address:
  476. ;enter with si -> incoming Ethernet address.
  477. ;exit with nc, al = node number, or cy if we can't remember this one.
  478.     mov    cx,MAX_NODES
  479.     mov    di,offset eaddr_list
  480. find_address_1:
  481.     cmp    di,eaddr_end        ;did we hit the end?
  482.     jae    find_address_5
  483.     cmpsw
  484.     jne    find_address_2
  485.     cmpsw
  486.     jne    find_address_3
  487.     cmpsw
  488.     jne    find_address_4
  489.     jmp    short find_address_6
  490. find_address_2:
  491.     add    si,2            ;increment by another two bytes.
  492.     add    di,2
  493. find_address_3:
  494.     add    si,2            ;increment by another two bytes.
  495.     add    di,2
  496. find_address_4:
  497.     add    si,-6            ;back si up to the beginning.
  498.     loop    find_address_1        ;or run out of slots?
  499.     stc
  500.     ret
  501. find_address_5:
  502.     movsw                ;okay, remember it here.
  503.     movsw
  504.     movsw
  505.     mov    eaddr_end,di
  506. find_address_6:
  507.     mov    al,MAX_NODES
  508.     sub    al,cl
  509.     clc
  510.     ret
  511.  
  512.  
  513.     include    printea.asm
  514.     include    pkterr.asm
  515.     include    getnum.asm
  516.     include    getdig.asm
  517.     include    skipblk.asm
  518.     include    digout.asm
  519.  
  520. chrout:
  521.     push    ax            ;print the char in al.
  522.     push    bx
  523.     push    bp
  524.     mov    ah,0eh
  525.     mov    bh,0
  526.     mov    bl,0ffh
  527.     int    10h
  528.     pop    bp
  529.     pop    bx
  530.     pop    ax
  531.     ret
  532.  
  533.  
  534.     align    4
  535. our_buffer    label    byte
  536.  
  537. code    ends
  538.  
  539.     end    start
  540.