Windows NT 4.0 source code leak
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.

107 lines
2.3 KiB

4 years ago
  1. /*
  2. * CM_CHAN.C - channel allocation (for incoming) code
  3. */
  4. #include <ndis.h>
  5. //#include <ndismini.h>
  6. #include <ndiswan.h>
  7. #include <mytypes.h>
  8. #include <mydefs.h>
  9. #include <disp.h>
  10. #include <util.h>
  11. #include <opcodes.h>
  12. #include <adapter.h>
  13. #include <idd.h>
  14. #include <mtl.h>
  15. #include <cm.h>
  16. CM_CHAN *chan_tbl;
  17. BOOL chan_used[MAX_CHAN_IN_SYSTEM];
  18. #pragma NDIS_INIT_FUNCTION(ChannelInit)
  19. //
  20. // Allocate free channel pool
  21. //
  22. VOID
  23. ChannelInit(VOID)
  24. {
  25. NDIS_PHYSICAL_ADDRESS pa = NDIS_PHYSICAL_ADDRESS_CONST(-1, -1);
  26. /* allocate memory object */
  27. NdisAllocateMemory((PVOID*)&chan_tbl, sizeof(CM_CHAN) * MAX_CHAN_IN_SYSTEM, 0, pa);
  28. if ( chan_tbl == NULL )
  29. {
  30. D_LOG(D_ALWAYS, ("ChannelInit: memory allocate failed!"));
  31. return;
  32. }
  33. D_LOG(D_ALWAYS, ("ChannelInit: chan_tbl: 0x%x", chan_tbl));
  34. NdisZeroMemory (chan_tbl, sizeof(CM_CHAN) * MAX_CHAN_IN_SYSTEM);
  35. NdisZeroMemory (chan_used, sizeof(chan_used));
  36. }
  37. VOID
  38. ChannelTerm(VOID)
  39. {
  40. /* free memory */
  41. NdisFreeMemory(chan_tbl, sizeof(CM_CHAN) * MAX_CHAN_IN_SYSTEM, 0);
  42. }
  43. /* allocate a channel */
  44. CM_CHAN*
  45. cm__chan_alloc(VOID)
  46. {
  47. CM_CHAN *chan = NULL;
  48. INT n;
  49. D_LOG(D_ENTRY, ("cm__chan_alloc: entry"));
  50. for ( n = 0 ; n < MAX_CHAN_IN_SYSTEM ; n++ )
  51. if ( !chan_used[n] )
  52. {
  53. chan_used[n] = TRUE;
  54. chan = chan_tbl + n;
  55. break;
  56. }
  57. D_LOG(D_EXIT, ("cm__alloc_chan: exit, chan: 0x%p", chan));
  58. return(chan);
  59. }
  60. /* free a channel */
  61. VOID
  62. cm__chan_free(CM_CHAN *chan)
  63. {
  64. D_LOG(D_ENTRY, ("cm__chan_free: entry, chan: 0x%p", chan));
  65. chan_used[chan - chan_tbl] = FALSE;
  66. }
  67. /* call a callback function for each used channel */
  68. BOOL
  69. cm__chan_foreach(BOOL (*func)(), VOID *a1, VOID *a2)
  70. {
  71. INT n;
  72. BOOL ret = TRUE;
  73. D_LOG(D_ENTRY, ("cm__chan_foreach: entry, func: %p, a1: 0x%p, a2: 0x%p", \
  74. func, a1, a2));
  75. for ( n = 0 ; n < MAX_CHAN_IN_SYSTEM ; n++ )
  76. if ( chan_used[n] )
  77. {
  78. CM_CHAN *chan = chan_tbl + n;
  79. D_LOG(D_ALWAYS, ("cm__chan_foreach: calling for chan# %d, channel: %p", n, chan));
  80. ret = (*func)(chan, a1, a2);
  81. D_LOG(D_ALWAYS, ("cm__chan_foreach: returned %d", ret));
  82. if ( !ret )
  83. break;
  84. }
  85. return(ret);
  86. }