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.

389 lines
7.4 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. init.c
  5. Abstract:
  6. Initialization and Termination routines for the ATMARP client.
  7. Revision History:
  8. Who When What
  9. -------- -------- ----------------------------------------------
  10. arvindm 08-09-96 Created
  11. Notes:
  12. --*/
  13. #include <precomp.h>
  14. #define _FILENUMBER 'TINI'
  15. VOID
  16. AtmArpInitGlobals(
  17. )
  18. /*++
  19. Routine Description:
  20. Initialize all our global data structures.
  21. Arguments:
  22. None
  23. Return Value:
  24. None
  25. --*/
  26. {
  27. AA_SET_MEM(pAtmArpGlobalInfo, 0, sizeof(ATMARP_GLOBALS));
  28. #if DBG
  29. pAtmArpGlobalInfo->aag_sig = aag_signature;
  30. #ifdef GPC
  31. pAtmArpGlobalInfo->aaq_sig = aaq_signature;
  32. #endif // GPC
  33. #endif // DBG
  34. AA_INIT_GLOBAL_LOCK(pAtmArpGlobalInfo);
  35. AA_INIT_BLOCK_STRUCT(&(pAtmArpGlobalInfo->Block));
  36. }
  37. NDIS_STATUS
  38. AtmArpInitIpOverAtm(
  39. IN PATMARP_INTERFACE pInterface
  40. )
  41. /*++
  42. Routine Description:
  43. Initialize IP/ATM data structures for the given interface.
  44. It is assumed that the configuration information for the interface
  45. has been read in.
  46. We allocate ATM Entries for the ARP servers, and the DHCP server,
  47. if configured.
  48. Arguments:
  49. pInterface - Pointer to ATMARP interface
  50. Return Value:
  51. NDIS_STATUS_SUCCESS if successful, NDIS_STATUS_RESOURCES if we
  52. aren't able to do the allocation necessary.
  53. --*/
  54. {
  55. PATMARP_SERVER_ENTRY pServerEntry;
  56. NDIS_STATUS Status;
  57. PATMARP_SERVER_LIST pServerList;
  58. //
  59. // Initialize.
  60. //
  61. Status = NDIS_STATUS_SUCCESS;
  62. do
  63. {
  64. #ifdef IPMCAST
  65. if (pInterface->ArpServerList.ListSize != 0)
  66. {
  67. //
  68. // Set the current ARP server to the first one in the list.
  69. //
  70. pInterface->pCurrentServer = pInterface->ArpServerList.pList;
  71. }
  72. if (pInterface->MARSList.ListSize != 0)
  73. {
  74. //
  75. // Set the current MARS server to the first one in the list.
  76. //
  77. pInterface->pCurrentMARS = pInterface->MARSList.pList;
  78. }
  79. for (pServerList = &(pInterface->ArpServerList);
  80. pServerList != NULL_PATMARP_SERVER_LIST;
  81. /* NONE -- see end of for loop */
  82. )
  83. {
  84. for (pServerEntry = pServerList->pList;
  85. pServerEntry != NULL_PATMARP_SERVER_ENTRY;
  86. pServerEntry = pServerEntry->pNext)
  87. {
  88. UCHAR AddrTypeLen;
  89. UCHAR SubaddrTypeLen;
  90. AddrTypeLen =
  91. AA_PKT_ATM_ADDRESS_TO_TYPE_LEN(&(pServerEntry->ATMAddress));
  92. if (pServerEntry->ATMSubaddress.NumberOfDigits > 0)
  93. {
  94. SubaddrTypeLen =
  95. AA_PKT_ATM_ADDRESS_TO_TYPE_LEN(&(pServerEntry->ATMSubaddress));
  96. }
  97. else
  98. {
  99. SubaddrTypeLen = 0;
  100. }
  101. pServerEntry->pAtmEntry =
  102. AtmArpSearchForAtmAddress(
  103. pInterface,
  104. AddrTypeLen,
  105. pServerEntry->ATMAddress.Address,
  106. SubaddrTypeLen,
  107. pServerEntry->ATMSubaddress.Address,
  108. AE_REFTYPE_IF,
  109. TRUE // Create new one if not found
  110. );
  111. if (pServerEntry->pAtmEntry == NULL_PATMARP_ATM_ENTRY)
  112. {
  113. //
  114. // Must be a resource failure.
  115. //
  116. Status = NDIS_STATUS_RESOURCES;
  117. break;
  118. }
  119. else
  120. {
  121. //
  122. // NOTE: AtmArpSearchForAtmAddress has alreaddy addrefd
  123. // the pAtmEntry for us.
  124. //
  125. }
  126. }
  127. //
  128. // Move to the next list of servers, if any.
  129. //
  130. if (pServerList == &(pInterface->MARSList))
  131. {
  132. //
  133. // We are done.
  134. //
  135. pServerList = NULL_PATMARP_SERVER_LIST;
  136. }
  137. else
  138. {
  139. //
  140. // We just finished with the ARP Server list. Now process
  141. // the MARS list.
  142. //
  143. pServerList = &(pInterface->MARSList);
  144. }
  145. }
  146. #else
  147. if (pInterface->ArpServerList.ListSize > 0)
  148. {
  149. //
  150. // Set the current ARP server to the first one in the list.
  151. //
  152. pInterface->pCurrentServer = pInterface->ArpServerList.pList;
  153. for (pServerEntry = pInterface->ArpServerList.pList;
  154. pServerEntry != NULL_PATMARP_SERVER_ENTRY;
  155. pServerEntry = pServerEntry->pNext)
  156. {
  157. UCHAR AddrTypeLen;
  158. UCHAR SubaddrTypeLen;
  159. AddrTypeLen =
  160. AA_PKT_ATM_ADDRESS_TO_TYPE_LEN(&(pServerEntry->ATMAddress));
  161. if (pServerEntry->ATMSubaddress.NumberOfDigits > 0)
  162. {
  163. SubaddrTypeLen =
  164. AA_PKT_ATM_ADDRESS_TO_TYPE_LEN(&(pServerEntry->ATMSubaddress));
  165. }
  166. else
  167. {
  168. SubaddrTypeLen = 0;
  169. }
  170. pServerEntry->pAtmEntry =
  171. AtmArpSearchForAtmAddress(
  172. pInterface,
  173. AddrTypeLen,
  174. pServerEntry->ATMAddress.Address,
  175. SubaddrTypeLen,
  176. pServerEntry->ATMSubaddress.Address,
  177. AE_REFTYPE_IF,
  178. TRUE // Create new one if not found
  179. );
  180. if (pServerEntry->pAtmEntry == NULL_PATMARP_ATM_ENTRY)
  181. {
  182. //
  183. // Must be a resource failure.
  184. //
  185. Status = NDIS_STATUS_RESOURCES;
  186. break;
  187. }
  188. else
  189. {
  190. //
  191. // NOTE: AtmArpSearchForAtmAddress has alreaddy addrefd
  192. // the pAtmEntry for us.
  193. //
  194. }
  195. }
  196. }
  197. #endif // IPMCAST
  198. if (Status != NDIS_STATUS_SUCCESS)
  199. {
  200. break;
  201. }
  202. #ifdef DHCP_OVER_ATM
  203. if (pInterface->DhcpEnabled)
  204. {
  205. UCHAR AddrTypeLen;
  206. AddrTypeLen = AA_PKT_ATM_ADDRESS_TO_TYPE_LEN(&(pInterface->DhcpServerAddress));
  207. pInterface->pDhcpServerAtmEntry =
  208. AtmArpSearchForAtmAddress(
  209. pInterface,
  210. AddrTypeLen,
  211. pInterface->DhcpServerAddress.Address,
  212. 0, // Subaddress type+len
  213. (PUCHAR)NULL, // Subaddress
  214. AE_REFTYPE_IF,
  215. TRUE // Create new one if not found
  216. );
  217. if (pInterface->pDhcpServerAtmEntry == NULL_PATMARP_ATM_ENTRY)
  218. {
  219. Status = NDIS_STATUS_RESOURCES;
  220. break;
  221. }
  222. else
  223. {
  224. //
  225. // NOTE: AtmArpSearchForAtmAddress has alreaddy addrefd
  226. // the pAtmEntry for us.
  227. //
  228. }
  229. }
  230. #endif // DHCP_OVER_ATM
  231. break;
  232. }
  233. while (FALSE);
  234. return (Status);
  235. }
  236. VOID
  237. AtmArpUnloadProtocol(
  238. VOID
  239. )
  240. /*++
  241. Routine Description:
  242. Unloads the ATMARP protocol module. We unbind from all adapters,
  243. and deregister from NDIS as a protocol.
  244. Arguments:
  245. None.
  246. Return Value:
  247. None
  248. --*/
  249. {
  250. NDIS_STATUS Status;
  251. PATMARP_ADAPTER pAdapter;
  252. #if DBG
  253. AADEBUGP(AAD_INFO, ("AtmArpUnloadProtocol entered\n"));
  254. #endif // DBG
  255. AA_ACQUIRE_GLOBAL_LOCK(pAtmArpGlobalInfo);
  256. if (pAtmArpGlobalInfo->bUnloading)
  257. {
  258. AA_RELEASE_GLOBAL_LOCK(pAtmArpGlobalInfo);
  259. return;
  260. }
  261. pAtmArpGlobalInfo->bUnloading = TRUE;
  262. #if 0
  263. //
  264. // Commented this out because we don't need to handle
  265. // the case of unclosed bindings ourselves. If there
  266. // are any at this time, then NDIS will call our Unbind
  267. // handlers for such bindings in response to our call
  268. // to NdisDeregisterProtocol below.
  269. //
  270. while (pAtmArpGlobalInfo->pAdapterList != NULL_PATMARP_ADAPTER)
  271. {
  272. pAdapter = pAtmArpGlobalInfo->pAdapterList;
  273. AA_RELEASE_GLOBAL_LOCK(pAtmArpGlobalInfo);
  274. AADEBUGP(AAD_INFO, ("UnloadProtocol: Will unbind adapter 0x%x\n", pAdapter));
  275. AtmArpUnbindAdapterHandler(
  276. &Status,
  277. (NDIS_HANDLE)pAdapter,
  278. (NDIS_HANDLE)NULL // No UnbindContext ==> Don't complete NdisUnbind
  279. );
  280. if (Status == NDIS_STATUS_PENDING)
  281. {
  282. //
  283. // Wait for the unbind to complete
  284. //
  285. (VOID)AA_WAIT_ON_BLOCK_STRUCT(&(pAtmArpGlobalInfo->Block));
  286. }
  287. AA_ACQUIRE_GLOBAL_LOCK(pAtmArpGlobalInfo);
  288. }
  289. #endif // 0
  290. AA_RELEASE_GLOBAL_LOCK(pAtmArpGlobalInfo);
  291. NdisDeregisterProtocol(
  292. &Status,
  293. pAtmArpGlobalInfo->ProtocolHandle
  294. );
  295. AA_FREE_GLOBAL_LOCK(pAtmArpGlobalInfo);
  296. AA_FREE_BLOCK_STRUCT(&(pAtmArpGlobalInfo->Block));
  297. #ifdef GPC
  298. AtmArpGpcShutdown();
  299. #endif // GPC
  300. #if DBG
  301. AaAuditShutdown();
  302. #endif // DBG
  303. AADEBUGP(AAD_LOUD,
  304. ("UnloadProtocol: will deregister protocol now, ProtHandle 0x%x\n",
  305. pAtmArpGlobalInfo->ProtocolHandle));
  306. AA_ASSERT(Status == NDIS_STATUS_SUCCESS);
  307. AADEBUGP(AAD_LOUD, ("UnloadProtocol done\n"));
  308. }