xref: /reactos/dll/win32/netapi32/netbios.h (revision c2c66aff)
1*c2c66affSColin Finck /* Copyright (c) 2003 Juan Lang
2*c2c66affSColin Finck  *
3*c2c66affSColin Finck  * This library is free software; you can redistribute it and/or
4*c2c66affSColin Finck  * modify it under the terms of the GNU Lesser General Public
5*c2c66affSColin Finck  * License as published by the Free Software Foundation; either
6*c2c66affSColin Finck  * version 2.1 of the License, or (at your option) any later version.
7*c2c66affSColin Finck  *
8*c2c66affSColin Finck  * This library is distributed in the hope that it will be useful,
9*c2c66affSColin Finck  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10*c2c66affSColin Finck  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11*c2c66affSColin Finck  * Lesser General Public License for more details.
12*c2c66affSColin Finck  *
13*c2c66affSColin Finck  * You should have received a copy of the GNU Lesser General Public
14*c2c66affSColin Finck  * License along with this library; if not, write to the Free Software
15*c2c66affSColin Finck  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
16*c2c66affSColin Finck  */
17*c2c66affSColin Finck #ifndef __WINE_NETBIOS_H__
18*c2c66affSColin Finck #define __WINE_NETBIOS_H__
19*c2c66affSColin Finck 
20*c2c66affSColin Finck /* This file describes the interface WINE's NetBIOS implementation uses to
21*c2c66affSColin Finck  * interact with a transport implementation (where a transport might be
22*c2c66affSColin Finck  * NetBIOS-over-TCP/IP (aka NetBT, NBT), NetBIOS-over-IPX, etc.)
23*c2c66affSColin Finck  */
24*c2c66affSColin Finck 
25*c2c66affSColin Finck /**
26*c2c66affSColin Finck  * Public functions
27*c2c66affSColin Finck  */
28*c2c66affSColin Finck 
29*c2c66affSColin Finck void NetBIOSInit(void) DECLSPEC_HIDDEN;
30*c2c66affSColin Finck void NetBIOSShutdown(void) DECLSPEC_HIDDEN;
31*c2c66affSColin Finck 
32*c2c66affSColin Finck struct _NetBIOSTransport;
33*c2c66affSColin Finck 
34*c2c66affSColin Finck /* A transport should register itself during its init function (see below) with
35*c2c66affSColin Finck  * a unique id (the transport_id of ACTION_HEADER, for example) and an
36*c2c66affSColin Finck  * implementation.  Returns TRUE on success, and FALSE on failure.
37*c2c66affSColin Finck  */
38*c2c66affSColin Finck BOOL NetBIOSRegisterTransport(ULONG id, struct _NetBIOSTransport *transport) DECLSPEC_HIDDEN;
39*c2c66affSColin Finck 
40*c2c66affSColin Finck /* Registers an adapter with the given transport and ifIndex with NetBIOS.
41*c2c66affSColin Finck  * ifIndex is an interface index usable by the IpHlpApi.  ifIndex is not
42*c2c66affSColin Finck  * required to be unique, but is required so that NetWkstaTransportEnum can use
43*c2c66affSColin Finck  * GetIfEntry to get the name and hardware address of the adapter.
44*c2c66affSColin Finck  * Returns TRUE on success, FALSE on failure.
45*c2c66affSColin Finck  * FIXME: need functions for retrieving the name and hardware index, rather
46*c2c66affSColin Finck  * than assuming a correlation with IpHlpApi.
47*c2c66affSColin Finck  */
48*c2c66affSColin Finck BOOL NetBIOSRegisterAdapter(ULONG transport, DWORD ifIndex, void *adapter) DECLSPEC_HIDDEN;
49*c2c66affSColin Finck 
50*c2c66affSColin Finck /* During enumeration, all adapters from your transport are disabled
51*c2c66affSColin Finck  * internally.  If an adapter is still valid, re-enable it with this function.
52*c2c66affSColin Finck  * Adapters you don't enable will have their transport's NetBIOSCleanupAdapter
53*c2c66affSColin Finck  * function (see below) called on them, and will be removed from the table.
54*c2c66affSColin Finck  * (This is to deal with lack of plug-and-play--sorry.)
55*c2c66affSColin Finck  */
56*c2c66affSColin Finck void NetBIOSEnableAdapter(UCHAR lana) DECLSPEC_HIDDEN;
57*c2c66affSColin Finck 
58*c2c66affSColin Finck /* Gets a quick count of the number of NetBIOS adapters.  Not guaranteed not
59*c2c66affSColin Finck  * to change from one call to the next, depending on what's been enumerated
60*c2c66affSColin Finck  * lately.  See also NetBIOSEnumAdapters.
61*c2c66affSColin Finck  */
62*c2c66affSColin Finck UCHAR NetBIOSNumAdapters(void) DECLSPEC_HIDDEN;
63*c2c66affSColin Finck 
64*c2c66affSColin Finck typedef struct _NetBIOSAdapterImpl {
65*c2c66affSColin Finck     UCHAR lana;
66*c2c66affSColin Finck     DWORD ifIndex;
67*c2c66affSColin Finck     void *data;
68*c2c66affSColin Finck } NetBIOSAdapterImpl;
69*c2c66affSColin Finck 
70*c2c66affSColin Finck typedef BOOL (*NetBIOSEnumAdaptersCallback)(UCHAR totalLANAs, UCHAR lanaIndex,
71*c2c66affSColin Finck  ULONG transport, const NetBIOSAdapterImpl *data, void *closure);
72*c2c66affSColin Finck 
73*c2c66affSColin Finck /* Enumerates all NetBIOS adapters for the transport transport, or for all
74*c2c66affSColin Finck  * transports if transport is ALL_TRANSPORTS.  Your callback will be called
75*c2c66affSColin Finck  * once for every enumerated adapter, with a count of how many adapters have
76*c2c66affSColin Finck  * been enumerated, a 0-based index relative to that count, the adapter's
77*c2c66affSColin Finck  * transport, and its ifIndex.
78*c2c66affSColin Finck  * Your callback should return FALSE if it no longer wishes to be called.
79*c2c66affSColin Finck  */
80*c2c66affSColin Finck void NetBIOSEnumAdapters(ULONG transport, NetBIOSEnumAdaptersCallback cb,
81*c2c66affSColin Finck  void *closure) DECLSPEC_HIDDEN;
82*c2c66affSColin Finck 
83*c2c66affSColin Finck /* Hangs up the session identified in the NCB; the NCB need not be a NCBHANGUP.
84*c2c66affSColin Finck  * Will result in the transport's hangup function being called, so release any
85*c2c66affSColin Finck  * locks you own before calling to avoid deadlock.
86*c2c66affSColin Finck  * This function is intended for use by a transport, if the session is closed
87*c2c66affSColin Finck  * by some error in the transport layer.
88*c2c66affSColin Finck  */
89*c2c66affSColin Finck void NetBIOSHangupSession(const NCB *ncb) DECLSPEC_HIDDEN;
90*c2c66affSColin Finck 
91*c2c66affSColin Finck /**
92*c2c66affSColin Finck  * Functions a transport implementation must implement
93*c2c66affSColin Finck  */
94*c2c66affSColin Finck 
95*c2c66affSColin Finck /* This function is called to ask a transport implementation to enumerate any
96*c2c66affSColin Finck  * LANAs into the NetBIOS adapter table by:
97*c2c66affSColin Finck  * - calling NetBIOSRegisterAdapter for any new adapters
98*c2c66affSColin Finck  * - calling NetBIOSEnableAdapter for any existing adapters
99*c2c66affSColin Finck  * NetBIOSEnumAdapters (see) may be of use to determine which adapters already
100*c2c66affSColin Finck  * exist.
101*c2c66affSColin Finck  * A transport can assume no other thread is modifying the NetBIOS adapter
102*c2c66affSColin Finck  * table during the lifetime of its NetBIOSEnum function (and, therefore, that
103*c2c66affSColin Finck  * this function won't be called reentrantly).
104*c2c66affSColin Finck  */
105*c2c66affSColin Finck typedef UCHAR (*NetBIOSEnum)(void);
106*c2c66affSColin Finck 
107*c2c66affSColin Finck /* A cleanup function for a transport.  This is the last function called on a
108*c2c66affSColin Finck  * transport.
109*c2c66affSColin Finck  */
110*c2c66affSColin Finck typedef void (*NetBIOSCleanup)(void);
111*c2c66affSColin Finck 
112*c2c66affSColin Finck /* Adapter functions */
113*c2c66affSColin Finck 
114*c2c66affSColin Finck /* Functions with direct mappings to the Netbios interface.  These functions
115*c2c66affSColin Finck  * are expected to be synchronous, although the first four bytes of the
116*c2c66affSColin Finck  * reserved member of the ncb are a cancel flag.  A long-running function
117*c2c66affSColin Finck  * should check whether this is not FALSE from time to time (see the
118*c2c66affSColin Finck  * NCB_CANCELLED macro), and return NRC_CMDCAN if it's been cancelled.  (The
119*c2c66affSColin Finck  * remainder of the NCB's reserved field is, well, reserved.)
120*c2c66affSColin Finck  */
121*c2c66affSColin Finck 
122*c2c66affSColin Finck /* Used to see whether the pointer to an NCB has been cancelled.  The NetBIOS
123*c2c66affSColin Finck  * interface designates certain functions as non-cancellable functions, but I
124*c2c66affSColin Finck  * use this flag for all NCBs.  Support it if you can.
125*c2c66affSColin Finck  * FIXME: this isn't enough, need to support an EVENT or some such, because
126*c2c66affSColin Finck  * some calls (recv) will block indefinitely, so a reset, shutdown, etc. will
127*c2c66affSColin Finck  * never occur.
128*c2c66affSColin Finck  */
129*c2c66affSColin Finck #define NCB_CANCELLED(pncb) *(const BOOL *)((pncb)->ncb_reserve)
130*c2c66affSColin Finck 
131*c2c66affSColin Finck typedef UCHAR (*NetBIOSAstat)(void *adapter, PNCB ncb);
132*c2c66affSColin Finck typedef UCHAR (*NetBIOSFindName)(void *adapter, PNCB ncb);
133*c2c66affSColin Finck 
134*c2c66affSColin Finck /* Functions to support the session service */
135*c2c66affSColin Finck 
136*c2c66affSColin Finck /* Implement to support the NCBCALL command.  If you need data stored for the
137*c2c66affSColin Finck  * session, return it in *session.  You can clean it up in your NetBIOSHangup
138*c2c66affSColin Finck  * function (see).
139*c2c66affSColin Finck  */
140*c2c66affSColin Finck typedef UCHAR (*NetBIOSCall)(void *adapter, PNCB ncb, void **session);
141*c2c66affSColin Finck typedef UCHAR (*NetBIOSSend)(void *adapter, void *session, PNCB ncb);
142*c2c66affSColin Finck typedef UCHAR (*NetBIOSRecv)(void *adapter, void *session, PNCB ncb);
143*c2c66affSColin Finck typedef UCHAR (*NetBIOSHangup)(void *adapter, void *session);
144*c2c66affSColin Finck 
145*c2c66affSColin Finck /* The last function called on an adapter; it is not called reentrantly, and
146*c2c66affSColin Finck  * no new calls will be made on the adapter once this has been entered.  Clean
147*c2c66affSColin Finck  * up any resources allocated for the adapter here.
148*c2c66affSColin Finck  */
149*c2c66affSColin Finck typedef void (*NetBIOSCleanupAdapter)(void *adapter);
150*c2c66affSColin Finck 
151*c2c66affSColin Finck typedef struct _NetBIOSTransport
152*c2c66affSColin Finck {
153*c2c66affSColin Finck     NetBIOSEnum           enumerate;
154*c2c66affSColin Finck     NetBIOSAstat          astat;
155*c2c66affSColin Finck     NetBIOSFindName       findName;
156*c2c66affSColin Finck     NetBIOSCall           call;
157*c2c66affSColin Finck     NetBIOSSend           send;
158*c2c66affSColin Finck     NetBIOSRecv           recv;
159*c2c66affSColin Finck     NetBIOSHangup         hangup;
160*c2c66affSColin Finck     NetBIOSCleanupAdapter cleanupAdapter;
161*c2c66affSColin Finck     NetBIOSCleanup        cleanup;
162*c2c66affSColin Finck } NetBIOSTransport;
163*c2c66affSColin Finck 
164*c2c66affSColin Finck /* Transport-specific functions.  When adding a transport, add a call to its
165*c2c66affSColin Finck  * init function in netapi32's DllMain.  The transport can do any global
166*c2c66affSColin Finck  * initialization it needs here.  It should call NetBIOSRegisterTransport to
167*c2c66affSColin Finck  * register itself with NetBIOS.
168*c2c66affSColin Finck  */
169*c2c66affSColin Finck 
170*c2c66affSColin Finck /* NetBIOS-over-TCP/IP (NetBT) functions */
171*c2c66affSColin Finck 
172*c2c66affSColin Finck /* Not defined by MS, so make my own private define: */
173*c2c66affSColin Finck #define TRANSPORT_NBT "MNBT"
174*c2c66affSColin Finck 
175*c2c66affSColin Finck void NetBTInit(void) DECLSPEC_HIDDEN;
176*c2c66affSColin Finck 
177*c2c66affSColin Finck #endif /* ndef __WINE_NETBIOS_H__ */
178