home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 8 / 08.iso / d / d026 / 25.ddi / NET / NETIFACE.AS_ / NETIFACE.AS
Encoding:
Text File  |  1991-04-19  |  9.0 KB  |  320 lines

  1. page        60, 132
  2. title        Network interface code
  3. ;===============================================================================
  4. ; Filename    NETIFACE.ASM
  5. ; Copyright    (C) 1989 by Research Machines
  6. ; Copyright    (C) 1989-1990 by Microsoft Corporation
  7. ;===============================================================================
  8. ; REVISIONS:    24/02/1989    Initial Version
  9. ;        16/03/1989    Change to STANDARD procedures (save si, di, es)
  10. ;        23/03/1989    Change to segment name
  11. ;        29/03/1989    Removed LDS's
  12. ;        31/03/1989    Tidied up comments
  13. ;        ever since    Made it work
  14. ;===============================================================================
  15.  
  16.         memM    equ    1        ; Middle memory model
  17.         ?WIN    =    1        ; Windows prolog/epilog
  18.         ?PLM    =    1        ; Pascal calling convention
  19.  
  20.         .xlist
  21. include     cmacros.inc
  22. include     windows.inc
  23. include     wnet.inc
  24. include     netbios.inc
  25. include     smb.inc
  26.         .list
  27.  
  28.         .sall
  29.  
  30. ;===============================================================================
  31. ; ============= EXTERNAL FUNCTIONS =============================================
  32. ;===============================================================================
  33.  
  34. externFP    UTLMemMove
  35.  
  36. ;===============================================================================
  37. ; ============= DATA SEGMENT ===================================================
  38. ;===============================================================================
  39.  
  40. sBegin        DATA
  41.  
  42. sEnd        DATA
  43.  
  44. ;===============================================================================
  45. ; ============= CODE SEGMENT ===================================================
  46. ;===============================================================================
  47.  
  48. createSeg    _PRNT, NETCODE, BYTE, PUBLIC, CODE
  49. sBegin        NETCODE
  50.         assumes CS, NETCODE
  51.         assumes DS, DATA
  52.  
  53. ;===============================================================================
  54. ; ============= STATIC FUNTIONS ================================================
  55. ;===============================================================================
  56.  
  57. ;===============================================================================
  58. ; ============= PUBLIC FUNTIONS ================================================
  59. ;===============================================================================
  60.  
  61. ;===============================================================================
  62. subttl        NETNetBiosSend
  63. page
  64. ;===============================================================================
  65.  
  66. cProc        NETNetBiosSend, <NEAR,PUBLIC>
  67.  
  68.         parmD    lpBuffer
  69.         parmW    nSize
  70.         parmW    nSession
  71.  
  72.         localV    rgbNCB, <size NCB>
  73. cBegin
  74.  
  75.         lea    bx, rgbNCB
  76.  
  77.         mov    ss: [ bx ].ncbCommand, NetBiosSend
  78.  
  79.         mov    ax, ( nSession )
  80.         mov    ss: [ bx ].ncbLocalSession, al
  81.  
  82.         mov    ax, word ptr ( lpBuffer + 0 )
  83.         mov    word ptr ss: [ bx ].ncbBuffer + 0, ax
  84.         mov    ax, word ptr ( lpBuffer + 2 )
  85.         mov    word ptr ss: [ bx ].ncbBuffer + 2, ax
  86.  
  87.         mov    ax, ( nSize )
  88.         mov    ss: [ bx ].ncbLength, ax
  89.  
  90.         mov    ss: [ bx ].ncbNetworkNumber, 0
  91.  
  92. ;---------------------------------------------------------------
  93. ; Send the buffer across the local session.
  94. ;---------------------------------------------------------------
  95.  
  96.         push    ss
  97.         pop    es            ; es:bx -> NCB
  98.  
  99.         call    Netbioscall
  100.  
  101.         cmp    al, WN_SUCCESS
  102.         jne    SendFail
  103.  
  104.         cmp    es: [ bx ].ncbReturnCode, WN_SUCCESS
  105.         jne    SendFail
  106.  
  107.         mov    ax, WN_SUCCESS
  108.         jmp    short SendExit
  109.  
  110. ;---------------------------------------------------------------
  111. ; return FAILURE
  112. ;---------------------------------------------------------------
  113.  
  114. SendFail:    mov    ax, WN_NET_ERROR
  115.  
  116. SendExit:
  117.  
  118. cEnd
  119.  
  120. ;===============================================================================
  121. subttl        NETNetBiosReceive
  122. page
  123. ;===============================================================================
  124.  
  125. cProc        NETNetBiosReceive, <NEAR,PUBLIC>
  126.  
  127.         parmD    lpBuffer
  128.         parmW    nSize
  129.         parmW    nSession
  130.  
  131.         localV    rgbNCB, <size NCB>
  132. cBegin
  133.  
  134.         lea    bx, rgbNCB
  135.         push    ss
  136.         pop    es
  137.  
  138.         mov    es: [ bx ].ncbCommand, NetBiosReceive
  139.  
  140.         mov    ax, ( nSession )
  141.         mov    es: [ bx ].ncbLocalSession, al
  142.  
  143.         mov    ax, word ptr ( lpBuffer + 0 )
  144.         mov    word ptr es: [ bx ].ncbBuffer + 0, ax
  145.         mov    ax, word ptr ( lpBuffer + 2 )
  146.         mov    word ptr es: [ bx ].ncbBuffer + 2, ax
  147.  
  148.         mov    ax, ( nSize )
  149.         mov    es: [ bx ].ncbLength, ax
  150.  
  151.         mov    es: [ bx ].ncbNetworkNumber, 0
  152.  
  153. ;---------------------------------------------------------------
  154. ; Send the buffer across the local session.
  155. ;---------------------------------------------------------------
  156.  
  157.         call    netbioscall
  158.  
  159.         cmp    al, WN_SUCCESS
  160.         jne    ReceiveFail
  161.  
  162.         cmp    es: [ bx ].ncbReturnCode, WN_SUCCESS
  163.         jne    ReceiveFail
  164.  
  165. ;---------------------------------------------------------------
  166. ; return SUCCESS
  167. ;---------------------------------------------------------------
  168.  
  169.         mov    ax, WN_SUCCESS
  170.         jmp    short ReceiveExit
  171.  
  172. ;---------------------------------------------------------------
  173. ; Free the NCB and return FAILURE
  174. ;---------------------------------------------------------------
  175.  
  176. ReceiveFail:    mov    ax, WN_NET_ERROR
  177.  
  178. ReceiveExit:
  179.  
  180. cEnd
  181.  
  182. ;===============================================================================
  183. subttl        NETGetPrintQueue
  184. page
  185. ;===============================================================================
  186. ;
  187. ; DESCRIPTION .
  188. ; ENTRY .......
  189. ; EXIT ........
  190. ; COMMENTS .... The caller must ensure that Buffer is large enough
  191. ;        to hold all the print queue entries plus an SMB request
  192. ;        header (maximum 1834 bytes). If not, they are
  193. ;        lightly soya margarine'ed wholewheat toast.
  194. ;
  195. ;===============================================================================
  196.  
  197. cProc        NETGetPrintQueue, <FAR, PUBLIC>, <si, di>
  198.  
  199.         parmD    lpBuffer
  200.         parmW    nIndex
  201.         parmW    nCount
  202.         parmW    nSessionNumber
  203.  
  204.         localW    nEntriesReturned
  205.         localW    nReturnCode
  206. cBegin
  207.         mov    ( nReturnCode ), WN_SUCCESS        ; ever optimistic
  208.  
  209. ;---------------------------------------------------------------
  210. ; Use the start of the buffer as an SMB request packet.
  211. ;---------------------------------------------------------------
  212.  
  213.         les    bx, ( lpBuffer )
  214.  
  215.         ; zero out the buffer
  216.         mov    di, bx
  217.         mov    cx, size SMBGetPrintQ / 2
  218.         sub    ax,ax
  219.         rep    stosw
  220.  
  221.         ; initialize the header magic bytes
  222.         mov    byte ptr es: [ bx ].smbHeader + 0, 0ffh
  223.         mov    byte ptr es: [ bx ].smbHeader + 1, 'S'
  224.         mov    byte ptr es: [ bx ].smbHeader + 2, 'M'
  225.         mov    byte ptr es: [ bx ].smbHeader + 3, 'B'
  226.  
  227.         ; set the fields for the 'get spool queue' function
  228.         mov    es: [ bx ].smbCommandCode, SMBReturnPrintQueue
  229.         mov    es: [ bx ].smbParameterCount, 2
  230.         mov    ax, ( nCount )
  231.         mov    es: [ bx ].smbGPQMaxCount, ax
  232.         mov    ax, ( nIndex )
  233.         mov    es: [ bx ].smbGPQStartIndex, ax
  234.         mov    es: [ bx ].smbGPQByteCount, 0
  235.  
  236. ;---------------------------------------------------------------
  237. ; Send the request over the specified session.
  238. ;---------------------------------------------------------------
  239.  
  240.         mov    ax, size SMBGetPrintQ            ; ?
  241.  
  242.         Arg    lpBuffer                ; -> SMB request
  243.         Arg    ax                    ; size
  244.         Arg    nSessionNumber                ; session
  245.         cCall    NETNetBiosSend
  246.  
  247.         cmp    ax, WN_SUCCESS
  248.         je    WaitForQueue
  249.  
  250.         mov    ( nReturnCode ), ax
  251.         jmp    short GetPrintQueueExit
  252.  
  253. ;---------------------------------------------------------------
  254. ; Wait for the reply to come back.
  255. ;---------------------------------------------------------------
  256.  
  257. WaitForQueue:    mov    ax, size SMBPrintQEntry
  258.         mov    cx, ( nCount )
  259.         mul    cx
  260.         add    ax, size SMBGetPrintQ
  261.  
  262.         Arg    lpBuffer                ; -> SMB request
  263.         Arg    ax                    ; size
  264.         Arg    nSessionNumber                ; session
  265.         cCall    NETNetBiosReceive
  266.                                 ;
  267.         cmp    ax, WN_SUCCESS                ;
  268.         jne    NetworkError                ;
  269.  
  270.         les    bx, ( lpBuffer )            ;
  271.  
  272.         cmp    es: [ bx ].smbErrorCodeClass, WN_SUCCESS;
  273.         je    ReturnCount                ;
  274.  
  275. NetworkError:    mov    ( nReturnCode ), WN_NET_ERROR
  276.         jmp    short GetPrintQueueExit
  277.  
  278. ;---------------------------------------------------------------
  279. ; Find the number of entries in the buffer.
  280. ;---------------------------------------------------------------
  281.  
  282. ReturnCount:    les    bx, ( lpBuffer )
  283.         mov    ax, es: [ bx ].smbGPQMaxCount
  284.         mov    ( nEntriesReturned ), ax
  285.  
  286. ;---------------------------------------------------------------
  287. ; Shuffle the entries to the head of the buffer, overwriting
  288. ; the SMB header.
  289. ;---------------------------------------------------------------
  290.  
  291.         mov    ax, size SMBPrintQEntry         ; Calculate number
  292.         mov    cx, ( nEntriesReturned )        ; of bytes used in
  293.         mul    cx                    ; queue entries.
  294.  
  295.         les    bx, ( lpBuffer )            ; Calculate source
  296.         add    bx, size SMBGetPrintQ            ; address for move.
  297.  
  298.         Arg    lpBuffer                ; lpDestination
  299.         Arg    RegPairEsBx                ; lpSource
  300.         Arg    ax                    ; nCount
  301.         cCall    UTLMemMove                ;
  302.  
  303. ;---------------------------------------------------------------
  304. ; Return to caller.
  305. ;---------------------------------------------------------------
  306.  
  307. GetPrintQueueExit:
  308.  
  309.         mov    ax, ( nReturnCode )
  310.         mov    cx, ( nEntriesReturned )
  311. cEnd
  312.  
  313.  
  314. ;===============================================================================
  315. ; ============= END OF NETIFACE ================================================
  316. ;===============================================================================
  317.  
  318. sEnd        NETCODE
  319.         end
  320.