home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / lan / driver6s / nb.asm < prev    next >
Assembly Source File  |  1990-03-15  |  12KB  |  476 lines

  1. version equ     3
  2.  
  3.         include defs.asm        ;SEE ENCLOSED COPYRIGHT MESSAGE
  4. NCB_NOWAIT         equ 80h         ;  Command wait flag
  5.  
  6. NCB_RESET          equ 32h         ;  Reset adapter
  7. NCB_CANCEL         equ 35h         ;  Cancel command
  8. NCB_STATUS         equ 33h         ;  Get NETBIOS intf status
  9. NCB_UNLINK         equ 70h         ;  Unlink   (RPL)
  10. NCB_ADDNAME        equ 30h         ;  Add name
  11. NCB_ADDGNAME       equ 36h         ;  Add group name
  12. NCB_DELNAME        equ 31h         ;  Delete name
  13. NCB_FINDNAME       equ 78h         ;  Find name
  14. NCB_CALL           equ 10h         ;  Call
  15. NCB_LISTEN         equ 11h         ;  Listen
  16. NCB_HANGUP         equ 12h         ;  Hang up
  17. NCB_SEND           equ 14h         ;  Send
  18. NCB_CHSEND         equ 17h         ;  Chain send
  19. NCB_RECEIVE        equ 15h         ;  Receive
  20. NCB_RECANY         equ 16h         ;  Receive any
  21. NCB_SESSTATUS      equ 34h         ;  Get session status
  22. NCB_SDATAGRAM      equ 20h         ;  Send datagram
  23. NCB_SBROADCAST     equ 22h         ;  Send broadcast
  24. NCB_RDATAGRAM      equ 21h         ;  Receive datagram
  25. NCB_RBROADCAST     equ 23h         ;  Receive broadcast
  26. NCB_TRACE          equ 79h         ;  Start trace
  27.  
  28. ncb             struc
  29. ncb_command     db ?
  30. ncb_retcode     db ?
  31. ncb_lsn         db ?
  32. ncb_num         db ?
  33. ncb_buffer      dd ?
  34. ncb_length      dw ?
  35. ncb_callname    db 16 dup(?)
  36. ncb_name        db 16 dup(?)
  37. ncb_rto         db ?
  38. ncb_sto         db ?
  39. ncb_post        dd ?
  40. ncb_lana_num    db ?
  41. ncb_cmd_cplt    db ?
  42. ncb_reserve     db 14 dup(?)
  43. ncb             ends
  44.  
  45. code    segment byte public
  46.         assume  cs:code, ds:code
  47. ;***************************************************************
  48. prefix          db "TCPIP"
  49.  
  50.         public  int_no
  51. int_no  db      0,0,0,0
  52. ip_adress       dw      2 dup(0)
  53. rq_size         dw      3
  54. padding         dd      0
  55.  
  56.     public    driver_class, driver_type, driver_name, driver_function, parameter_list
  57. driver_class    db      6               ;from the packet spec
  58. driver_type     db      0               ;from the packet spec
  59. driver_name     db      'netbios',0     ;name of the driver.
  60. driver_function    db    2
  61. parameter_list    label    byte
  62.     db    1    ;major rev of packet driver
  63.     db    9    ;minor rev of packet driver
  64.     db    14    ;length of parameter list
  65.     db    EADDR_LEN    ;length of MAC-layer address
  66.     dw    512    ;MTU, including MAC headers
  67.     dw    MAX_MULTICAST * EADDR_LEN    ;buffer size of multicast addrs
  68.     dw    0    ;(# of back-to-back MTU rcvs) - 1
  69.     dw    0    ;(# of successive xmits) - 1
  70.     dw    0    ;Interrupt # to hook for post-EOI
  71.             ;processing, 0 == none,
  72.  
  73.     public    rcv_modes
  74. rcv_modes    dw    4        ;number of receive modes in our table.
  75.         dw    0,0,0,rcv_mode_3
  76.  
  77. lana_num        db 0
  78. local_ncb_num   db 0  ; handle returned by add_name
  79.  
  80.  
  81.         public  nbsend, nbrcv1, nbrcv2, rcv_buffer1, rcv_buffer2 ; MAP
  82. nbsend          ncb <>
  83. nbrcv1          ncb <>
  84. nbrcv2          ncb <>
  85.  
  86.  
  87. MAX_DG          equ 512
  88. rcv_buffer1     db MAX_DG dup(?)
  89. rcv_buffer2     db MAX_DG dup(?)
  90.  
  91.         public  send_pkt
  92. send_pkt:
  93.         assume ds: nothing
  94. ;enter with ds:si -> packet, cx = packet length.
  95. ;exit with nc if ok, or else cy if error, dh set to error number.
  96.         push    es
  97.         push    bx
  98.         push    ds
  99.  
  100.         push    cs
  101.         pop     es
  102.         mov     bx,offset cs:nbsend
  103.  
  104.         mov     cs:[bx].ncb_buffer.offs,si
  105.         mov     ax,ds
  106.         mov     cs:[bx].ncb_buffer.segm,ds
  107.         mov     cs:[bx].ncb_length,cx
  108.  
  109.         push    bx
  110.         lea     di,cs:nbsend.ncb_callname
  111.         mov     dh,ds:[si+16]
  112.         mov     dl,ds:[si+17]
  113.         mov     bh,ds:[si+18]
  114.         mov     bl,ds:[si+19]
  115.         push    cs
  116.         pop     ds
  117.         call    ip_to_nbname
  118.         pop     bx
  119.  
  120.         int     5ch
  121.  
  122.         cmp     al,0
  123.         jz      send_ok
  124.         add     ax,32
  125.         call    tty
  126.         mov     al,'S'
  127.         call    tty
  128.         stc
  129.         jmp     send_done
  130. send_ok:
  131.         mov     al,'s'
  132.         call    tty
  133.         clc
  134. send_done:
  135.         pop     ds
  136.         pop     bx
  137.         pop     es
  138.         ret
  139.  
  140.  
  141.  
  142.         public  get_address
  143. get_address:
  144. ;get the address of the interface.
  145. ;enter with es:di -> place to get the address, cx = size of address buffer.
  146. ;exit with nc, cx = actual size of address, or cy if buffer not big enough.
  147.         clc
  148.         ret
  149.  
  150.  
  151.     public    set_address
  152. set_address:
  153. ;enter with ds:si -> Ethernet address, CX = length of address.
  154. ;exit with nc if okay, or cy, dh=error if any errors.
  155.     assume    ds:nothing
  156.     ret
  157.  
  158.  
  159. rcv_mode_3:
  160. ;receive mode 3 is the only one we support, so we don't have to do anything.
  161.     ret
  162.  
  163.  
  164.     public    set_multicast_list
  165. set_multicast_list:
  166. ;enter with ds:si ->list of multicast addresses, cx = number of addresses.
  167. ;return nc if we set all of them, or cy,dh=error if we didn't.
  168.     mov    dh,NO_MULTICAST
  169.     stc
  170.     ret
  171.  
  172.  
  173.     public    terminate
  174. terminate:
  175.     ret
  176.  
  177.         public  reset_interface
  178. reset_interface:
  179. ;reset the interface.
  180.         ret
  181.  
  182.  
  183. ;called when we want to determine what to do with a received packet.
  184. ;enter with cx = packet length, es:di -> packet type.
  185.         extrn   recv_find: near
  186.  
  187. ;called after we have copied the packet into the buffer.
  188. ;enter with ds:si ->the packet, cx = length of the packet.
  189.         extrn   recv_copy: near
  190.  
  191.         extrn   count_in_err: near
  192.         extrn   count_out_err: near
  193.         extrn   dwordout: near
  194.         extrn   error: near
  195.  
  196.         public  recv
  197. recv:
  198. ;called from the recv isr.  All registers have been saved, and ds=cs.
  199. ;Upon exit, the interrupt will be acknowledged.
  200.         assume  ds:code
  201.         ret
  202.  
  203.         public nbint  ; MAP
  204. nbint   proc far
  205.         push ds
  206.         push cs
  207.         pop  ds
  208.         mov     al,'r'
  209.         call    tty
  210.         mov  al,[bx].ncb_retcode
  211.         cmp  al,0               ; ok
  212.         jnz  bad_nbint
  213.         push bx
  214.         mov  cx,[bx].ncb_length
  215.         mov  di,0
  216.         call recv_find
  217.         pop  bx
  218.         mov  ax,es
  219.         or   ax,di
  220.         je   nbint_done
  221.  
  222. ;                   cx, di already set
  223.         mov     si,[bx].ncb_buffer.offs
  224.         rep     movsb
  225.         call    recv_copy
  226.  
  227.         mov     [bx].ncb_length,MAX_DG  ; reestablish dg-length
  228.  
  229.         push    ds
  230.         pop     es
  231.         int 5ch
  232.         cmp     al,0ffh
  233.         jz      nbint_pending_ok1
  234.         mov     al,'?'
  235.         call    tty
  236.         cmp     al,00h
  237.         jz      nbint_pending_ok1
  238.         add     ax,32
  239.         call    tty
  240.         mov     al,'.'
  241.         call    tty
  242.  
  243. nbint_pending_ok1:
  244.         jmp     short nbint_done
  245.  
  246. bad_nbint:
  247.         cmp     ax,17h          ; name deleted
  248.         add     ax,32
  249.         call    tty
  250.         mov     al,'R'
  251.         call    tty
  252.  
  253. nbint_done:
  254.         pop ds
  255.         iret
  256. nbint   endp
  257.  
  258.         public  nb_stop
  259. nb_stop:
  260.         ;                   unregister name
  261.         push    cs
  262.         pop     es
  263.         lea      bx,nbrcv1
  264.         mov     [bx].ncb_command,NCB_DELNAME
  265. ;        mov     al,lana_num
  266. ;        mov     [bx].ncb_lana_num,al
  267.         int     5ch
  268.         cmp     al,0
  269.         jz      good_delete
  270.         add     ax,32
  271.         call    tty
  272.         mov     al,'I'
  273.         call    tty
  274. good_delete:
  275.         ret
  276.  
  277.  
  278.  
  279. tty:
  280.         push    bx
  281.         mov     ah,14
  282.         int     10h
  283.         pop     bx
  284.         ret
  285.  
  286. ip_to_nbname:
  287.         ;      call with es:di = *ncb_name
  288.         ;            bx and dx = ip_address
  289.  
  290.         mov     cx,5
  291.         mov     si,offset prefix
  292.         rep     movsb
  293.  
  294.         mov     [di],bx
  295.         mov     [di+2],dx
  296.         ret
  297.  
  298.     public    recv_exiting
  299. recv_exiting:
  300. ;called from the recv isr after interrupts have been acknowledged.
  301. ;Only ds and ax have been saved.
  302.     assume    ds:nothing
  303.     ret
  304.  
  305.  
  306. ;any code after this will not be kept after initialization.
  307.         public end_resident ; MAP
  308. end_resident    label   byte
  309.  
  310.  
  311.         public  usage_msg
  312. usage_msg       db      "usage: nb <packet_int_no> <ip.ad.dr.ess> [receive queue size]",CR,LF,'$'
  313.  
  314.         public  copyright_msg
  315. copyright_msg   db      "Packet driver for a netbios device, version ",'0'+version,CR,LF,'$'
  316.                 db      "Portions Copyright 1990, Michael Haberler",CR,LF,'$'
  317.  
  318. ip_adress_name  db      "IP Adress ",'$'
  319. rq_size_name    db      "Receive Queue ",'$'
  320. bad_name_msg    db      " bad returncode from nb add_name",CR,LF,'$'
  321. bad_rcv_msg     db      " bad returncode from nb receive dg",CR,LF,'$'
  322. good_name_msg   db      " good returncode from nb add_name",CR,LF,'$'
  323. good_rcv_msg    db      " good returncode from nb receive dg",CR,LF,'$'
  324. temp_dw         dw      ?
  325.         extrn   set_recv_isr: near
  326.  
  327. ;enter with si -> argument string, di -> word to store.
  328. ;if there is no number, don't change the number.
  329.         extrn   get_number: near
  330.  
  331.         public  parse_args
  332. parse_args:
  333.         mov     di, offset temp_dw
  334.         mov     bx, offset ip_adress_name
  335.         call    get_number
  336.         mov     ax,temp_dw
  337.         mov     byte ptr ip_adress+3,al
  338.         inc     si
  339.         mov     di, offset temp_dw
  340.         mov     bx, offset ip_adress_name
  341.         call    get_number
  342.         mov     ax,temp_dw
  343.         mov     byte ptr ip_adress+2,al
  344.         inc     si
  345.         mov     di, offset temp_dw
  346.         mov     bx, offset ip_adress_name
  347.         call    get_number
  348.         mov     ax,temp_dw
  349.         mov     byte ptr ip_adress+1,al
  350.         inc     si
  351.         mov     di, offset temp_dw
  352.         mov     bx, offset ip_adress_name
  353.         call    get_number
  354.         mov     ax,temp_dw
  355.         mov     byte ptr ip_adress+0,al
  356.  
  357.         mov     di, offset rq_size
  358.         mov     bx, offset rq_size_name
  359.         call    get_number
  360.         ret
  361.  
  362.  
  363.  
  364.         public  etopen
  365. etopen:
  366.         pushf
  367.         cld
  368.  
  369. ;if all is okay,
  370. ;        mov     bx,offset nbsend
  371.         lea     bx,nbsend
  372.         mov     [bx].ncb_command,NCB_ADDNAME
  373.         mov     al,lana_num
  374.         mov     [bx].ncb_lana_num,al
  375.  
  376.         push    ds
  377.         push    cs
  378.         push    cs
  379.         pop     ds
  380.         pop     es
  381.  
  382.         push    bx
  383.         lea     di,nbsend.ncb_name
  384.         mov     bx,ip_adress
  385.         mov     dx,ip_adress+2
  386.         call    ip_to_nbname
  387.         pop     bx
  388.  
  389.         mov     cx,16
  390.         mov     di,offset nbrcv1.ncb_name
  391.         mov     si,offset nbsend.ncb_name
  392.         rep     movsb
  393.         mov     cx,16
  394.         mov     di,offset nbrcv2.ncb_name
  395.         mov     si,offset nbsend.ncb_name
  396.         rep     movsb
  397.  
  398.         int     5ch     ; add_name, -> returns rc in al
  399.         cmp     al,0
  400.         jz      good_name
  401.         mov     dx,0
  402.         mov     ah,0
  403.         call    dwordout
  404.         mov     dx,offset bad_name_msg
  405.         pop     ds
  406.         jmp     error
  407.  
  408. good_name:
  409. ;        mov     dx,offset good_name_msg
  410. ;        call    say
  411.  
  412.         mov     al,[bx].ncb_num
  413.         mov     local_ncb_num,al
  414.         mov     [bx].ncb_command,NCB_SDATAGRAM  ;set send command code
  415.  
  416.         ;       start receive operations
  417. ;        mov     bx,offset nbrcv1
  418.         lea     bx,nbrcv1
  419.         mov     al,NCB_RDATAGRAM+NCB_NOWAIT  ;set rcv command
  420.         mov     [bx].ncb_command,al
  421.  
  422.         mov     al,local_ncb_num
  423.         mov     [bx].ncb_num,al
  424.  
  425.         mov     ax,MAX_DG
  426.         mov     [bx].ncb_length,ax
  427.  
  428.         mov     ax,ds
  429.         mov     [bx].ncb_buffer.segm,ax
  430.         mov     [bx].ncb_buffer.offs,offset rcv_buffer1
  431.  
  432.         mov     [bx].ncb_post.segm,ax
  433.         mov     [bx].ncb_post.offs,offset nbint
  434.  
  435.         mov     al,lana_num
  436.         mov     [bx].ncb_lana_num,al
  437.         int     5ch
  438.  
  439.         cmp     al,0ffh
  440.         jz      pending_ok1
  441.         cmp     al,00h
  442.         jnz     bad_init
  443.  
  444. pending_ok1:
  445.         mov     dx,offset good_rcv_msg
  446.         call    say
  447.  
  448.         mov     dx,offset end_resident
  449.         pop     ds
  450.         popf
  451.         clc
  452.         ret
  453. ;if we got an error,
  454. bad_init:
  455.         mov     ah,0
  456.         mov     dx,0
  457.         call    dwordout
  458.         mov     dx,offset bad_rcv_msg
  459.         call    say
  460.         call    nb_stop
  461.         pop     ds
  462.         popf
  463.         stc
  464.         ret
  465.  
  466. say:
  467.         mov     ah,9
  468.         int     21h
  469.         ret
  470.  
  471.  
  472. code    ends
  473.  
  474.         end
  475.  
  476.