home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 2 / ctrom_ii_b.zip / ctrom_ii_b / PROGRAM / PASCAL / NETCHA / NETWORK.PAS < prev   
Encoding:
Pascal/Delphi Source File  |  1988-12-01  |  8.9 KB  |  221 lines

  1. {/////////////////////////////////////////////////////////////////////////////
  2. // Network Unit Version 1.0                                December 1, 1988 //
  3. // Copyright 1988 by L. Brett Glass, Systems Consultant                     //
  4. //                                                                          //
  5. // This source code is copyrighted and may NOT be published in any medium   //
  6. // without the express permission of the author.                            //
  7. //                                                                          //
  8. // Please address correspondence to:                                        //
  9. // L. Brett Glass, P.O Box 817, Palo Alto, CA 94302-0817                    //
  10. //////////////////////////////////////////////////////////////////////////////}
  11.  
  12. unit Network;
  13.  
  14. interface
  15.  
  16. const {Codes for NetBIOS commands.
  17.        Note that only those commands for which there is a constant
  18.        ending in NO_WAIT can be executed with the no-wait option.}
  19.   {General}
  20.   ADAPTER_RESET= $32;
  21.   CANCEL = $35;
  22.   ADAPTER_STATUS = $33;
  23.   ADAPTER_STATUS_NO_WAIT = $B3;
  24.   {Remote boot support}
  25.   UNLINK = $70;
  26.   {Name support}
  27.   ADD_NAME = $30;
  28.   ADD_NAME_NO_WAIT = $B0;
  29.   ADD_GROUP_NAME = $36;
  30.   ADD_GROUP_NAME_NO_WAIT = $B6;
  31.   DELETE_NAME = $31;
  32.   DELETE_NAME_NO_WAIT = $B1;
  33.   {Session support}
  34.   CALL = $10;
  35.   CALL_NO_WAIT = $90;
  36.   LISTEN = $11;
  37.   LISTEN_NO_WAIT = $91;
  38.   HANG_UP = $12;
  39.   HANG_UP_NO_WAIT = $92;
  40.   SEND = $14;
  41.   SEND_NO_WAIT = $94;
  42.   CHAIN_SEND = $17;
  43.   CHAIN_SEND_NO_WAIT = $97;
  44.   RECEIVE = $15;
  45.   RECEIVE_NO_WAIT = $95;
  46.   RECEIVE_ANY = $16;
  47.   RECEIVE_ANY_NO_WAIT = $96;
  48.   SESSION_STATUS = $34;
  49.   SESSION_STATUS_NO_WAIT = $B4;
  50.   {Datagram support}
  51.   SEND_DATAGRAM = $20;
  52.   SEND_DATAGRAM_NO_WAIT = $A0;
  53.   SEND_BROADCAST_DATAGRAM = $22;
  54.   SEND_BROADCAST_DATAGRAM_NO_WAIT = $A2;
  55.   RECEIVE_DATAGRAM = $21;
  56.   RECEIVE_DATAGRAM_NO_WAIT = $A1;
  57.   RECEIVE_BROADCAST_DATAGRAM = $23;
  58.   RECEIVE_BROADCAST_DATAGRAM_NO_WAIT = $A3;
  59.   INTENTIONAL_BAD_COMMAND = $7F;
  60.  
  61. const {Return codes}
  62.   GOOD_RTN = $00;           {Good return}
  63.   ILL_LENGTH = $01;         {Bad length field}
  64.   INVALID_CMD = $03;        {Bad command number}
  65.   TIMEOUT = $05;            {Operation timed out}
  66.   MSG_INCOMPLETE = $06;     {Not enough space for message}
  67.   ILL_SESSION = $08;        {Session number was invalid}
  68.   NOT_AVAIL = $09;          {Adapter out of memory}
  69.   SESSION_CLOSED = $0A;     {Session closed successfully}
  70.   CMD_CANCELLED = $0B;      {Command cancelled successfully}
  71.   DUP_NAME = $0D;           {Name already in local table}
  72.   NAME_TABLE_FULL = $0E;    {Name table is full}
  73.   NAME_STILL_ACTIVE = $0F;  {Name deregistered but has active sessions}
  74.   SESSION_TABLE_FULL = $11; {No more sessions allowed}
  75.   OPEN_REJECTED = $12;      {No LISTEN pending on remote}
  76.   ILL_NAME_NUMBER = $13;    {Name number must match name}
  77.   NO_ANSWER = $14;          {Call not answered}
  78.   ILL_NAME = $15;           {Name not found or illegal}
  79.   NAME_IN_USE = $16;        {Name in use on network}
  80.   NAME_DELETED = $17;       {Name successfully deleted}
  81.   SESSION_ABEND = $18;      {Session ended abnormally}
  82.   NAME_CONFLICT = $19;      {Two names on the net are identical}
  83.   ILL_PACKET = $1A;         {Packet protocol not recognized}
  84.   BUSY = $21;               {BIOS re-entrancy error}
  85.   TOO_MANY_CMDS = $22;      {Too many commands outstanding}
  86.   INVALID_ADAPTER = $23;    {Invalid number for LAN adapter}
  87.   CMPL_DURING_CANCEL = $24; {Command completed before it could be cancelled}
  88.   CANNOT_CANCEL = $26;      {Command cannot be cancelled}
  89.   COMMAND_PENDING = $FF;    {Command is pending}
  90.  
  91. type
  92.   AdapterNum = 0..1; {Legal adapter number}
  93.   NetName = array [1..16] of Char; {Format of a name used in net operations}
  94.   {The following variant record supports the use of the
  95.    callName field of an NCB for either a network name or
  96.    buffer chaining.}
  97.   NameOrBufInfo = record
  98.     case Boolean of
  99.       FALSE: (name : NetName);       {Network name}
  100.       TRUE:  (nextBufLen : Word;     {Length of next buffer in a chain}
  101.               nextBufPtr : Pointer)  {Pointer to next buffer in a chain}
  102.       end;
  103.   NCB = record
  104.     command,          {NetBIOS command}
  105.     retcode,          {Return code}
  106.     lsn,              {Local session number}
  107.     num : Byte;       {Number of a local name}
  108.     bufPtr : Pointer; {Pointer to message buffer}
  109.     len : Word;       {Message buffer length}
  110.     callName:         {Destination name or info about second}
  111.       NameOrBufInfo;  {buffer in a CHAIN SEND)}
  112.     name : NetName;   {Source (local) name}
  113.     rto,              {Receive timeout in half seconds}
  114.     sto : Byte;       {Send timeout in half seconds}
  115.     post : Pointer;   {Interrrupt completion routine address}
  116.     lana_num : AdapterNum; {Number of LAN adapter}
  117.     cmd_cplt : Byte;  {Command complete flag}
  118.     reserved : array [1..14] of Byte {Internal use only}
  119.     end;
  120.  
  121.  
  122. const
  123.   {Masks for jumpers field of StatusBuf record}
  124.   W1 = $40; {Mask for W1 jumper on IBM net adapter card (Remote Boot)}
  125.   W2 = $80; {Mask for W2 jumper on IBM net adapter card (Reserved)}
  126.  
  127.   NAME_STATUS_MASK = $07; {Mask for reg status of name. Apply to status field
  128.                            of a LocalName record after ADAPTER_STATUS call}
  129.   NAME_PENDING_REG = 1;   {Registration pending}
  130.   NAME_REGISTERED = 4;    {Name is registered}
  131.   NAME_DEREGISTERED = 5;  {Name now deregistered}
  132.   NAME_DUPLICATED = 6;    {Name was found to be a duplicate}
  133.   NAME_DUP_PENDING_DEREG = 7; {Duplicate name now being deregistered}
  134.  
  135.   NAME_GROUP_MASK = $80;  {Mask for group/local bit. Apply to status field
  136.                            of a LocalName record after ADAPTER_STATUS call}
  137.  
  138. type
  139.   LocalName = record
  140.     name : NetName; {The name itself}
  141.     num,            {The number of the name}
  142.     status : Byte;  {Status of name. See constants above.}
  143.     end;
  144.   StatusBuf = record
  145.     unitID : array [1..6] of Byte; {Unique ID of hardware board}
  146.     jumpers,                       {Reflects jumper settings for W1 and W2}
  147.     postResult,                    {Result byte from adapter POST}
  148.     majorVersion,                  {Software version number}
  149.     minorVersion : Byte;
  150.     period,                        {Error reporting period in minutes}
  151.     crcErrors,                     {CRC errors found}
  152.     alignErrors,                   {Alignment errors found}
  153.     collisions,                    {Collisions found}
  154.     aborts : Word;                 {Aborted transmissions}
  155.     succXmt, succRcv : Longint;    {Successful transmissions and receptions}
  156.     reXmts,                        {Retransmissions}
  157.     overruns : Word;               {Adapter buffer overruns}
  158.     reserved : array [1..8] of Byte; {For internal use}
  159.     freeNCBs,                      {How many more NCBs can there be?}
  160.     configMaxNCBs,                 {Configured max NCBs}
  161.     maxNCBs : Word;                {Actual max NCBs}
  162.     reserved2 : array [1..4] of Byte;
  163.     sessions,                      {How many sessions in progress or pending}
  164.     configMaxSessions,             {Configured max sessions}
  165.     maxSessions,                   {Actual max sessions}
  166.     maxSessionPacketSize : Word;   {Max size of packet sent during a session}
  167.     nameCount : Word;              {Number of local names}
  168.     localNames : array [1..16] of LocalName {Local name table}
  169.     end;
  170.  
  171. procedure InitNCB(var n : NCB);
  172.   {Initialize an NCB by filling it with zeroes}
  173.  
  174. function NetPresent: Boolean;
  175.   {Determine if the NETBIOS (or an emulation thereof) is present}
  176.  
  177. function NetBIOS(var n : NCB) : Byte;
  178.   {Call the NetBIOS with the given NCB. The function returns the
  179.    same value that appears in the retCode field of the NCB after
  180.    the call. Note that commands issued with the no-wait option and
  181.    no interrupt completion routine will return their final result
  182.    codes in the cmd_cplt field. A Turbo Pascal inline procedure is
  183.    used here to generate efficient code.}
  184.   inline($5B                   {pop bx}
  185.         /$07                   {pop es}
  186.         /$CD/$5C               {int $5C}
  187.   );
  188.  
  189. procedure CallNetBIOS(var n : NCB);
  190.   {Call the NetBIOS with the given NCB. All return codes must
  191.    be read from the NCB when using this procedure.}
  192.   inline($5B                   {pop bx}
  193.         /$07                   {pop es}
  194.         /$CD/$5C               {int $5C}
  195.   );
  196.  
  197. implementation
  198.  
  199. procedure InitNCB(var n : NCB);
  200.   begin {InitNCB}
  201.   FillChar(n,SizeOf(n),0)
  202.   end;  {InitNCB}
  203.  
  204. function NetPresent : Boolean;
  205.   var
  206.     netBlock : NCB;
  207.     netVec : Pointer absolute $0000:$0170;
  208.   begin {NetPresent}
  209.   NetPresent := FALSE;
  210.   if netVec = NIL then {Network can't be there if vector is all zeroes}
  211.     Exit;
  212.   InitNCB(netBlock);
  213.   with netBlock do
  214.     begin
  215.     command := INTENTIONAL_BAD_COMMAND;
  216.     CallNetBios(netBlock);
  217.     NetPresent := (retCode = INVALID_CMD) {Net must recognize a bad command}
  218.     end
  219.   end;  {NetPresent}
  220. end.
  221.