Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

500 lines
12 KiB

  1. /*++
  2. Copyright (c) 1993 Microsoft Corporation
  3. Module Name:
  4. vwdll.c
  5. Abstract:
  6. ntVdm netWare (Vw) IPX/SPX Functions
  7. Vw: The peoples' network
  8. VDD functions for DOS/WOW IPX/SPX support
  9. Contents:
  10. VwDllEntryPoint
  11. VwInitialize
  12. VWinInitialize
  13. VwDispatcher
  14. VwInvalidFunction
  15. Author:
  16. Richard L Firth (rfirth) 30-Sep-1993
  17. Environment:
  18. User-mode Win32
  19. Revision History:
  20. 30-Sep-1993 rfirth
  21. Created
  22. --*/
  23. #include "vw.h"
  24. #pragma hdrstop
  25. #include <overflow.h>
  26. //
  27. // private prototypes
  28. //
  29. PRIVATE
  30. VOID
  31. VwInvalidFunction(
  32. VOID
  33. );
  34. //
  35. // private data
  36. //
  37. PRIVATE
  38. VOID
  39. (*VwDispatchTable[])(VOID) = {
  40. VwIPXOpenSocket, // 0x00
  41. VwIPXCloseSocket, // 0x01
  42. VwIPXGetLocalTarget, // 0x02
  43. VwIPXSendPacket, // 0x03
  44. VwIPXListenForPacket, // 0x04
  45. VwIPXScheduleIPXEvent, // 0x05
  46. VwIPXCancelEvent, // 0x06
  47. VwIPXScheduleAESEvent, // 0x07
  48. VwIPXGetIntervalMarker, // 0x08
  49. VwIPXGetInternetworkAddress, // 0x09
  50. VwIPXRelinquishControl, // 0x0A
  51. VwIPXDisconnectFromTarget, // 0x0B
  52. VwInvalidFunction, // 0x0C
  53. VwInvalidFunction, // 0x0D old-style GetMaxPacketSize
  54. VwInvalidFunction, // 0x0E
  55. VwInvalidFunction, // 0x0F internal send packet function
  56. VwSPXInitialize, // 0x10
  57. VwSPXEstablishConnection, // 0x11
  58. VwSPXListenForConnection, // 0x12
  59. VwSPXTerminateConnection, // 0x13
  60. VwSPXAbortConnection, // 0x14
  61. VwSPXGetConnectionStatus, // 0x15
  62. VwSPXSendSequencedPacket, // 0x16
  63. VwSPXListenForSequencedPacket, // 0x17
  64. VwInvalidFunction, // 0x18
  65. VwInvalidFunction, // 0x19
  66. VwIPXGetMaxPacketSize, // 0x1A
  67. VwInvalidFunction, // 0x1B
  68. VwInvalidFunction, // 0x1C
  69. VwInvalidFunction, // 0x1D
  70. VwInvalidFunction, // 0x1E
  71. VwIPXGetInformation, // 0x1F
  72. VwIPXSendWithChecksum, // 0x20
  73. VwIPXGenerateChecksum, // 0x21
  74. VwIPXVerifyChecksum // 0x22
  75. };
  76. #define MAX_IPXSPX_FUNCTION LAST_ELEMENT(VwDispatchTable)
  77. WSADATA WsaData = {0};
  78. HANDLE hAesThread = NULL;
  79. //
  80. // global data
  81. //
  82. SOCKADDR_IPX MyInternetAddress;
  83. WORD MyMaxPacketSize;
  84. int Ica;
  85. BYTE IcaLine;
  86. //
  87. // not-really-global data
  88. //
  89. extern CRITICAL_SECTION SerializationCritSec;
  90. extern CRITICAL_SECTION AsyncCritSec;
  91. //
  92. // functions
  93. //
  94. BOOL
  95. WINAPI
  96. VwDllEntryPoint(
  97. IN PVOID DllHandle,
  98. IN ULONG Reason,
  99. IN PCONTEXT Context OPTIONAL
  100. )
  101. /*++
  102. Routine Description:
  103. Called when the process attaches (LoadLibrary/init) and detaches (FreeLibrary/
  104. process termination) from this DLL
  105. Attach:
  106. initialize Winsock DLL
  107. get internet address for this station
  108. get maximum packet size supported by transport (IPX)
  109. create AES thread
  110. Detach:
  111. terminate Winsock DLL
  112. Arguments:
  113. DllHandle - unused
  114. Reason - checked for process attach/detach
  115. Context - unused
  116. Return Value:
  117. BOOLEAN
  118. --*/
  119. {
  120. DWORD aesThreadId; // unused outside of this function
  121. static BOOL CriticalSectionsAreInitialized = FALSE;
  122. UNREFERENCED_PARAMETER(DllHandle);
  123. UNREFERENCED_PARAMETER(Context);
  124. IPXDBGSTART();
  125. IPXDBGPRINT((__FILE__, __LINE__,
  126. FUNCTION_ANY,
  127. IPXDBG_LEVEL_INFO,
  128. "VwDllEntryPoint: %s\n",
  129. Reason == DLL_PROCESS_ATTACH ? "DLL_PROCESS_ATTACH"
  130. : Reason == DLL_PROCESS_DETACH ? "DLL_PROCESS_DETACH"
  131. : Reason == DLL_THREAD_ATTACH ? "DLL_THREAD_ATTACH"
  132. : Reason == DLL_THREAD_DETACH ? "DLL_THREAD_DETACH"
  133. : "?"
  134. ));
  135. if (Reason == DLL_PROCESS_ATTACH) {
  136. int err;
  137. //
  138. // TRACKING: get ICA values from new VDD service. Right now we grab
  139. // line 4 on the slave (base = 0x70, modifier = 0x03)
  140. //
  141. Ica = ICA_SLAVE;
  142. IcaLine = 3;
  143. err = WSAStartup(MAKEWORD(1, 1), &WsaData);
  144. if (err) {
  145. IPXDBGPRINT((__FILE__, __LINE__,
  146. FUNCTION_ANY,
  147. IPXDBG_LEVEL_FATAL,
  148. "VwDllEntryPoint: WSAStartup() returns %d\n",
  149. err
  150. ));
  151. return FALSE;
  152. } else {
  153. IPXDBGPRINT((__FILE__, __LINE__,
  154. FUNCTION_ANY,
  155. IPXDBG_LEVEL_INFO,
  156. "VwDllEntryPoint: WsaData:\n"
  157. "\twVersion : 0x%04x\n"
  158. "\twHighVersion : 0x%04x\n"
  159. "\tszDescription : \"%s\"\n"
  160. "\tszSystemStatus : \"%s\"\n"
  161. "\tiMaxSockets : %d\n"
  162. "\tiMaxUdpDg : %d\n"
  163. "\tlpVendorInfo : 0x%08x\n",
  164. WsaData.wVersion,
  165. WsaData.wHighVersion,
  166. WsaData.szDescription,
  167. WsaData.szSystemStatus,
  168. WsaData.iMaxSockets,
  169. WsaData.iMaxUdpDg,
  170. WsaData.lpVendorInfo
  171. ));
  172. }
  173. //
  174. // retrieve the internet address for this station. Used in
  175. // IPXGetInternetworkAddress() and IPXSendPacket()
  176. //
  177. err = GetInternetAddress(&MyInternetAddress);
  178. if (err) {
  179. IPXDBGPRINT((__FILE__, __LINE__,
  180. FUNCTION_ANY,
  181. IPXDBG_LEVEL_FATAL,
  182. "VwDllEntryPoint: GetInternetAddress() returns %d\n",
  183. WSAGetLastError()
  184. ));
  185. goto attach_error_exit;
  186. } else {
  187. IPXDBGPRINT((__FILE__, __LINE__,
  188. FUNCTION_ANY,
  189. IPXDBG_LEVEL_INFO,
  190. "VwDllEntryPoint: MyInternetAddress:\n"
  191. "\tNet : %02.2x-%02.2x-%02.2x-%02.2x\n"
  192. "\tNode : %02.2x-%02.2x-%02.2x-%02.2x-%02.2x-%02.2x\n",
  193. MyInternetAddress.sa_netnum[0] & 0xff,
  194. MyInternetAddress.sa_netnum[1] & 0xff,
  195. MyInternetAddress.sa_netnum[2] & 0xff,
  196. MyInternetAddress.sa_netnum[3] & 0xff,
  197. MyInternetAddress.sa_nodenum[0] & 0xff,
  198. MyInternetAddress.sa_nodenum[1] & 0xff,
  199. MyInternetAddress.sa_nodenum[2] & 0xff,
  200. MyInternetAddress.sa_nodenum[3] & 0xff,
  201. MyInternetAddress.sa_nodenum[4] & 0xff,
  202. MyInternetAddress.sa_nodenum[5] & 0xff
  203. ));
  204. }
  205. //
  206. // get the maximum packet size supported by IPX. Used in
  207. // IPXGetMaxPacketSize()
  208. //
  209. err = GetMaxPacketSize(&MyMaxPacketSize);
  210. if (err) {
  211. IPXDBGPRINT((__FILE__, __LINE__,
  212. FUNCTION_ANY,
  213. IPXDBG_LEVEL_FATAL,
  214. "VwDllEntryPoint: GetMaxPacketSize() returns %d\n",
  215. WSAGetLastError()
  216. ));
  217. goto attach_error_exit;
  218. } else {
  219. IPXDBGPRINT((__FILE__, __LINE__,
  220. FUNCTION_ANY,
  221. IPXDBG_LEVEL_INFO,
  222. "VwDllEntryPoint: GetMaxPacketSize: %04x (%d)\n",
  223. MyMaxPacketSize,
  224. MyMaxPacketSize
  225. ));
  226. }
  227. hAesThread = CreateThread(NULL,
  228. 0,
  229. (LPTHREAD_START_ROUTINE)VwAesThread,
  230. NULL,
  231. 0,
  232. &aesThreadId
  233. );
  234. if (hAesThread == NULL) {
  235. IPXDBGPRINT((__FILE__, __LINE__,
  236. FUNCTION_ANY,
  237. IPXDBG_LEVEL_FATAL,
  238. "VwDllEntryPoint: CreateThread() returns %d\n",
  239. GetLastError()
  240. ));
  241. goto attach_error_exit;
  242. }
  243. //
  244. // finally initialize any critical sections
  245. //
  246. InitializeCriticalSection(&SerializationCritSec);
  247. InitializeCriticalSection(&AsyncCritSec);
  248. CriticalSectionsAreInitialized = TRUE;
  249. } else if (Reason == DLL_PROCESS_DETACH) {
  250. if (hAesThread != NULL) {
  251. WaitForSingleObject(hAesThread, ONE_TICK * 2);
  252. CloseHandle(hAesThread);
  253. }
  254. WSACleanup();
  255. if (CriticalSectionsAreInitialized) {
  256. DeleteCriticalSection(&SerializationCritSec);
  257. DeleteCriticalSection(&AsyncCritSec);
  258. }
  259. IPXDBGEND();
  260. }
  261. return TRUE;
  262. attach_error_exit:
  263. //
  264. // here if any fatal errors on process attach after successfully performing
  265. // WSAStartup
  266. //
  267. WSACleanup();
  268. return FALSE;
  269. }
  270. BYTE
  271. VWinInitialize(
  272. VOID
  273. )
  274. /*++
  275. Routine Description:
  276. Called by interface when nwipxspx.dll is loaded. We
  277. return the IRQ value.
  278. Arguments:
  279. None.
  280. Return Value:
  281. The IRQ value.
  282. --*/
  283. {
  284. return 0x73;
  285. }
  286. VOID
  287. VwInitialize(
  288. VOID
  289. )
  290. /*++
  291. Routine Description:
  292. Called by VDD interface when DLL loaded via call to RegisterModule. We
  293. get the IRQ value and return it as an interrupt vector in BX
  294. Arguments:
  295. None.
  296. Return Value:
  297. None.
  298. --*/
  299. {
  300. IPXDBGPRINT((__FILE__, __LINE__,
  301. FUNCTION_ANY,
  302. IPXDBG_LEVEL_INFO,
  303. "VwInitialize\n"
  304. ));
  305. //
  306. // only lines on slave PIC are available. Currently, lines 3, 4 and 7 are
  307. // not used. We'll grab line 3 here, but in the future we expect a function
  308. // to return the available IRQ line
  309. //
  310. setBX( VWinInitialize() );
  311. }
  312. VOID
  313. VwDispatcher(
  314. VOID
  315. )
  316. /*++
  317. Routine Description:
  318. Branches to relevant IPX/SPX handler for DOS calls, based on contents of
  319. VDM BX register.
  320. Control transfered here from 16-bit entry point, either as result of call
  321. to far address returned from INT 2Fh/AH=7A or INT 7Ah
  322. Special: we use BX = 0xFFFF to indicate that the app is terminating. The
  323. TSR hooks INT 0x2F/AX=0x1122 (IFSResetEnvironment)
  324. Arguments:
  325. None.
  326. Return Value:
  327. None.
  328. --*/
  329. {
  330. DWORD dispatchIndex;
  331. dispatchIndex = (DWORD)getBX() & 0x7fff;
  332. if (dispatchIndex <= MAX_IPXSPX_FUNCTION) {
  333. VwDispatchTable[dispatchIndex]();
  334. } else if (dispatchIndex == 0x7FFE) {
  335. EsrCallback();
  336. } else if (dispatchIndex == 0x7FFF) {
  337. VwTerminateProgram();
  338. } else {
  339. IPXDBGPRINT((__FILE__, __LINE__,
  340. FUNCTION_ANY,
  341. IPXDBG_LEVEL_ERROR,
  342. "ERROR: VwDispatcher: dispatchIndex = %x\n",
  343. dispatchIndex
  344. ));
  345. setAX(ERROR_INVALID_FUNCTION);
  346. setCF(1);
  347. }
  348. }
  349. PRIVATE
  350. VOID
  351. VwInvalidFunction(
  352. VOID
  353. )
  354. /*++
  355. Routine Description:
  356. Just alerts us to the fact that an invalid function request was made.
  357. Useful if any app makes a bad call, or we miss out a required function
  358. during design/implementation
  359. Arguments:
  360. None.
  361. Return Value:
  362. None.
  363. --*/
  364. {
  365. IPXDBGPRINT((__FILE__, __LINE__,
  366. FUNCTION_ANY,
  367. IPXDBG_LEVEL_INFO,
  368. "VwInvalidFunction: BX=%04x\n",
  369. getBX()
  370. ));
  371. }