' ########################################################################################
' Microsoft Windows
' File: Nb30.inc
' Contents: Definitions for portable NetBIOS 3.0 support.
' Copyright (c) 2011 Jos? Roca
' Portions Copyright (c) Microsoft Corporation.
' All Rights Reserved.
' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
' EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
' MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
' ########################################################################################
#IF NOT %DEF(PBX_Nb30_PBI)
#DEFINE PBX_Nb30_PBI
%EQUATE `NB30_INC = 1
'/****************************************************************
' * *
' * Data structure templates *
' * *
' ****************************************************************/
%EQUATE `NCBNAMSZ = 16 ' absolute length of a net name
%EQUATE `MAX_LANA = 254 ' lana's in range 0 to MAX_LANA
'/*
' * Network Control Block
' */
' // Size = 64 bytes
TYPE NCB BYTE
 ncb_command AS BYTE ' UCHAR ncb_command; /* command code */
 ncb_retcode AS BYTE ' UCHAR ncb_retcode; /* return code */
 ncb_lsn AS BYTE ' UCHAR ncb_lsn; /* local session number */
 ncb_num AS BYTE ' UCHAR ncb_num; /* number of our network name */
 ncb_buffer AS BYTE PTR ' PUCHAR ncb_buffer; /* address of message buffer */
 ncb_length AS WORD ' WORD ncb_length; /* size of message buffer */
 ncb_callname AS STRING * %NCBNAMSZ ' UCHAR ncb_callname[NCBNAMSZ]; /* blank-padded name of remote */
 ncb_name AS STRING * %NCBNAMSZ ' UCHAR ncb_name[NCBNAMSZ]; /* our blank-padded netname */
 ncb_rto AS BYTE ' UCHAR ncb_rto; /* rcv timeout/retry count */
 ncb_sto AS BYTE ' UCHAR ncb_sto; /* send timeout/sys timeout */
 ncb_post AS DWORD ' void (CALLBACK *ncb_post)( struct _NCB * ); /* POST routine address */
 ncb_lana_num AS BYTE ' UCHAR ncb_lana_num; /* lana (adapter) number */
 ncb_cmd_cplt AS BYTE ' UCHAR ncb_cmd_cplt; /* 0xff => commmand pending */
'#IF %DEF(%WIN64)
' ncb_reserve(17) AS BYTE ' UCHAR ncb_reserve[18]; /* reserved, used by BIOS */
'#ELSE
 ncb_reserve(9) AS BYTE ' UCHAR ncb_reserve[10]; /* reserved, used by BIOS */
'#ENDIF
 ncb_event AS DWORD ' HANDLE ncb_event; /* HANDLE to Win32 event which */
 ' /* will be set to the signalled */
 ' /* state when an ASYNCH command completes */
END TYPE
'/*
' * Structure returned to the NCB command NCBASTAT is ADAPTER_STATUS followed
' * by an array of NAME_BUFFER structures.
' */
UNION ADAPTER_STATUS_ADAPTER_ADDRESS_UNION
 adapter_address(5) AS BYTE ' UCHAR adapter_address[6]
 ' // For compatibiloity with PB includes
 adapter_address AS STRING * 6
END UNION
' // Size = 60 bytes
TYPE ADAPTER_STATUS BYTE
 ADAPTER_STATUS_ADAPTER_ADDRESS_UNION
 rev_major AS BYTE ' UCHAR
 reserved0 AS BYTE ' UCHAR
 adapter_type AS BYTE ' UCHAR
 rev_minor AS BYTE ' UCHAR
 duration AS WORD ' WORD
 frmr_recv AS WORD ' WORD
 frmr_xmit AS WORD ' WORD
 iframe_recv_err AS WORD ' WORD
 xmit_aborts AS WORD ' WORD
 xmit_success AS DWORD
 recv_success AS DWORD
 iframe_xmit_err AS WORD ' WORD
 recv_buff_unavail AS WORD ' WORD
 t1_timeouts AS WORD ' WORD
 ti_timeouts AS WORD ' WORD
 reserved1 AS DWORD
 free_ncbs AS WORD ' WORD
 max_cfg_ncbs AS WORD ' WORD
 max_ncbs AS WORD ' WORD
 xmit_buf_unavail AS WORD ' WORD
 max_dgram_size AS WORD ' WORD
 pending_sess AS WORD ' WORD
 max_cfg_sess AS WORD ' WORD
 max_sess AS WORD ' WORD
 max_sess_pkt_size AS WORD ' WORD
 name_count AS WORD ' WORD
END TYPE
UNION NAME_BUFFER_NAME_UNION BYTE
 name AS STRING * %NCBNAMSZ ' UCHAR name[NCBNAMSZ]
 ' // For compatibility with PB includes
 sname AS STRING * %NCBNAMSZ ' UCHAR name[NCBNAMSZ]
END UNION
' // Size = 18 bytes
TYPE NAME_BUFFER BYTE
 NAME_BUFFER_NAME_UNION
 name_num AS BYTE ' UCHAR name_num
 name_flags AS BYTE ' UCHAR name_flags
END TYPE
'// values for name_flags bits.
%EQUATE `NAME_FLAGS_MASK = &H87
%EQUATE `GROUP_NAME = &H80
%EQUATE `UNIQUE_NAME = &H00
%EQUATE `REGISTERING = &H00
%EQUATE `REGISTERED = &H04
%EQUATE `DEREGISTERED = &H05
%EQUATE `DUPLICATE = &H06
%EQUATE `DUPLICATE_DEREG = &H07
'/*
' * Structure returned to the NCB command NCBSSTAT is SESSION_HEADER followed
' * by an array of SESSION_BUFFER structures. If the NCB_NAME starts with an
' * asterisk then an array of these structures is returned containing the
' * status for all names.
' */
' // Size = 4 bytes
TYPE SESSION_HEADER BYTE
 sess_name AS BYTE ' UCHAR
 num_sess AS BYTE ' UCHAR
 rcv_dg_outstanding AS BYTE ' UCHAR
 rcv_any_outstanding AS BYTE ' UCHAR
END TYPE
' // Size = 36 bytes
TYPE SESSION_BUFFER BYTE
 lsn AS BYTE ' UCHAR lsn
 state AS BYTE ' UCHAR state
 local_name AS STRING * %NCBNAMSZ ' UCHAR local_name[NCBNAMSZ]
 remote_name AS STRING * %NCBNAMSZ ' UCHAR remote_name[NCBNAMSZ]
 rcvs_outstanding AS BYTE ' UCHAR rcvs_outstanding
 sends_outstanding AS BYTE ' UCHAR sends_outstanding
END TYPE
'// Values for state
%EQUATE `LISTEN_OUTSTANDING = &H01
%EQUATE `CALL_PENDING = &H02
%EQUATE `SESSION_ESTABLISHED = &H03
%EQUATE `HANGUP_PENDING = &H04
%EQUATE `HANGUP_COMPLETE = &H05
%EQUATE `SESSION_ABORTED = &H06
'/*
' * Structure returned to the NCB command NCBENUM.
' *
' * On a system containing lana's 0, 2 and 3, a structure with
' * length =3, lana[0]=0, lana[1]=2 and lana[2]=3 will be returned.
' */
' // Size = 256 bytes
TYPE LANA_ENUM BYTE
 length AS BYTE ' UCHAR length
 lana(%MAX_LANA) AS BYTE ' UCHAR lana[MAX_LANA+1]
END TYPE
'/*
' * Structure returned to the NCB command NCBFINDNAME is followed
' * by an array of FIND_NAME_BUFFER structures.
' */
' // Size = 4 bytes
TYPE FIND_NAME_HEADER BYTE
 node_count AS WORD ' WORD ' // Note: In the PB includes it is wrongly declared as DWORD
 reserved AS BYTE ' UCHAR
 unique_group AS BYTE ' UCHAR
END TYPE
UNION FIND_NAME_BUFFER_UNION
 destination_addr(5) AS BYTE ' UCHAR destination_addr[6]
 source_addr(5) AS BYTE ' UCHAR source_addr[6]
 routing_info(17) AS BYTE ' UCHAR routing_info[18]
 ' // For compatibility with the PB includes
 destination_addr AS STRING * 6
 source_addr AS STRING * 6
 routing_info AS STRING * 18
END UNION
' // Size = 33 bytes
TYPE FIND_NAME_BUFFER BYTE
 length AS BYTE ' UCHAR length
 access_control AS BYTE ' UCHAR access_control
 frame_control AS BYTE ' UCHAR frame_control
 FIND_NAME_BUFFER_UNION
END TYPE
'/*
' * Structure provided with NCBACTION. The purpose of NCBACTION is to provide
' * transport specific extensions to netbios.
' */
' // Size = 8 bytes
TYPE ACTION_HEADER BYTE
 transport_id AS DWORD ' ULONG
 action_code AS WORD ' USHORT
 reserved AS WORD ' USHORT
END TYPE
'// Values for transport_id
'#define ALL_TRANSPORTS "M\0\0\0"
'#define MS_NBF "MNBF"
$ALL_TRANSPORTS = "M" & CHR$(0,0,0) ' // Declared as $ALL_TRANSPORTS = "M\0\0\0" in the PB includes
$MS_NBF = "MNBF"
'/****************************************************************
' * *
' * Special values and constants *
' * *
' ****************************************************************/
'/*
' * NCB Command codes
' */
%EQUATE `NCBCALL = &H10 ' NCB CALL
%EQUATE `NCBLISTEN = &H11 ' NCB LISTEN
%EQUATE `NCBHANGUP = &H12 ' NCB HANG UP
%EQUATE `NCBSEND = &H14 ' NCB SEND
%EQUATE `NCBRECV = &H15 ' NCB RECEIVE
%EQUATE `NCBRECVANY = &H16 ' NCB RECEIVE ANY
%EQUATE `NCBCHAINSEND = &H17 ' NCB CHAIN SEND
%EQUATE `NCBDGSEND = &H20 ' NCB SEND DATAGRAM
%EQUATE `NCBDGRECV = &H21 ' NCB RECEIVE DATAGRAM
%EQUATE `NCBDGSENDBC = &H22 ' NCB SEND BROADCAST DATAGRAM
%EQUATE `NCBDGRECVBC = &H23 ' NCB RECEIVE BROADCAST DATAGRAM
%EQUATE `NCBADDNAME = &H30 ' NCB ADD NAME
%EQUATE `NCBDELNAME = &H31 ' NCB DELETE NAME
%EQUATE `NCBRESET = &H32 ' NCB RESET
%EQUATE `NCBASTAT = &H33 ' NCB ADAPTER STATUS
%EQUATE `NCBSSTAT = &H34 ' NCB SESSION STATUS
%EQUATE `NCBCANCEL = &H35 ' NCB CANCEL
%EQUATE `NCBADDGRNAME = &H36 ' NCB ADD GROUP NAME
%EQUATE `NCBENUM = &H37 ' NCB ENUMERATE LANA NUMBERS
%EQUATE `NCBUNLINK = &H70 ' NCB UNLINK
%EQUATE `NCBSENDNA = &H71 ' NCB SEND NO ACK
%EQUATE `NCBCHAINSENDNA = &H72 ' NCB CHAIN SEND NO ACK
%EQUATE `NCBLANSTALERT = &H73 ' NCB LAN STATUS ALERT
%EQUATE `NCBACTION = &H77 ' NCB ACTION
%EQUATE `NCBFINDNAME = &H78 ' NCB FIND NAME
%EQUATE `NCBTRACE = &H79 ' NCB TRACE
'#define ASYNCH 0x80 /* high bit set == asynchronous */
%EQUATE `ASYNCH = &H80 ' high bit set == asynchronous
'/*
' * NCB Return codes
' */
%EQUATE `NRC_GOODRET = &H00 ' good return
 ' also returned when ASYNCH request accepted
%EQUATE `NRC_BUFLEN = &H01 ' illegal buffer length
%EQUATE `NRC_ILLCMD = &H03 ' illegal command
%EQUATE `NRC_CMDTMO = &H05 ' command timed out
%EQUATE `NRC_INCOMP = &H06 ' message incomplete, issue another command
%EQUATE `NRC_BADDR = &H07 ' illegal buffer address
%EQUATE `NRC_SNUMOUT = &H08 ' session number out of range
%EQUATE `NRC_NORES = &H09 ' no resource available
%EQUATE `NRC_SCLOSED = &H0A ' session closed
%EQUATE `NRC_CMDCAN = &H0B ' command cancelled
%EQUATE `NRC_DUPNAME = &H0D ' duplicate name
%EQUATE `NRC_NAMTFUL = &H0E ' name table full
%EQUATE `NRC_ACTSES = &H0F ' no deletions, name has active sessions
%EQUATE `NRC_LOCTFUL = &H11 ' local session table full
%EQUATE `NRC_REMTFUL = &H12 ' remote session table full
%EQUATE `NRC_ILLNN = &H13 ' illegal name number
%EQUATE `NRC_NOCALL = &H14 ' no callname
%EQUATE `NRC_NOWILD = &H15 ' cannot put in NCB_NAME
%EQUATE `NRC_INUSE = &H16 ' name in use on remote adapter
%EQUATE `NRC_NAMERR = &H17 ' name deleted
%EQUATE `NRC_SABORT = &H18 ' session ended abnormally
%EQUATE `NRC_NAMCONF = &H19 ' name conflict detected
%EQUATE `NRC_IFBUSY = &H21 ' interface busy, IRET before retrying
%EQUATE `NRC_TOOMANY = &H22 ' too many commands outstanding, retry later
%EQUATE `NRC_BRIDGE = &H23 ' ncb_lana_num field invalid
%EQUATE `NRC_CANOCCR = &H24 ' command completed while cancel occurring
%EQUATE `NRC_CANCEL = &H26 ' command not valid to cancel
%EQUATE `NRC_DUPENV = &H30 ' name defined by anther local process
%EQUATE `NRC_ENVNOTDEF = &H34 ' environment undefined. RESET required
%EQUATE `NRC_OSRESNOTAV = &H35 ' required OS resources exhausted
%EQUATE `NRC_MAXAPPS = &H36 ' max number of applications exceeded
%EQUATE `NRC_NOSAPS = &H37 ' no saps available for netbios
%EQUATE `NRC_NORESOURCES = &H38 ' requested resources are not available
%EQUATE `NRC_INVADDRESS = &H39 ' invalid ncb address or length > segment
%EQUATE `NRC_INVDDID = &H3B ' invalid NCB DDID
%EQUATE `NRC_LOCKFAIL = &H3C ' lock of user area failed
%EQUATE `NRC_OPENERR = &H3F ' NETBIOS not loaded
%EQUATE `NRC_SYSTEM = &H40 ' system error
%EQUATE `NRC_PENDING = &HFF ' asynchronous command is not yet finished
'/****************************************************************
' * *
' * main user entry point for NetBIOS 3.0 *
' * *
' * Usage: result = Netbios( pncb ); *
' ****************************************************************/
DECLARE FUNCTION Netbios LIB "netapi32.dll" ALIAS "Netbios" ( BYREF pncb AS NCB ) AS BYTE ' UCHAR
'/****************************************************************
' * *
' * Prefix for callback routines *
' * *
' * Usage in a declaration: NCB_POST MyPostRoutine( PNCB pncb ); *
' ****************************************************************/
'#define NCB_POST void CALLBACK
#ENDIF
