ReactOS  0.4.11-dev-946-g431643b
netbios.c File Reference
#include "svchost.h"
#include <lmerr.h>
#include <nb30.h>
Include dependency graph for netbios.c:

Go to the source code of this file.

Functions

DWORD WINAPI SvcNetBiosStatusToApiStatus (_In_ DWORD NetBiosError)
 
BOOL WINAPI LanaFlagIsSet (_In_ UCHAR Lana)
 
VOID WINAPI SetLanaFlag (_In_ UCHAR Lana)
 
VOID WINAPI SvcNetBiosInit (VOID)
 
VOID WINAPI SvcNetBiosClose (VOID)
 
VOID WINAPI SvcNetBiosOpen (VOID)
 
DWORD WINAPI SvcNetBiosReset (_In_ UCHAR LanaNum)
 

Variables

LONG GlobalNetBiosUseCount
 
DWORD LanaFlags [8]
 
CRITICAL_SECTION SvcNetBiosCritSec
 

Function Documentation

◆ LanaFlagIsSet()

BOOL WINAPI LanaFlagIsSet ( _In_ UCHAR  Lana)

Definition at line 60 of file netbios.c.

Referenced by SvcNetBiosReset().

63 {
64  DWORD i = Lana / 32;
65 
66  /* Clear the flag for this LANA */
67  return (i <= 7) ? LanaFlags[i] & (1 << (Lana - 32 * i)) : FALSE;
68 }
DWORD LanaFlags[8]
Definition: netbios.c:19
GLenum GLclampf GLint i
Definition: glfuncs.h:14
unsigned long DWORD
Definition: ntddk_ex.h:95

◆ SetLanaFlag()

VOID WINAPI SetLanaFlag ( _In_ UCHAR  Lana)

Definition at line 72 of file netbios.c.

Referenced by SvcNetBiosReset().

75 {
76  DWORD i = Lana / 32;
77 
78  /* Set the flag for this LANA */
79  if (i <= 7) LanaFlags[i] |= 1 << (Lana - 32 * i);
80 }
DWORD LanaFlags[8]
Definition: netbios.c:19
GLenum GLclampf GLint i
Definition: glfuncs.h:14
unsigned long DWORD
Definition: ntddk_ex.h:95

◆ SvcNetBiosClose()

VOID WINAPI SvcNetBiosClose ( VOID  )

Definition at line 96 of file netbios.c.

Referenced by SvchostBuildSharedGlobals().

99 {
100  /* While holding the lock, drop a reference*/
102  if ((GlobalNetBiosUseCount != 0) && (--GlobalNetBiosUseCount == 0))
103  {
104  /* All references are gone, clear all LANA's */
105  ZeroMemory(LanaFlags, sizeof(LanaFlags));
106  }
108 }
DWORD LanaFlags[8]
Definition: netbios.c:19
#define ZeroMemory
Definition: winbase.h:1635
CRITICAL_SECTION SvcNetBiosCritSec
Definition: netbios.c:20
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
LONG GlobalNetBiosUseCount
Definition: netbios.c:18
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)

◆ SvcNetBiosInit()

VOID WINAPI SvcNetBiosInit ( VOID  )

Definition at line 84 of file netbios.c.

Referenced by SvchostBuildSharedGlobals().

87 {
88  /* Initialize NetBIOS-related structures and variables */
91  ZeroMemory(LanaFlags, sizeof(LanaFlags));
92 }
DWORD LanaFlags[8]
Definition: netbios.c:19
#define ZeroMemory
Definition: winbase.h:1635
CRITICAL_SECTION SvcNetBiosCritSec
Definition: netbios.c:20
VOID WINAPI InitializeCriticalSection(OUT LPCRITICAL_SECTION lpCriticalSection)
Definition: synch.c:697
LONG GlobalNetBiosUseCount
Definition: netbios.c:18

◆ SvcNetBiosOpen()

VOID WINAPI SvcNetBiosOpen ( VOID  )

Definition at line 112 of file netbios.c.

Referenced by SvchostBuildSharedGlobals().

115 {
116  /* Increment the reference counter while holding the lock */
120 }
CRITICAL_SECTION SvcNetBiosCritSec
Definition: netbios.c:20
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
LONG GlobalNetBiosUseCount
Definition: netbios.c:18
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)

◆ SvcNetBiosReset()

DWORD WINAPI SvcNetBiosReset ( _In_ UCHAR  LanaNum)

Definition at line 124 of file netbios.c.

Referenced by SvchostBuildSharedGlobals().

