home *** CD-ROM | disk | FTP | other *** search
/ HAM Radio 1 / HamRadio.cdr / packet / pclana / pclana.asm next >
Assembly Source File  |  1989-07-27  |  18KB  |  823 lines

  1.     Title    pclana -- IBM PC LAN or SYTEK 6120 Packet Driver Interface
  2.     Page    ,132
  3. version    equ    5
  4.  
  5. ;
  6. ;       COPYRIGHT (c) 1989, Kevin J. Rowett -- N6RCE
  7. ;          Cupertino, CA
  8. ;
  9.  
  10. ;
  11. ;   implements the body of a packet driver supporting the 
  12. ;   IBM PC network LAN adapter (LANA), also known as a SYTEK 6120
  13. ;   card.
  14. ;
  15. ;   These cards have an on-board (now known as version 1) NETBIOS
  16. ;   interface, accessed via INT 5C.
  17. ;
  18. ;   The cards implement networking with their own OSI style session
  19. ;   and transport protocols. The MAC layer is almost raw 802.3
  20. ;
  21. ;   While the card has a connected mode session protocol available,
  22. ;   our implementation uses the DATAGRAM mode.  Packets are sent and
  23. ;   received as datagrams using the PROM supplied MAC address. 
  24. ;   Broadcast packets are send/received using the DATAGRAM BROADCAST
  25. ;   mode.
  26. ;
  27. ;   The card is not nice enough to interrupt us when a frame has
  28. ;   arrived.  We must supply it a buffer to put the frame into
  29. ;   as it arrives.  Therefore, we have one DATAGRAM and DATAGRAM
  30. ;   BROADCAST buffer defined here.  Of course, if we don't empty
  31. ;   it fast enough, the next arriving frame will go into the bit 
  32. ;   bucket :-).  Some might view this as a performance problem.
  33. ;   So does the author :-(.
  34. ;
  35. ;   We reserve another NCB for control.
  36. ;
  37. ;   Why bother you ask? So, N3EUA can demo N6GN's uwv talents.
  38. ;
  39.  
  40.     Page
  41.     include    defs.asm    ;SEE ENCLOSED COPYRIGHT MESSAGE
  42.  
  43.     Page
  44. code    segment    byte public
  45.     assume    cs:code, ds:code
  46.  
  47.     public    int_no
  48. int_no        db    3,0,0,0        ;we don't use it, but tail.asm wants to
  49.                             ;fix it if this is an AT
  50.  
  51.     public    lana_num
  52. lana_num    db    0,0,0,0
  53.  
  54.     public    mac_addr
  55. mac_addr        db    6 dup (0)
  56. ether_broadcast    db    6 dup (0FFh)
  57.  
  58.     public    driver_class, driver_type, driver_name
  59. driver_class    db    1        ;from the packet spec
  60. driver_type    db    16        ;from the packet spec
  61. driver_name    db    'pclana',0    ;name of the driver.
  62.  
  63. savess        Dw    ?
  64. savesp        Dw    ?
  65.  
  66. ;
  67. ;  Struct defining a std NCB layout
  68. ;
  69. NCB    Struc
  70.  
  71.  
  72. NCB_COMMAND    Db    ?                  ;NCB command field
  73. NCB_RETCODE    Db    ?      
  74. NCB_LSN        Db    ?                  ;local session number
  75. NCB_NUM        Db    ?                ;NCB number of your name
  76. NCB_BUFFER    Dd    ?                ;FAR ptr to buffer
  77. NCB_LENGTH    Dw    ?                ;bufer length
  78. NCB_CALLNAME    Db    16 dup (?)    ;name on local or remote adapter
  79. NCB_NAME    Db    16 dup (?)        ;name on local adapter
  80. NCB_RTO        Db    ?                ;receive timeout value
  81. NCB_STO        Db    ?                ;send timeout value
  82. NCB_POST        Dd    ?            ;far ptr to post completion rtn
  83. NCB_LANA_NUM    Db    ?            ;adapter number 0 or 1
  84. NCB_CMD_CPLT    Db    ?            ;cmd status flag
  85. NCB_RESERVE     Db    14 dup (?)    ;reserved work area
  86.  
  87. previous_error    Db    ?
  88. immediate_error    Db    ?
  89. active_flag        Db    ?    ;have we done an INT on this NCB?
  90. NCB_link        Dw    ?            ;offset to next NCB
  91.  
  92. NCB_data_buffer    Db    512 dup (0)
  93.  
  94. NCB            ends
  95.  
  96. NETBIOS        Equ        5CH
  97.  
  98. MAX_LANA_BUF_LEN    Equ    512
  99. ncb_count        Equ    5
  100. NCB_in_use    Equ    0FFH
  101. NCB_unused    Equ    00H
  102.  
  103. CTL_NCB    Db    (size NCB) dup (0)
  104.  
  105. RCV_NCB    Db    ncb_count*(size NCB) dup (0)
  106.  
  107. RCV_BDCST_NCB    Db    ncb_count*(size NCB) dup (0)
  108.  
  109. SEND_NCB    Db    (size NCB) dup (0)
  110.  
  111. SEND_BDCST_NCB    Db    (size NCB) dup (0)
  112.  
  113. send_in_use    Db    00H
  114. recv_in_use    Db    00H
  115.  
  116. stack        Dw    100 dup (?)
  117.  
  118. ;
  119. ;   cmd codes for the LANA
  120. ;
  121. LANA_RESET    Equ    32H                ;RESET, waited mode
  122. LANA_ADPTS    Equ    33H                ;Adapter status, waited mode
  123. LANA_SENDDG    Equ    0A0H            ;SEND DATAGRAM, nowait mode
  124. LANA_SENDDG_BDCST    Equ    0A2H    ;SEND BROADCAST DATAGRAM, nowait 
  125. LANA_RCVDG    equ    0A1H            ;RCV DATAGRAM, nowait
  126. LANA_RCVDG_BDCST    Equ    0A3H    ;RCV BROADCAST DATAGRAM, nowait
  127. LANA_TEST_PRES        Equ    7FH        ;TEST IF LANA Present (inv cmd)
  128.  
  129.     Subttl    send_pkt
  130.     Page
  131.     public    send_pkt
  132. send_pkt:
  133. ;enter with ds:si -> packet, cx = packet length.
  134. ;exit with nc if ok, or else cy if error, dh set to error number.
  135.  
  136.     
  137.     assume    ds:nothing
  138. ;  better protect our selves
  139.     Pushf
  140.     Cli
  141.     Nop     ;03H
  142.     Cmp    CS:send_in_use,NCB_in_use
  143.     Jne    not_reentered_s
  144.     Int    03H
  145.  
  146. not_reentered_s:
  147.     Mov    send_in_use,NCB_in_use
  148.  
  149. ;  check to see if the recv routine is active
  150.     Cmp    CS:recv_in_use,NCB_in_use
  151.     Jne    not_reentered_r_wins
  152.     Int    03H
  153.  
  154. not_reentered_r_wins:
  155.  
  156.     Popf
  157.     Pushf
  158.  
  159. ;  check the length
  160.     Cmp        CX,MAX_LANA_BUF_LEN
  161.     Jb        ok_send_len
  162.     Mov        CX,MAX_LANA_BUF_LEN
  163. ok_send_len:
  164.  
  165. ;
  166. ;  Determine if the destination is broadcast
  167. ;   real ethernet uses the DMAC of all FFh for broadcast
  168. ;   The LANA does as well, but it wants us to use a different
  169. ;    NCB type.
  170. ;
  171.     Push    SI                        ;save ptr to start of buffer
  172.     Push    CX                        ;and original length of packet
  173.     Mov        CX,6
  174.     Mov        DI,offset ether_broadcast
  175.     Push    CS
  176.     Pop        ES
  177.     Cld
  178.     Repe    Cmpsb
  179.     Pop        CX
  180.     Pop        SI
  181.     Jz        send_bdcst
  182.     Jmp        send_dgram
  183. ;
  184. send_bdcst:
  185. ;
  186. ;  send in broadcast mode
  187. ;
  188.     Mov        BX,offset  SEND_BDCST_NCB
  189.     Jmp        send_ncb_prep
  190.     
  191. send_dgram:
  192. ;
  193. ;  send in datagram mode
  194. ;
  195.     Mov        BX,offset  SEND_NCB
  196.     Jmp        send_ncb_prep
  197.  
  198.  
  199. send_ncb_prep:
  200.  
  201. ; check previous send operation completed. Note, we prime the value of
  202. ; this field during etopen ( retcode = 00H, cmd_cplt = 00H )
  203. sendb_cplt_loop:
  204.     Cmp        [BX].NCB_CMD_CPLT,0FFh
  205.       Je        sendb_cplt_loop
  206.     Jne        sendb_cplt
  207.     Int    03H
  208.     Popf
  209.     Stc
  210.     Ret
  211.  
  212. sendb_cplt:
  213. ;
  214.     Push    CS
  215.     Pop    ES
  216.     Mov        AL,ES:[BX].NCB_RETCODE
  217.     Mov        ES:[BX].previous_error,AL
  218. ;  the NCB is ours. Initialize it.
  219.     Call    init_ncb
  220. ;
  221. ;    setup the length field
  222. ;
  223.     Mov        ES:[BX].NCB_LENGTH,CX
  224. ;
  225. ;    Move the destination address into CALLNAME
  226. ;
  227.     Lea        DI,ES:[BX].NCB_CALLNAME+10
  228.     Push    CX
  229.     Mov        CX,6
  230.     Push    SI
  231.     Rep        Movsb
  232.     Pop        SI
  233.     Pop        CX
  234. ;
  235. ;    Move the data to the buffer
  236. ;
  237.     Lea        DI, ES:[BX].NCB_data_buffer
  238.     Rep    Movsb
  239. ;
  240. ;    NCB is prepared and ready to go
  241. ;
  242. ;    note, we don't load the cmd field, since init will do this
  243. ;   for us, and the LANA never alters it
  244. ;
  245.     Int        NETBIOS
  246.     Mov        ES:[BX].immediate_error,AL
  247.     Cmp        AL,00H
  248.     Je        okay_send_ret
  249.     Mov        DH,CANT_SEND
  250.     Mov    CS:send_in_use,NCB_unused
  251.     Int     03H
  252.     Popf
  253.     Stc
  254.     Ret
  255.  
  256. okay_send_ret:
  257.     Mov        DH,00H
  258.     Mov    CS:send_in_use,NCB_unused
  259.     Popf
  260.     Clc
  261.     Ret
  262.     
  263.  
  264.  
  265.     Subttl    get_address
  266.     Page
  267.     public    get_address
  268. get_address:
  269. ;get the address of the interface.
  270. ;enter with es:di -> place to get the address, cx = size of address buffer.
  271. ;exit with nc, cx = actual size of address, or cy if buffer not big enough.
  272.  
  273.     assume    ds:code
  274.     Cmp        CX,6
  275.     Jb        get_address_2
  276.     Mov        CX,6                        ;count of bytes to copy
  277.     Cld                                    ;increment addr index
  278.     Mov        si,OFFSET mac_addr
  279. ;       dest is a callng parameter
  280.     Rep        Movsb
  281.     Mov        CX,6
  282.     Clc
  283.     Ret
  284. get_address_2:
  285.     Stc
  286.     Ret
  287.  
  288.     Subttl    set_address
  289.     Page
  290. ;Set Ethernet address on controller
  291.     public    set_address
  292. set_address:
  293.     assume    ds:nothing
  294. ;enter with ds:si -> Ethernet address, CX = length of address.
  295. ;exit with nc if okay, or cy, dh=error if any errors.
  296. ;
  297.     stc
  298. set_address_done:
  299.     push    cs
  300.     pop    ds
  301.     assume    ds:code
  302.     ret
  303.  
  304.  
  305.     Subttl    reset_interface
  306.     Page
  307.     public    reset_interface
  308. reset_interface:
  309. ;reset the interface.
  310. ;    RESET the LANA
  311. ;
  312.     Mov        BX,offset CTL_NCB
  313.     Call    init_ncb
  314.     Mov        [BX].NCB_COMMAND,LANA_RESET
  315.     Mov        [BX].NCB_LSN,01H            ;number of sessions to support
  316.     Mov        [BX].NCB_NUM,06H            ;number of commands to support
  317.     Int        NETBIOS
  318. ;
  319.     Ret
  320.  
  321.  
  322.     Subttl    
  323.     Page
  324. ;called when we want to determine what to do with a received packet.
  325. ;enter with cx = packet length, es:di -> packet type.
  326.     extrn    recv_find: near
  327.  
  328. ;called after we have copied the packet into the buffer.
  329. ;enter with ds:si ->the packet, cx = length of the packet.
  330.     extrn    recv_copy: near
  331.  
  332.     extrn    count_in_err: near
  333.     extrn    count_out_err: near
  334.  
  335.     Subttl    recv
  336.     Page
  337.     public    recv
  338. recv:
  339. ;called from the recv isr.  All registers have been saved, and ds=cs.
  340. ;Upon exit, the interrupt will be acknowledged.
  341.     assume    ds:code
  342.  
  343.     Mov        AL,ES:[BX].NCB_RETCODE
  344.     Mov        ES:[BX].previous_error,AL
  345.     Les        DI,ES:[BX].NCB_BUFFER
  346. ;
  347. ;  Check if it is from ourselves ( we hear our own broadcasts), if
  348. ;  so, then ignore it.
  349. ;
  350.     Add        DI,6                    ;point to SMAC
  351.     Mov        CX,6
  352.     Mov        SI,offset mac_addr
  353.     Cld
  354.     Repe    Cmpsb
  355.     Jz        drop_frame                ;it's from ourselves
  356.     
  357. ;  after the above, we have no idea where DI is pointing
  358.  
  359.     Les        DI,ES:[BX].NCB_BUFFER
  360.     Add        DI,12                ;point to frame type field
  361.     Mov        CX,ES:[BX].NCB_LENGTH
  362.     Push    BX
  363.     Nop    ;03H
  364.     Call    recv_find
  365. ; returns with buffer ptr in ES:DI, or null if not buffer allocated
  366.  
  367.     Pop        BX
  368.     Mov        AX,ES                    ;did we get a buffer ptr back?
  369.     Or        AX,DI
  370.     Je        drop_frame
  371.  
  372.     Push    ES                        ;remember ptr to appl's buffer
  373.     Push    DI
  374.  
  375.     Mov        CX,DS:[BX].NCB_LENGTH
  376.     Lds        SI,DS:[BX].NCB_BUFFER
  377.  
  378.     Cld
  379.     Rep        Movsb
  380.     
  381.     Mov        CX,DS:[BX].NCB_LENGTH
  382.     Pop        SI
  383.     Pop        DS
  384.     Call    recv_copy
  385.  
  386. drop_frame:
  387.  
  388. ;
  389. ;   to keep receiving of frames, we need to put another NCB
  390. ;   to the LANA.  The NCB's are chained in a single forward linked
  391. ;   list.  We loop thru it looking for one to use.
  392.  
  393.     Push    CS
  394.     Pop    DS
  395.     Push    BX        ;we'll need to get back to the one
  396.                 ;we started with
  397.     Mov    CX,ncb_count    ;loop counter
  398.     Dec    CX        ;since at least one is in use!
  399. src_free_recv_NCB:
  400.     Mov    BX,[BX].NCB_link    ;link to the next NCB
  401.     Cmp    [BX].active_flag,NCB_unused  ;this guy free?
  402.     Je    fnd_free_recv_NCB    ;yea! use him
  403.     Loop    src_free_recv_NCB    ;no, keep looking
  404.     Pop    BX            ;didn't find a free NCB
  405.     Jmp    no_free_recv_NCB    ;but that is okay
  406.  
  407. fnd_free_recv_NCB:
  408.  
  409.     Push    CS
  410.     Pop    ES
  411.     Call    init_ncb
  412.     Mov    AX,offset lana_post_recv
  413.     Mov    word ptr  ES:[BX].NCB_POST,AX
  414.     Mov    AX,ES
  415.     Mov    word ptr  ES:[BX].NCB_POST+2,AX
  416.     Mov    [BX].NCB_LENGTH,MAX_LANA_BUF_LEN
  417.     Mov    [BX].active_flag,NCB_in_use
  418.  
  419.     Int    NETBIOS
  420.     Mov    [BX].immediate_error,AL
  421.     Pop    BX
  422.  
  423. no_free_recv_NCB:
  424.     Mov    [BX].active_flag,NCB_unused
  425.  
  426.     Ret
  427.  
  428.     Subttl    lana_post_recv
  429.     Page
  430. lana_post_recv:
  431. ;
  432. ;  come here when the LANA posts open of the RECV NCB's as complete
  433. ;
  434. ;  AL = RetCode
  435. ;  CS = set to this code segment
  436. ;  ES = of the NCB
  437. ;  BX = offset of the NCB
  438. ;  we don't need to preserve any of the registers, since the LANA
  439. ;  BIOS has already done that.
  440.  
  441.     
  442. ;  check to see if this is a recursive reenter
  443.     Cmp    CS:recv_in_use,NCB_in_use
  444.     Jne    not_reentered_r
  445.     Int    03H
  446.  
  447. not_reentered_r:
  448.     Mov    recv_in_use,NCB_in_use
  449.  
  450. ;  check to see if the send routine is active
  451.     Cmp    CS:send_in_use,NCB_in_use
  452.     Jne    not_reentered_s_winr
  453.     Int    03H
  454.  
  455. not_reentered_s_winr:
  456.  
  457.     Mov        AX,CS
  458.     Mov        DS,AX
  459.  
  460.     Mov        savesp,SP
  461.     Mov        savess,SS
  462.  
  463.     Mov        SS,AX
  464.     Mov        SP,offset stack
  465.  
  466.     Call    Recv
  467.  
  468.     Mov    recv_in_use,NCB_unused
  469.     Push    CS
  470.     Pop        DS
  471.     Mov        SS,savess
  472.     Mov        SP,savesp
  473.     
  474.     Iret
  475.     
  476.     Subttl    init_ncb
  477.     Page
  478. init_ncb:
  479. ;  bx -> NCB to clear and init
  480.  
  481. ;            Mov        [BX].NCB_COMMAND,00H
  482. ; note, we don't init NCB_COMMAND Field, as it's value, once set is
  483. ; never changed
  484. ;
  485.     Mov        ES:[BX].NCB_RETCODE,00H
  486.     Mov        ES:[BX].NCB_LSN,00H
  487.     Mov        ES:[BX].NCB_NUM,01H        ;01H says use the PROM MAC address
  488.     Mov        AX,0000H
  489.     Mov        word ptr  ES:[BX].NCB_LENGTH,AX
  490.     Lea        AX,       ES:[BX].NCB_data_buffer
  491.     Mov        word ptr  ES:[BX].NCB_BUFFER,AX
  492.     Mov        AX,ES
  493.     Mov        word ptr  ES:[BX].NCB_BUFFER+2,AX
  494. ;
  495.     Push    SI
  496. ;
  497.     Mov        SI,0000H
  498. init_ncb_1:
  499.     Mov        AX,0000H
  500.     Mov        word ptr ES:[BX][SI].NCB_CALLNAME,AX
  501.     Inc        SI
  502.     Inc        SI
  503.     Cmp        SI,8
  504.     Jl        init_ncb_1
  505. ;
  506.     Mov        SI,0000H
  507.     Mov        AX,0000H
  508. init_ncb_2:
  509.     Mov        word ptr ES:[BX][SI].NCB_NAME,AX
  510.     Inc        SI
  511.     Inc        SI
  512.     Cmp        SI,5                    ;this sets first ten bytes to zero
  513.     Jl        init_ncb_2
  514.     Mov        AX,word ptr CS:mac_addr
  515.     Mov        word ptr ES:[BX].NCB_NAME+10,AX
  516.     Mov        AX,word ptr CS:mac_addr+2
  517.     Mov        word ptr ES:[BX].NCB_NAME+12,AX
  518.     Mov        AX,word ptr CS:mac_addr+4
  519.     Mov        word ptr ES:[BX].NCB_NAME+14,AX
  520. ;
  521.     Mov        ES:[BX].NCB_RTO,00H
  522.     Mov        ES:[BX].NCB_STO,00H
  523.     Mov        AX,0000H
  524.     Mov        word ptr ES:[BX].NCB_POST,AX
  525.     Mov        word ptr ES:[BX].NCB_POST+2,AX
  526.     Mov        AL,ES:lana_num
  527.     Mov        ES:[BX].NCB_LANA_NUM,AL
  528.     Mov        ES:[BX].NCB_CMD_CPLT,00H
  529. ;
  530.     Mov        SI,0000H
  531.     Mov        AX,0000H
  532. init_ncb_3:
  533.     Mov        word ptr ES:[BX][SI].NCB_RESERVE,AX
  534.     Inc        SI
  535.     Inc        SI
  536.     Cmp        SI,7
  537.     Jl        init_ncb_3
  538. ;
  539.     Pop     SI
  540.     Ret
  541.  
  542.  
  543.     
  544. ;any code after this will not be kept after initialization.
  545. end_resident    label    byte
  546.  
  547.  
  548.     Subttl    
  549.     Page
  550.     public    usage_msg
  551. usage_msg    db    "usage: pclana <packet_int_no> <LANA # -- 1 | 2>",CR,LF,'$'
  552.  
  553.     public    copyright_msg
  554. copyright_msg    db    "Packet driver for IBM PC LAN card or SYTEK 6120, version ",'0'+majver,".",'0'+version,CR,LF
  555.         db    "Portions Copyright 1989, Kevin J. Rowett - N6RCE",CR,LF,'$'
  556.  
  557. no_lana_msg    db    "NETBIOS (LANA) not present",CR,LF,'$'
  558.  
  559. inv_lana_num_msg    db    "No LANA with that number found",CR,LF,'$'
  560.  
  561. lana_err_msg    db    "LANA  returned error",CR,LF,'$'
  562.  
  563. lana_num_name    db    "LANA number = ",'$'
  564.  
  565.     extrn    set_recv_isr: near
  566.  
  567.     Subttl    parse_args
  568.     Page
  569. ;enter with si -> argument string, di -> word to store.
  570. ;if there is no number, don't change the number.
  571.     extrn    get_number: near
  572.  
  573.     public    parse_args
  574. parse_args:
  575.  
  576.     Mov        di,offset lana_num            ;save the LANA or NCB
  577.     Mov        bx,offset lana_num_name        ;and name for get num to print
  578.     Call    get_number
  579.     Dec        lana_num                    ;user supplies 1 or 2, card want
  580.                                         ; 0 or 1
  581.     
  582.     Ret
  583.  
  584.  
  585. lana_not_present:
  586.  
  587.     Mov        dx,offset no_lana_msg
  588.     Mov        ah,9
  589.     Int        21H                            ;DOS FN Call
  590.     Stc
  591.     Ret
  592.  
  593.  
  594. invalid_lana_num:
  595.  
  596.     Mov        dx,offset inv_lana_num_msg
  597.     Mov        ah,9
  598.     Int        21H                            ;DOS FN Call
  599.     Stc
  600.     Ret
  601.  
  602.  
  603. lana_error_rpt:
  604.     
  605.     Mov        dx,offset lana_err_msg
  606.     Mov        ah,9
  607.     Int        21H                            ;DOS FN Call
  608.     Stc
  609.     Ret
  610.     
  611.  
  612.     Subttl    etopen
  613.     Page
  614.     public    etopen
  615. etopen:
  616. ;if all is okay,
  617.  
  618. ;
  619. ;  check to see if the LANA is present.  Right out of book, page 2-88.
  620. ;
  621. ;  version two learned something.  Also must check the vector is not pointing
  622. ;  into ROM above 0D000h.
  623. ;   
  624. ;
  625. ;   1. check that INT 5C is not zero's
  626. ;
  627. ;   1A check segment < 0D000h
  628. ;
  629. ;    2. issue a cmd 7fH
  630. ;
  631. ;    3. see that the cmd comes back 03H (invalid cmd)
  632. ;
  633. ;    if so, we have an adapter present
  634. ;
  635.  
  636.     Mov        send_in_use,NCB_unused
  637.     Mov        recv_in_use,NCB_unused
  638.     Mov        ah,35H                        ;DOS FN get vector
  639.     Mov        al,NETBIOS
  640.     Int        21H                            ;Hello DOS
  641.     Cmp        bx,0000H                ;vector other than zero?
  642.     Jne        lana_pres_test2
  643.     Jmp        lana_not_present
  644. lana_pres_test2:
  645.     Mov        BX,ES
  646. ; get our ES back
  647.     Push    DS
  648.     Pop        ES
  649.     Cmp        BX,0000H
  650.     Jne        lana_pres_test3
  651.     Jmp        lana_not_present
  652. lana_pres_test3:
  653.     Cmp        BX,0D000H
  654.     Jb        lana_present
  655.     Jmp        lana_not_present
  656. lana_present:
  657.  
  658. ;   vector not zero
  659.  
  660.  
  661.     Mov        BX,offset CTL_NCB
  662. ;
  663.     Call    init_ncb
  664.     Mov        [BX].NCB_COMMAND,LANA_TEST_PRES
  665.     Int        NETBIOS
  666.     Cmp        [BX].NCB_RETCODE,03H
  667.     Je        lana_test_ret_ok
  668.     Cmp        [BX].NCB_RETCODE,23H
  669.     Je         invalid_lana_num_s
  670.     Jmp        lana_not_present
  671. invalid_lana_num_s:
  672.     Jmp        invalid_lana_num
  673.  
  674.  
  675. lana_test_ret_ok:
  676.  
  677. ;   good chance we have a LANA present
  678. ;
  679. ;    Now, RESET the bastard, and get the MAC address
  680. ;
  681.     Call    init_ncb
  682.     Mov        [BX].NCB_COMMAND,LANA_RESET
  683.     Mov        [BX].NCB_LSN,01H            ;number of sessions to support
  684.     Mov        [BX].NCB_NUM,0cH            ;number of commands to support
  685.     Int        NETBIOS
  686.     Cmp        [BX].NCB_RETCODE,00H
  687.     Je        lana_reset_okay
  688.     Jmp        lana_error_rpt
  689. lana_reset_okay:
  690. ;
  691. ;    adapter status please
  692. ;
  693.     Call    init_ncb
  694.     Mov        [BX].NCB_COMMAND,LANA_ADPTS
  695.     Mov        [BX].NCB_CALLNAME,'*'        ;get status of local adapter
  696.     Mov        [BX].NCB_LENGTH,MAX_LANA_BUF_LEN
  697.     Int        NETBIOS
  698.     Cmp        [BX].NCB_RETCODE,00H
  699.     Je        lana_adpts_okay
  700.     Jmp        lana_error_rpt
  701. lana_adpts_okay:
  702. ;
  703. ;    save the mac address
  704. ;
  705.     Mov        AX,word ptr [BX].NCB_data_buffer
  706.     Mov        word ptr mac_addr,AX
  707.     Mov        AX,word ptr [BX].NCB_data_buffer+2
  708.     Mov        word ptr mac_addr+2,AX
  709.     Mov        AX,word ptr [BX].NCB_data_buffer+4
  710.     Mov        word ptr mac_addr+4,AX
  711.  
  712. ;
  713. ;   set the NCB_COMMAND fields for the various static NCB's
  714. ;
  715.     Mov        BX,offset SEND_NCB
  716.     Mov        [BX].NCB_COMMAND,LANA_SENDDG
  717.     
  718.     Mov        BX,offset SEND_BDCST_NCB
  719.     Mov        [BX].NCB_COMMAND,LANA_SENDDG_BDCST
  720.  
  721. ;
  722. ;    loop thru the string of receive style NCB's
  723. ;
  724.     Mov        BX,offset RCV_NCB
  725.     Mov        CX,ncb_count
  726.  
  727. recv_ncb_loop:
  728.     Call    init_ncb
  729.     Mov        AX,offset lana_post_recv
  730.     Mov        word ptr  ES:[BX].NCB_POST,AX
  731.     Mov        AX,ES
  732.     Mov        word ptr  ES:[BX].NCB_POST+2,AX
  733.     Mov        [BX].NCB_COMMAND,LANA_RCVDG
  734.     Mov        [BX].NCB_LENGTH,MAX_LANA_BUF_LEN
  735.     Mov        [BX].active_flag,NCB_in_use
  736.  
  737.     Mov        DX,BX
  738.     Add        DX,size NCB
  739.     Mov        [BX].NCB_link,DX
  740.     Mov        BX,DX
  741.  
  742.     Loop    recv_ncb_loop
  743. ;
  744. ;  fix up the last one
  745. ;
  746.     Sub        BX,size NCB
  747.     Mov        Dx,offset RCV_NCB
  748.     Mov        [BX].NCB_link,DX
  749.  
  750. ;
  751. ;    post a chain of rcv datagram NCBs
  752. ;
  753.     Mov        BX,offset RCV_NCB
  754.     Mov        CX,ncb_count
  755.  
  756. rcv_ncb_post_loop:
  757.      Int        NETBIOS
  758.      Mov        [BX].immediate_error,AL
  759.      Cmp        AL,00H
  760.      Je        ok_post_rcvdg
  761.     Jmp        lana_error_rpt
  762. ok_post_rcvdg:
  763.     Add        BX,size NCB
  764.     Loop    rcv_ncb_post_loop
  765.     
  766.     
  767. ;
  768. ;    now the same for rcv broadcast ncb's
  769. ;
  770.     Mov        BX,offset RCV_BDCST_NCB
  771.     Mov        CX,ncb_count
  772.  
  773. recv_bdcst_ncb_loop:
  774.     Call    init_ncb
  775.     Mov        AX,offset lana_post_recv
  776.     Mov        word ptr  ES:[BX].NCB_POST,AX
  777.     Mov        AX,ES
  778.     Mov        word ptr  ES:[BX].NCB_POST+2,AX
  779.     Mov        [BX].NCB_COMMAND,LANA_RCVDG_BDCST
  780.     Mov        [BX].NCB_LENGTH,MAX_LANA_BUF_LEN
  781.     Mov        [BX].active_flag,NCB_unused
  782. ;        We marked the BDCST as unused initially, since we only 
  783. ;        post one of them
  784.  
  785.     Mov        DX,BX
  786.     Add        DX,size NCB
  787.     Mov        [BX].NCB_link,DX
  788.     Mov        BX,DX
  789.  
  790.     Loop    recv_bdcst_ncb_loop
  791. ;
  792. ;  fix up the last one
  793. ;
  794.     Sub        BX,size NCB
  795.     Mov        Dx,offset RCV_BDCST_NCB
  796.     Mov        [BX].NCB_link,DX
  797.  
  798. ;
  799. ;    post only one RECV BDCST DATAGRAM NCB, as they all complete
  800. ;   at once.
  801. ;
  802.     Mov        BX,offset RCV_BDCST_NCB
  803.     Mov        [BX].active_flag,NCB_in_use ;mark as in_use
  804.       Int        NETBIOS
  805.       Mov        [BX].immediate_error,AL
  806.       Cmp        AL,00H
  807.       Je        ok_post_rcvdg_bdcst
  808. ;      Jmp        ok_post_rcvdg_bdcst
  809.     Jmp        lana_error_rpt
  810. ok_post_rcvdg_bdcst:
  811.  
  812.     
  813.     mov    dx,offset end_resident
  814.     clc
  815.     ret
  816. ;if we got an error,
  817.     stc
  818.     ret
  819.  
  820. code    ends
  821.  
  822.     end
  823.