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.

319 lines
5.4 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. adptmgr.c
  5. Abstract:
  6. This module contains the adapter management functions
  7. Author:
  8. Stefan Solomon 12/02/1996
  9. Revision History:
  10. --*/
  11. #include "precomp.h"
  12. #pragma hdrstop
  13. #define ADAPTER_INDEX_HASH_TABLE_SIZE 32
  14. #define adpthashindex(AdapterIndex) (AdapterIndex) % ADAPTER_INDEX_HASH_TABLE_SIZE
  15. LIST_ENTRY AdapterHT[ADAPTER_INDEX_HASH_TABLE_SIZE];
  16. LIST_ENTRY DiscardedAdaptersList;
  17. HANDLE AdapterConfigPortHandle;
  18. VOID
  19. CreateAdapter(ULONG AdapterIndex,
  20. PADAPTER_INFO AdapterInfo);
  21. VOID
  22. DeleteAdapter(ULONG AdapterIndex);
  23. /*++
  24. Function: StartAdapterManager
  25. Descr: opens the IPX stack notification port for ipxwan
  26. --*/
  27. DWORD
  28. StartAdapterManager(VOID)
  29. {
  30. ADAPTERS_GLOBAL_PARAMETERS AdptGlobalParameters;
  31. DWORD rc, i;
  32. Trace(ADAPTER_TRACE, "StartAdapterManager: Entered\n");
  33. // create adapter config port
  34. if((AdapterConfigPortHandle = IpxWanCreateAdapterConfigurationPort(
  35. hWaitableObject[ADAPTER_NOTIFICATION_EVENT],
  36. &AdptGlobalParameters)) == INVALID_HANDLE_VALUE) {
  37. // can't create config port
  38. return ERROR_CAN_NOT_COMPLETE;
  39. }
  40. // create adapters hash table
  41. for(i=0; i<ADAPTER_INDEX_HASH_TABLE_SIZE; i++) {
  42. InitializeListHead(&AdapterHT[i]);
  43. }
  44. // create discarded adapters list
  45. InitializeListHead(&DiscardedAdaptersList);
  46. return NO_ERROR;
  47. }
  48. /*++
  49. Function: AddToAdapterHt
  50. Descr: Adds the adapter control block to the hash table of adapters
  51. Remark: >> called with database lock held <<
  52. --*/
  53. VOID
  54. AddToAdapterHt(PACB acbp)
  55. {
  56. int hv;
  57. PLIST_ENTRY lep;
  58. PACB list_acbp;
  59. // insert in index hash table
  60. hv = adpthashindex(acbp->AdapterIndex);
  61. InsertTailList(&AdapterHT[hv], &acbp->Linkage);
  62. }
  63. /*++
  64. Function: RemoveFromAdapterHt
  65. Descr:
  66. Remark: >> called with database lock held <<
  67. --*/
  68. VOID
  69. RemoveFromAdapterHt(PACB acbp)
  70. {
  71. RemoveEntryList(&acbp->Linkage);
  72. }
  73. /*++
  74. Function: GetAdapterByIndex
  75. Descr:
  76. Remark: >> called with database lock held <<
  77. --*/
  78. PACB
  79. GetAdapterByIndex(ULONG AdptIndex)
  80. {
  81. PACB acbp;
  82. PLIST_ENTRY lep;
  83. int hv;
  84. hv = adpthashindex(AdptIndex);
  85. lep = AdapterHT[hv].Flink;
  86. while(lep != &AdapterHT[hv])
  87. {
  88. acbp = CONTAINING_RECORD(lep, ACB, Linkage);
  89. if (acbp->AdapterIndex == AdptIndex) {
  90. return acbp;
  91. }
  92. lep = acbp->Linkage.Flink;
  93. }
  94. return NULL;
  95. }
  96. /*++
  97. Function: StopAdapterManager
  98. Descr: Closes the IPX notification port
  99. --*/
  100. VOID
  101. StopAdapterManager(VOID)
  102. {
  103. DWORD rc;
  104. ULONG AdapterIndex;
  105. Trace(ADAPTER_TRACE, "StopAdapterManager: Entered\n");
  106. // Close the IPX stack notification port
  107. IpxDeleteAdapterConfigurationPort(AdapterConfigPortHandle);
  108. }
  109. /*++
  110. Function: AdapterNotification
  111. Descr: Processes adapter notification events
  112. --*/
  113. VOID
  114. AdapterNotification(VOID)
  115. {
  116. ADAPTER_INFO AdapterInfo;
  117. ULONG AdapterIndex;
  118. ULONG AdapterConfigurationStatus;
  119. ULONG AdapterNameSize;
  120. LPWSTR AdapterNameBuffer;
  121. DWORD rc;
  122. Trace(ADAPTER_TRACE, "AdapterNotification: Entered\n");
  123. while((rc = IpxGetQueuedAdapterConfigurationStatus(
  124. AdapterConfigPortHandle,
  125. &AdapterIndex,
  126. &AdapterConfigurationStatus,
  127. &AdapterInfo)) == NO_ERROR) {
  128. switch(AdapterConfigurationStatus) {
  129. case ADAPTER_CREATED:
  130. // got the adapter name, create the adapter
  131. CreateAdapter(AdapterIndex,
  132. &AdapterInfo);
  133. break;
  134. case ADAPTER_DELETED:
  135. DeleteAdapter(AdapterIndex);
  136. break;
  137. default:
  138. SS_ASSERT(FALSE);
  139. break;
  140. }
  141. }
  142. }
  143. /*++
  144. Function: CreateAdapter
  145. Descr:
  146. --*/
  147. VOID
  148. CreateAdapter(ULONG AdapterIndex,
  149. PADAPTER_INFO AdapterInfo)
  150. {
  151. PACB acbp;
  152. Trace(ADAPTER_TRACE, "CreateAdapter: Entered for adpt# %d", AdapterIndex);
  153. if((acbp = (PACB)GlobalAlloc(GPTR, sizeof(ACB))) == NULL) {
  154. Trace(ADAPTER_TRACE, "CreateAdapter: Cannot allocate adapter control block\n");
  155. IpxcpConfigDone(AdapterInfo->ConnectionId,
  156. NULL,
  157. NULL,
  158. NULL,
  159. FALSE);
  160. return;
  161. }
  162. ACQUIRE_DATABASE_LOCK;
  163. acbp->AdapterIndex = AdapterIndex;
  164. acbp->ConnectionId = AdapterInfo->ConnectionId;
  165. acbp->Discarded = FALSE;
  166. InitializeCriticalSection(&acbp->AdapterLock);
  167. AddToAdapterHt(acbp);
  168. ACQUIRE_ADAPTER_LOCK(acbp);
  169. RELEASE_DATABASE_LOCK;
  170. // initialize and start the protocol negotiation on this adapter
  171. StartIpxwanProtocol(acbp);
  172. RELEASE_ADAPTER_LOCK(acbp);
  173. }
  174. /*++
  175. Function: DeleteAdapter
  176. Descr:
  177. Remark: If adapter gets deleted IPXCP is also informed by PPP that
  178. the connection has been terminated.
  179. --*/
  180. VOID
  181. DeleteAdapter(ULONG AdapterIndex)
  182. {
  183. PACB acbp;
  184. ACQUIRE_DATABASE_LOCK;
  185. if((acbp = GetAdapterByIndex(AdapterIndex)) == NULL) {
  186. RELEASE_DATABASE_LOCK;
  187. return;
  188. }
  189. Trace(ADAPTER_TRACE, "DeleteAdapter: Entered for adpt# %d", AdapterIndex);
  190. ACQUIRE_ADAPTER_LOCK(acbp);
  191. StopIpxwanProtocol(acbp);
  192. RemoveFromAdapterHt(acbp);
  193. if(acbp->RefCount) {
  194. InsertTailList(&DiscardedAdaptersList, &acbp->Linkage);
  195. acbp->Discarded = TRUE;
  196. Trace(ADAPTER_TRACE, "DeleteAdapter: adpt# %d still referenced, inserted in discarded list", AdapterIndex);
  197. RELEASE_ADAPTER_LOCK(acbp);
  198. }
  199. else
  200. {
  201. DeleteCriticalSection(&acbp->AdapterLock);
  202. Trace(ADAPTER_TRACE, "DeleteAdapter: adpt# %d not referenced, free CB", AdapterIndex);
  203. GlobalFree(acbp);
  204. }
  205. RELEASE_DATABASE_LOCK;
  206. }