127 {
128  DWORD dwError = ERROR_SUCCESS;
129  UCHAR nbtError;
130  NCB ncb;
131 
132  /* Block all other NetBIOS operations */
134 
135  /* Is this LANA enabled? */
136  if (!LanaFlagIsSet(LanaNum))
137  {
138  /* Yep, build a reset packet */
139  ZeroMemory(&ncb, sizeof(ncb));
140  ncb.ncb_lsn = 0;
141  ncb.ncb_command = NCBRESET;
142  ncb.ncb_callname[0] = 0xFE; // Max Sessions
143  ncb.ncb_callname[1] = 0;
144  ncb.ncb_callname[2] = 0xFD; // Max Names
145  ncb.ncb_callname[3] = 0;
146  ncb.ncb_lana_num = LanaNum;
147 
148  /* Send it */
149  nbtError = Netbios(&ncb);
150 
151  /* Convert the status to Win32 format */
152  dwError = SvcNetBiosStatusToApiStatus(nbtError);
153 
154  /* Enable the LANA if the reset worked */
155  if (dwError == ERROR_SUCCESS) SetLanaFlag(LanaNum);
156  }
157 
158  /* Drop the lock and return */
160  return dwError;
161 }
#define ERROR_SUCCESS
Definition: deptool.c:10
UCHAR WINAPI Netbios(PNCB ncb)
Definition: netbios.c:785
UCHAR ncb_callname[NCBNAMSZ]
Definition: nb30.h:155
Definition: nb30.h:148
#define ZeroMemory
Definition: winbase.h:1635
CRITICAL_SECTION SvcNetBiosCritSec
Definition: netbios.c:20
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
VOID WINAPI SetLanaFlag(_In_ UCHAR Lana)
Definition: netbios.c:72
#define NCBRESET
Definition: nb30.h:38
unsigned long DWORD
Definition: ntddk_ex.h:95
unsigned char UCHAR
Definition: xmlstorage.h:181
BOOL WINAPI LanaFlagIsSet(_In_ UCHAR Lana)
Definition: netbios.c:60
UCHAR ncb_lana_num
Definition: nb30.h:160
DWORD WINAPI SvcNetBiosStatusToApiStatus(_In_ DWORD NetBiosError)
Definition: netbios.c:26
UCHAR ncb_lsn
Definition: nb30.h:151
UCHAR ncb_command
Definition: nb30.h:149
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)

◆ SvcNetBiosStatusToApiStatus()

DWORD WINAPI SvcNetBiosStatusToApiStatus ( _In_ DWORD  NetBiosError)

Definition at line 26 of file netbios.c.

Referenced by SvcNetBiosReset().

29 {
30  /* Convert from one status to another */
31  switch (NetBiosError)
32  {
33  case NRC_GOODRET:
34  return NERR_Success;
35  case NRC_INUSE:
36  case NRC_NAMCONF:
37  return NERR_DuplicateName;
38  case NRC_NOWILD:
39  case NRC_NAMERR:
41  case NRC_NOCALL:
42  return NERR_NameNotFound;
43  case NRC_NORES:
45  case NRC_DUPNAME:
46  return NERR_AlreadyExists;
47  case NRC_NAMTFUL:
48  return NERR_TooManyNames;
49  case NRC_ACTSES:
50  return NERR_DeleteLater;
51  case NRC_REMTFUL:
52  return ERROR_REM_NOT_LIST;
53  default:
54  return NERR_NetworkError;
55  }
56 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
#define NRC_GOODRET
Definition: nb30.h:52
#define NRC_NAMTFUL
Definition: nb30.h:63
#define NERR_NameNotFound
Definition: lmerr.h:123
#define ERROR_REM_NOT_LIST
Definition: winerror.h:143
#define NERR_DuplicateName
Definition: lmerr.h:142
#define NERR_Success
Definition: lmerr.h:5
#define NRC_NAMCONF
Definition: nb30.h:73
#define NERR_AlreadyExists
Definition: lmerr.h:126
#define NRC_REMTFUL
Definition: nb30.h:66
#define NRC_NAMERR
Definition: nb30.h:71
#define NRC_NOWILD
Definition: nb30.h:69
#define NRC_DUPNAME
Definition: nb30.h:62
#define NERR_DeleteLater
Definition: lmerr.h:143
#define NRC_INUSE
Definition: nb30.h:70
#define NRC_ACTSES
Definition: nb30.h:64
#define NERR_TooManyNames
Definition: lmerr.h:127
#define NERR_NoNetworkResource
Definition: lmerr.h:10
#define NRC_NORES
Definition: nb30.h:59
#define NRC_NOCALL
Definition: nb30.h:68
#define NERR_NetworkError
Definition: lmerr.h:24

Variable Documentation

◆ GlobalNetBiosUseCount

LONG GlobalNetBiosUseCount

Definition at line 18 of file netbios.c.

Referenced by SvcNetBiosClose(), SvcNetBiosInit(), and SvcNetBiosOpen().

◆ LanaFlags

DWORD LanaFlags[8]

Definition at line 19 of file netbios.c.

Referenced by LanaFlagIsSet(), SetLanaFlag(), SvcNetBiosClose(), and SvcNetBiosInit().

◆ SvcNetBiosCritSec

CRITICAL_SECTION SvcNetBiosCritSec

Definition at line 20 of file netbios.c.