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.

148 lines
2.3 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. adpdbase.c
  5. Abstract:
  6. Functions to manipulate the adapters data base
  7. Author:
  8. Stefan Solomon 04/10/1995
  9. Revision History:
  10. --*/
  11. #include "precomp.h"
  12. #pragma hdrstop
  13. #define adpthashindex(AdptIndex) (AdptIndex) % ADAPTER_HASH_TABLE_SIZE
  14. // THIS FUNCTIONS ASSUME THE ROUTER MANAGER IS IN CRITICAL SECTION WHEN CALLED
  15. //***
  16. //
  17. // Function: InitAdptDB
  18. //
  19. // Descr:
  20. //
  21. //***
  22. VOID
  23. InitAdptDB(VOID)
  24. {
  25. int i;
  26. PLIST_ENTRY IfHtBucketp;
  27. IfHtBucketp = IndexAdptHt;
  28. for(i=0; i<ADAPTER_HASH_TABLE_SIZE; i++, IfHtBucketp++) {
  29. InitializeListHead(IfHtBucketp);
  30. }
  31. }
  32. /*++
  33. Function: AddToAdapterHt
  34. Descr: Adds the adapter control block to the hash table of adapters
  35. --*/
  36. VOID
  37. AddToAdapterHt(PACB acbp)
  38. {
  39. int hv;
  40. PLIST_ENTRY lep;
  41. PACB list_acbp;
  42. // insert in index hash table
  43. hv = adpthashindex(acbp->AdapterIndex);
  44. InsertTailList(&IndexAdptHt[hv], &acbp->IndexHtLinkage);
  45. }
  46. VOID
  47. RemoveFromAdapterHt(PACB acbp)
  48. {
  49. RemoveEntryList(&acbp->IndexHtLinkage);
  50. }
  51. /*++
  52. Function: GetAdapterByIndex
  53. Descr:
  54. --*/
  55. PACB
  56. GetAdapterByIndex(ULONG AdptIndex)
  57. {
  58. PACB acbp;
  59. PLIST_ENTRY lep;
  60. int hv;
  61. hv = adpthashindex(AdptIndex);
  62. lep = IndexAdptHt[hv].Flink;
  63. while(lep != &IndexAdptHt[hv])
  64. {
  65. acbp = CONTAINING_RECORD(lep, ACB, IndexHtLinkage);
  66. if (acbp->AdapterIndex == AdptIndex) {
  67. return acbp;
  68. }
  69. lep = acbp->IndexHtLinkage.Flink;
  70. }
  71. return NULL;
  72. }
  73. /*++
  74. Function: GetAdapterByName
  75. Descr: Scans the list of adapters looking for the matching name
  76. --*/
  77. PACB
  78. GetAdapterByNameAndPktType (LPWSTR AdapterName, ULONG PacketType)
  79. {
  80. PACB acbp;
  81. PLIST_ENTRY lep;
  82. int i;
  83. // the list of adapters is kept in the adapters hash table.
  84. for(i=0; i<ADAPTER_HASH_TABLE_SIZE;i++) {
  85. lep = IndexAdptHt[i].Flink;
  86. while(lep != &IndexAdptHt[i])
  87. {
  88. acbp = CONTAINING_RECORD(lep, ACB, IndexHtLinkage);
  89. if(!_wcsicmp(AdapterName, acbp->AdapterNamep)) {
  90. if ((PacketType == AUTO_DETECT_PACKET_TYPE)
  91. || (PacketType == acbp->AdapterInfo.PacketType))
  92. // found !
  93. return acbp;
  94. }
  95. lep = acbp->IndexHtLinkage.Flink;
  96. }
  97. }
  98. return NULL;
  99. }