ReactOS  0.4.13-dev-66-gc714b7f
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.

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
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
unsigned long DWORD
Definition: ntddk_ex.h:95

Referenced by SvcNetBiosReset().

◆ SetLanaFlag()

VOID WINAPI SetLanaFlag ( _In_ UCHAR  Lana)

Definition at line 72 of file netbios.c.

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
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
unsigned long DWORD
Definition: ntddk_ex.h:95

Referenced by SvcNetBiosReset().

◆ SvcNetBiosClose()

VOID WINAPI SvcNetBiosClose ( VOID  )

Definition at line 96 of file netbios.c.

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)

Referenced by SvchostBuildSharedGlobals().

◆ SvcNetBiosInit()

VOID WINAPI SvcNetBiosInit ( VOID  )

Definition at line 84 of file netbios.c.

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

Referenced by SvchostBuildSharedGlobals().

◆ SvcNetBiosOpen()

VOID WINAPI SvcNetBiosOpen ( VOID  )

Definition at line 112 of file netbios.c.

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)

Referenced by SvchostBuildSharedGlobals().

◆ SvcNetBiosReset()

DWORD WINAPI SvcNetBiosReset ( _In_ UCHAR  LanaNum)

Definition at line 124 of file netbios.c.

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)

Referenced by SvchostBuildSharedGlobals().

◆ SvcNetBiosStatusToApiStatus()

DWORD WINAPI SvcNetBiosStatusToApiStatus ( _In_ DWORD  NetBiosError)

Definition at line 26 of file netbios.c.

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

Referenced by SvcNetBiosReset().

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.

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