home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / progjour / 1991 / 04 / net_misc.asm < prev    next >
Assembly Source File  |  1991-05-17  |  7KB  |  357 lines

  1.     title    NetBIOS Miscellaneous
  2.     include    asm.inc
  3.     include    netbios.inc
  4.  
  5.  
  6.     public    clear_ncb
  7.     public    netbios_add_name
  8.     public    netbios_call
  9.     public    netbios_cancel
  10.     public    netbios_check
  11.     public    netbios_delete_name
  12.     public    netbios_hang_up
  13.     public    netbios_receive_wait
  14.     public    netbios_send_broadcast
  15.     public    netbios_send_datagram
  16.     public    netbios_send_wait
  17.     public    put_netbios_name
  18.  
  19.  
  20.     .data?
  21.  
  22. temp_ncb    ncb    <>    ; netbios control block for temporary use
  23.  
  24.     .code
  25.     extn    putchar,strncpy,save_most
  26.  
  27.  
  28. ;;    clear ncb
  29. ;
  30. ;    entry    DS:SI    ncb ptr
  31. ;
  32. clear_ncb proc
  33.     pushm    ax,cx,di,es
  34.     mov    ax,ds
  35.     mov    es,ax
  36.     mov    di,si
  37.     xor    ax,ax
  38.     mov    cx,size ncb
  39.     rep    stosb
  40.     popm    es,di,cx,ax
  41.     ret
  42. clear_ncb endp
  43.  
  44.  
  45. ;;    netbios add name
  46. ;
  47. ;    entry    DS:SI    asciiz name (less than 16 characters long)
  48. ;    exit    Cf    if error
  49. ;        AL    name number (or return code if error)
  50. ;
  51. netbios_add_name proc
  52.     call    save_most
  53.     call    zero_temp_ncb        ; copy name to control block
  54.     call    write_temp_ncb
  55.     lea    di,Ncb_Name[di]
  56.     mov    cx,size Ncb_Name+1    ;  (+1 is for \0, OK to overflow \0
  57.     call    strncpy            ;   into next field)
  58.  
  59.     call    read_temp_ncb
  60.     mov    Ncb_Command[si],NB_ADD_NAME_WAIT
  61.     call    netbios_call
  62.     jc    nan1            ;  if error
  63.  
  64.     mov    al,Ncb_Num[si]
  65. nan1:    ret
  66. netbios_add_name endp
  67.  
  68.  
  69. ;;    netbios call
  70. ;
  71. ;    entry    DS:SI    netbios control block
  72. ;    exit    AX    return code (0xFF if function pending)
  73. ;        Cf    if error
  74. ;
  75. netbios_call proc
  76.     push    es
  77.     mov    ax,ds            ; call NetBIOS
  78.     mov    es,ax            ;  ES:BX points to control block
  79.     xchg    bx,si
  80.     int    5Ch
  81.     xchg    bx,si
  82.  
  83.     mov    al,Ncb_Cmd_Cplt[si]    ; get return code
  84.     and    ax,0FFh            ;  (AH=0)
  85.     jz    ncb1            ;  if successful completion (Cf==0)
  86.  
  87.     cmp    al,0FFh            ; set Cf if error (AL!=0xFF)
  88.  
  89. ncb1:    pop    es
  90.     ret
  91. netbios_call endp
  92.  
  93.  
  94. ;;    netbios cancel
  95. ;
  96. ;    entry    DS:SI    netbios command block
  97. ;    exit    AX    final return code
  98. ;        Cf    if error
  99. ;
  100. netbios_cancel proc
  101.     pushm    si,ds
  102.     pushm    si,ds            ; (push again, pop into NCB below)
  103.  
  104.     call    read_temp_ncb        ; clear control block
  105.     call    clear_ncb
  106.  
  107.     pop    Ncb_BufferSeg[si]    ; set control block fields
  108.     pop    Ncb_BufferOff[si]
  109.     mov    Ncb_Command[si],NB_CANCEL
  110.  
  111.     call    netbios_call
  112.     popm    ds,si
  113.     ret
  114. netbios_cancel endp
  115.  
  116.  
  117. ;;    netbios check
  118. ;
  119. ;    exit    Cf    if no netbios driver
  120. ;    uses    AX,SI
  121. ;
  122. netbios_check proc
  123.     push    ds            ; check if vector 5C is zero
  124.     mov    ax,0
  125.     mov    ds,ax
  126.     mov    si,4*5Ch
  127.     lds    si,[si]            ;  (this will fault in protect mode)
  128.     mov    ax,ds
  129.     or    ax,si
  130.     jz    nbc1            ;  if no NetBIOS driver (Cf==0)
  131.  
  132.     call    read_temp_ncb
  133.     call    clear_ncb
  134.     mov    Ncb_Command[si],NB_INVALID_COMMAND
  135.     call    netbios_call
  136.  
  137. nbc1:    cmc                ; flip error flag
  138.     pop    ds
  139.     ret
  140. netbios_check endp
  141.  
  142.  
  143. ;;    netbios delete name
  144. ;
  145. ;    entry    DS:SI    asciiz name (less than 16 characters long)
  146. ;    exit    Cf    if error
  147. ;        AL    return code
  148. ;
  149. netbios_delete_name proc
  150.     call    save_most
  151.     call    zero_temp_ncb        ; copy name to control block
  152.     call    write_temp_ncb
  153.     lea    di,Ncb_Name[di]
  154.     mov    cx,size Ncb_Name+1    ;  (+1 is for \0, OK to overflow \0
  155.     call    strncpy            ;   into next field)
  156.  
  157.     call    read_temp_ncb
  158.     mov    Ncb_Command[si],NB_DELETE_NAME_WAIT
  159.     call    netbios_call
  160.     ret
  161. netbios_delete_name endp
  162.  
  163.  
  164. ;;    netbios hang up
  165. ;
  166. ;    entry    AL    session number
  167. ;    exit    AL    return code
  168. ;        Cf    if error
  169. ;
  170. netbios_hang_up proc
  171.     pushm    si,ds
  172.     call    read_temp_ncb
  173.     call    zero_temp_ncb
  174.     mov    Ncb_Lsn[si],al
  175.     mov    Ncb_Command[si],NB_HANG_UP_WAIT
  176.     call    netbios_call
  177.     popm    ds,si
  178.     ret
  179. netbios_hang_up endp
  180.  
  181.  
  182. ;;    netbios receive wait
  183. ;
  184. ;    entry    AL    local session number
  185. ;        CX    buffer length
  186. ;        ES:DI    buffer pointer
  187. ;    exit    AL    return code
  188. ;        CX    bytes received (0 if session closed or error)
  189. ;        Cf    if error (session closed is not an error)
  190. ;
  191. netbios_receive_wait proc
  192.     pushm    si,ds
  193.     call    read_temp_ncb
  194.     call    zero_temp_ncb
  195.  
  196.     mov    Ncb_Lsn[si],al
  197.     mov    Ncb_Length[si],cx
  198.     mov    Ncb_BufferOff[si],di
  199.     mov    Ncb_BufferSeg[si],es
  200.  
  201.     mov    Ncb_Command[si],NB_RECEIVE_WAIT
  202.  
  203.     call    netbios_call
  204.     jnc    nrw1            ; if receive OK
  205.  
  206.     mov    cx,0            ; else check return code
  207.     cmp    al,0Ah
  208.     je    nrw2            ;  if session closed, then no error
  209.     stc                ;  else return error
  210.     jmp    nrw2
  211.  
  212. nrw1:    mov    cx,Ncb_Length[si]
  213. nrw2:    popm    ds,si
  214.     ret
  215. netbios_receive_wait endp
  216.  
  217.  
  218. ;;    netbios send broadcast
  219. ;
  220. ;    entry    AL    add name number
  221. ;        CX    buffer length
  222. ;        ES:DI    buffer
  223. ;    exit    AL    return code
  224. ;        Cf    if error
  225. ;    note    waits until datagram sent over network
  226. ;
  227. netbios_send_broadcast proc
  228.     pushm    si,ds
  229.     call    read_temp_ncb
  230.     call    clear_ncb
  231.     mov    Ncb_Num[si],al
  232.     mov    Ncb_Length[si],cx
  233.     mov    Ncb_BufferOff[si],di
  234.     mov    Ncb_BufferSeg[si],es
  235.     mov    Ncb_Command[si],NB_SEND_BROADCAST_WAIT
  236.     call    netbios_call
  237.     popm    ds,si
  238.     ret
  239. netbios_send_broadcast endp
  240.  
  241.  
  242. ;;    netbios send datagram
  243. ;
  244. ;    entry    AL    add name number
  245. ;        CX    buffer length
  246. ;        ES:DI    buffer
  247. ;        DS:SI    asciiz call name (destination)
  248. ;    exit    AL    return code
  249. ;        Cf    if error
  250. ;    note    waits until datagram sent over network
  251. ;
  252. netbios_send_datagram proc
  253.     call    save_most        ; initialize datagram control block
  254.     pushm    ds,si
  255.     call    zero_temp_ncb
  256.     call    read_temp_ncb
  257.     mov    Ncb_Num[si],al        ;  set "add name" number,
  258.     mov    Ncb_Length[si],cx    ;   buffer length and pointer
  259.     mov    Ncb_BufferOff[si],di
  260.     mov    Ncb_BufferSeg[si],es
  261.     popm    si,ds
  262.  
  263.     call    write_temp_ncb        ; copy destination name into block
  264.     lea    di,Ncb_CallName[di]
  265.     mov    cx,size Ncb_CallName+1
  266.     call    strncpy
  267.  
  268.     call    read_temp_ncb        ; send datagram and wait
  269.     mov    Ncb_Command[si],NB_SEND_DATAGRAM_WAIT
  270.     call    netbios_call
  271.     ret
  272. netbios_send_datagram endp
  273.  
  274.  
  275. ;;    netbios send wait
  276. ;
  277. ;    entry    AL    session number
  278. ;        CX    length
  279. ;        ES:DI    buffer pointer
  280. ;    exit    AL    return code
  281. ;        Cf    if error
  282. ;
  283. netbios_send_wait proc
  284.     pushm    si,ds
  285.     call    read_temp_ncb
  286.     call    zero_temp_ncb
  287.  
  288.     mov    Ncb_Lsn[si],al
  289.     mov    Ncb_Length[si],cx
  290.     mov    Ncb_BufferOff[si],di
  291.     mov    Ncb_BufferSeg[si],es
  292.  
  293.     mov    Ncb_Command[si],NB_SEND_WAIT
  294.  
  295.     call    netbios_call
  296.     popm    ds,si
  297.     ret
  298. netbios_send_wait endp
  299.  
  300.  
  301. ;;    put netbios name
  302. ;
  303. ;    entry    DS:SI    name field of control block
  304. ;    uses    AX,SI
  305. ;
  306. put_netbios_name proc
  307.     push    cx
  308.     mov    cx,size Ncb_CallName
  309. pnn1:    lodsb
  310.     cmp    al,' '
  311.     jbe    pnn2
  312.     cmp    al,'~'
  313.     jbe    pnn3
  314. pnn2:    mov    al,' '
  315. pnn3:    call    putchar
  316.     loop    pnn1
  317.     pop    cx
  318.     ret
  319. put_netbios_name endp
  320.  
  321.  
  322. ;;    read temp ncb
  323. ;
  324. ;    exit    DS:SI    temporary netbios control block
  325. ;
  326. read_temp_ncb proc
  327.     mov    si,@data
  328.     mov    ds,si
  329.     lea    si,temp_ncb
  330.     ret
  331. read_temp_ncb endp
  332.  
  333.  
  334. ;;    write temp ncb
  335. ;
  336. ;    exit    ES:DI    temporary netbios control block
  337. ;
  338. write_temp_ncb proc
  339.     mov    di,@data
  340.     mov    es,di
  341.     lea    di,temp_ncb
  342.     ret
  343. write_temp_ncb endp
  344.  
  345.  
  346. ;;    zero temp ncb
  347. ;
  348. zero_temp_ncb proc
  349.     pushm    ax,si,ds
  350.     call    read_temp_ncb
  351.     call    clear_ncb
  352.     popm    ds,si,ax
  353.     ret
  354. zero_temp_ncb endp
  355.  
  356.     end
  357.