Source code of Windows XP (NT5)
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.

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