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.

216 lines
3.7 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. ifdbase.c
  5. Abstract:
  6. RIP Interface Data Base Manager
  7. All functions called with the database locked
  8. Author:
  9. Stefan Solomon 07/06/1995
  10. Revision History:
  11. --*/
  12. #include "precomp.h"
  13. #pragma hdrstop
  14. #define ifhashindex(IfIndex) (IfIndex) % IF_INDEX_HASH_TABLE_SIZE
  15. #define adapterhashindex(AdapterIndex) (AdapterIndex) % ADAPTER_INDEX_HASH_TABLE_SIZE
  16. USHORT
  17. tickcount(UINT linkspeed);
  18. VOID
  19. InitIfDbase(VOID)
  20. {
  21. int i;
  22. PLIST_ENTRY HtBucketp;
  23. InitializeListHead(&IndexIfList);
  24. InitializeListHead(&DiscardedIfList);
  25. for(i=0, HtBucketp = IfIndexHt;
  26. i<IF_INDEX_HASH_TABLE_SIZE;
  27. i++, HtBucketp++) {
  28. InitializeListHead(HtBucketp);
  29. }
  30. for(i=0, HtBucketp = AdapterIndexHt;
  31. i<ADAPTER_INDEX_HASH_TABLE_SIZE;
  32. i++, HtBucketp++) {
  33. InitializeListHead(HtBucketp);
  34. }
  35. }
  36. PICB
  37. GetInterfaceByIndex(ULONG InterfaceIndex)
  38. {
  39. PLIST_ENTRY lep, hashbucketp;
  40. PICB icbp;
  41. hashbucketp = &IfIndexHt[ifhashindex(InterfaceIndex)];
  42. lep = hashbucketp->Flink;
  43. while(lep != hashbucketp) {
  44. icbp = CONTAINING_RECORD(lep, ICB, IfHtLinkage);
  45. if(icbp->InterfaceIndex == InterfaceIndex) {
  46. return icbp;
  47. }
  48. lep = lep->Flink;
  49. }
  50. return NULL;
  51. }
  52. PICB
  53. GetInterfaceByAdapterIndex(ULONG AdapterIndex)
  54. {
  55. PLIST_ENTRY lep, hashbucketp;
  56. PICB icbp;
  57. hashbucketp = &AdapterIndexHt[adapterhashindex(AdapterIndex)];
  58. lep = hashbucketp->Flink;
  59. while(lep != hashbucketp) {
  60. icbp = CONTAINING_RECORD(lep, ICB, AdapterHtLinkage);
  61. if(icbp->AdapterBindingInfo.AdapterIndex == AdapterIndex) {
  62. return icbp;
  63. }
  64. lep = lep->Flink;
  65. }
  66. return NULL;
  67. }
  68. VOID
  69. AddIfToDb(PICB icbp)
  70. {
  71. int hv;
  72. PLIST_ENTRY lep;
  73. PICB list_icbp;
  74. BOOL Done = FALSE;
  75. hv = ifhashindex(icbp->InterfaceIndex);
  76. InsertTailList(&IfIndexHt[hv], &icbp->IfHtLinkage);
  77. // insert in the list ordered by index
  78. lep = IndexIfList.Flink;
  79. while(lep != &IndexIfList)
  80. {
  81. list_icbp = CONTAINING_RECORD(lep, ICB, IfListLinkage);
  82. if (list_icbp->InterfaceIndex > icbp->InterfaceIndex) {
  83. InsertTailList(lep, &icbp->IfListLinkage);
  84. Done = TRUE;
  85. break;
  86. }
  87. lep = lep->Flink;
  88. }
  89. if(!Done) {
  90. InsertTailList(lep, &icbp->IfListLinkage);
  91. }
  92. }
  93. VOID
  94. RemoveIfFromDb(PICB icbp)
  95. {
  96. RemoveEntryList(&icbp->IfListLinkage);
  97. RemoveEntryList(&icbp->IfHtLinkage);
  98. }
  99. VOID
  100. BindIf(PICB icbp,
  101. PIPX_ADAPTER_BINDING_INFO BindingInfop)
  102. {
  103. int hv;
  104. icbp->AdapterBindingInfo = *BindingInfop;
  105. // set then tick count if not internal interface
  106. if(icbp->InterfaceIndex != 0) {
  107. icbp->LinkTickCount = tickcount(BindingInfop->LinkSpeed);
  108. }
  109. hv = adapterhashindex(icbp->AdapterBindingInfo.AdapterIndex);
  110. InsertTailList(&AdapterIndexHt[hv], &icbp->AdapterHtLinkage);
  111. }
  112. /*++
  113. Function: UnbindIf
  114. Descr: removes the if CB from the adapters hash table
  115. sets the adapter index in the if CB to INVALID_ADAPTER_INDEX
  116. --*/
  117. VOID
  118. UnbindIf(PICB icbp)
  119. {
  120. RemoveEntryList(&icbp->AdapterHtLinkage);
  121. icbp->AdapterBindingInfo.AdapterIndex = INVALID_ADAPTER_INDEX;
  122. }
  123. /*++
  124. Function: tickcount
  125. Descr: gets nr of ticks to send a 576 bytes packet over this link
  126. Argument: link speed as a multiple of 100 bps
  127. --*/
  128. USHORT
  129. tickcount(UINT linkspeed)
  130. {
  131. USHORT tc;
  132. if(linkspeed == 0) {
  133. return 1;
  134. }
  135. if(linkspeed >= 10000) {
  136. // link speed >= 1M bps
  137. return 1;
  138. }
  139. else
  140. {
  141. // compute the necessary time to send a 576 bytes packet over this
  142. // line and express it as nr of ticks.
  143. // One tick = 55ms
  144. // time in ms to send 576 bytes (assuming 10 bits/byte for serial line)
  145. tc = 57600 / linkspeed;
  146. // in ticks
  147. tc = tc / 55 + 1;
  148. return tc;
  149. }
  150. }