Leaked source code of windows server 2003
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.

256 lines
7.7 KiB

  1. //-------------------------------------------------------------------
  2. // This is main object
  3. // It starts all life of the system.
  4. // Author: Sergey Ivanov
  5. // Log:
  6. // 06/08/99 - implemented
  7. //-------------------------------------------------------------------
  8. /**********************************************************/
  9. #ifndef __KERNEL__
  10. #define __KERNEL__
  11. // System includes
  12. #include "generic.h"
  13. // Objects supported by the kernel
  14. // Client side
  15. #include "device.h"
  16. #include "system.h"
  17. #include "memory.h"
  18. #include "irp.h"
  19. #include "event.h"
  20. #include "semaphore.h"
  21. #include "int.h"
  22. #include "power.h"
  23. #include "debug.h"
  24. #include "logger.h"
  25. #include "lock.h"
  26. #include "reader.h"
  27. #include "interface.h"
  28. #include "protocol.h"
  29. #include "smartcard.h"
  30. #include "rdrconfig.h"
  31. #include "iopack.h"
  32. #include "timer.h"
  33. /**********************************************************/
  34. #pragma LOCKEDCODE
  35. class CGBus;
  36. class CChild;
  37. class CUSBDevice;
  38. class CUSBReader;
  39. class CKernel;
  40. class CDevice;
  41. class CReaderInterface;
  42. /*
  43. There is only one instance of the class CKernel
  44. */
  45. class CKernel
  46. {
  47. public:
  48. NTSTATUS m_Status;
  49. SAFE_DESTRUCTORS();
  50. virtual VOID dispose(VOID);
  51. public:
  52. ~CKernel(VOID){};
  53. // Return the kernel object.
  54. static CKernel* loadWDMKernel(VOID);
  55. static CKernel* loadNT4Kernel(VOID);
  56. static CKernel* loadWin9xKernel(VOID);
  57. LONG getSystemType(VOID){return systemtype;};
  58. CDebug* getDebug(VOID){return debug;};
  59. CLogger* getLogger(VOID){return logger;};
  60. #ifdef USBREADER_PROJECT
  61. #ifndef USBDEVICE_PROJECT
  62. #define USBDEVICE_PROJECT
  63. #endif
  64. #endif
  65. // This is kernel system objects factory
  66. #ifdef USBDEVICE_PROJECT
  67. static CUSBDevice* createUSBDevice(VOID);
  68. #endif
  69. #ifdef USBREADER_PROJECT
  70. static CUSBReader* createUSBReader(VOID);
  71. #endif
  72. #ifdef BUS_PROJECT
  73. static CDevice* createBus(VOID);
  74. static CDevice* createChild(CGBus* parent,LONG instanceID);
  75. static CDevice* createChild(CGBus* parent,IN PUNICODE_STRING DeviceName,LONG instanceID);
  76. #endif
  77. // Objects driver can create
  78. static CSystem* createSystem(VOID);
  79. static CMemory* createMemory(VOID);
  80. static CIrp* createIrp(VOID);
  81. static CEvent* createEvent(VOID);
  82. static CSemaphore* createSemaphore(VOID);
  83. static CInterrupt* createInterrupt(VOID);
  84. static CPower* createPower(VOID);
  85. static CLock* createLock(VOID);
  86. static CDebug* createDebug(VOID);
  87. static CTimer* createTimer(TIMER_TYPE Type);
  88. // Creates interface to comminicate with reader...
  89. static CReaderInterface* createReaderInterface(LONG interfaceType,LONG protocolType,CDevice* device);
  90. static CLogger* createLogger(VOID);
  91. // Device registration function
  92. // Register device at driver
  93. static VOID registerObject(PDEVICE_OBJECT fdo,CDevice* dev);
  94. static VOID unregisterObject(PDEVICE_OBJECT fdo);
  95. static CDevice* getRegisteredDevice(PDEVICE_OBJECT fdo);
  96. public:
  97. CUString* RegistryPath;
  98. // Linked list of device objects
  99. static CLinkedList<CDevice> *DeviceLinkHead;
  100. private:
  101. static LONG systemtype;
  102. static LONG refcount;
  103. static CDebug* debug;
  104. static CLogger* logger;
  105. private:
  106. CKernel(){};
  107. };
  108. typedef enum _SYSTEM_TYPE_
  109. {
  110. WDM_SYSTEM = 1,
  111. NT4_SYSTEM,
  112. WIN9X_SYSTEM
  113. } SYSTEM_TYPE;
  114. #define CALLBACK_FUNCTION(f) ::f
  115. #define DECLARE_CALLBACK_VOID0(f) VOID f(PDEVICE_OBJECT pDO)
  116. #define DECLARE_CALLBACK_BOOL0(f) BOOL f(PDEVICE_OBJECT pDO)
  117. #define DECLARE_CALLBACK_LONG0(f) NTSTATUS f(PDEVICE_OBJECT pDO)
  118. // functions which take two argument
  119. #define DECLARE_CALLBACK_VOID1(f,type) VOID f(PDEVICE_OBJECT pDO,type arg)
  120. #define DECLARE_CALLBACK_LONG1(f,type) NTSTATUS f(PDEVICE_OBJECT pDO,type arg)
  121. // functions which can take three argument
  122. #define DECLARE_CALLBACK_LONG2(f,type1,type2) NTSTATUS f(PDEVICE_OBJECT pDO,type1 arg1, type2 arg2)
  123. //C wrapper for the DPC function
  124. #define DECLARE_CALLBACK_DPCR(fname,type1,type2) VOID fname(PKDPC Dpc, PDEVICE_OBJECT pDO,type1 arg1, type2 arg2)
  125. #define DECLARE_CALLBACK_ISR(fname) BOOL fname(struct _KINTERRUPT *Interrupt,PDEVICE_OBJECT pDO)
  126. // This will be used to create callback functions
  127. //#define CDEVICE(pDo) ((CDevice*)pDo->DeviceExtension)
  128. inline CDevice* getObjectPointer(PDEVICE_OBJECT pDo)
  129. {
  130. //DBG_PRINT("Object %8.8lX was called\n",pDo);
  131. if(!pDo || !pDo->DeviceExtension)
  132. {
  133. DBG_PRINT("\n****** ERROR! Device %8.8lX ????, CDevice %8.8lX>>> ",pDo,pDo->DeviceExtension);
  134. return NULL; // Object was removed...
  135. }
  136. ULONG type = ((CDevice*)pDo->DeviceExtension)->m_Type;
  137. switch(type)
  138. {
  139. case USB_DEVICE:
  140. {
  141. //DBG_PRINT("\nUSB_DEVICE %8.8lX >>> ",(CDevice*)((CUSBDevice*)pDo->DeviceExtension));
  142. return ((CDevice*)((CUSBDevice*)pDo->DeviceExtension)); break;
  143. }
  144. case USBREADER_DEVICE:
  145. {
  146. //DBG_PRINT("\nUSBREADER_DEVICE %8.8lX >>> ",(CDevice*)((CUSBReader*)pDo->DeviceExtension));
  147. return ((CDevice*)((CUSBReader*)pDo->DeviceExtension)); break;
  148. }
  149. default:
  150. DBG_PRINT("\n****** ERROR! Device %8.8lX ????, CDevice %8.8lX>>> ",pDo,pDo->DeviceExtension);
  151. return ((CDevice*)pDo->DeviceExtension);
  152. }
  153. };
  154. #define CDEVICE(pDo) getObjectPointer(pDo)
  155. // functions which take one argument -> device object
  156. #define IMPLEMENT_CALLBACK_VOID0(f) \
  157. VOID f(PDEVICE_OBJECT pDO)\
  158. {if(CDEVICE(pDO)) CDEVICE(pDO)->f();}
  159. #define IMPLEMENT_CALLBACK_BOOL0(f) \
  160. BOOL f(PDEVICE_OBJECT pDO) \
  161. {if(!CDEVICE(pDO)) return FALSE; return CDEVICE(pDO)->f();}
  162. #define IMPLEMENT_CALLBACK_LONG0(f) \
  163. NTSTATUS f(PDEVICE_OBJECT pDO) \
  164. {if(!CDEVICE(pDO)) return STATUS_INVALID_HANDLE; return CDEVICE(pDO)->f();}
  165. // functions which take two argument
  166. #define IMPLEMENT_CALLBACK_VOID1(f,type)\
  167. VOID f(PDEVICE_OBJECT pDO,type arg)\
  168. {if(CDEVICE(pDO)) CDEVICE(pDO)->f(arg);}
  169. #define IMPLEMENT_CALLBACK_LONG1(f,type) \
  170. NTSTATUS f(PDEVICE_OBJECT pDO,type arg)\
  171. {if(!CDEVICE(pDO)) return STATUS_INVALID_HANDLE; return CDEVICE(pDO)->f(arg);}
  172. // functions which can take three argument
  173. #define IMPLEMENT_CALLBACK_LONG2(f,type1,type2)\
  174. NTSTATUS f(PDEVICE_OBJECT pDO,type1 arg1, type2 arg2)\
  175. {if(!CDEVICE(pDO)) return STATUS_INVALID_HANDLE; return CDEVICE(pDO)->f(arg1, arg2);}
  176. //C wrapper for the DPC function
  177. #define IMPLEMENT_CALLBACK_DPCR(fname,type1,type2) \
  178. VOID fname(PKDPC Dpc, PDEVICE_OBJECT pDO,type1 arg1, type2 arg2)\
  179. {if(CDEVICE(pDO)) CDEVICE(pDO)->DpcForIsr(Dpc, arg1,arg2);}
  180. #define IMPLEMENT_CALLBACK_ISR(fname) \
  181. BOOL fname(struct _KINTERRUPT *Interrupt,PDEVICE_OBJECT pDO)\
  182. {if(CDEVICE(pDO)) return CDEVICE(pDO)->fname();}
  183. //A global reference to the one and only kernel object
  184. extern CKernel* kernel;
  185. // System side
  186. // WDM system
  187. #ifdef WDM_KERNEL
  188. #include "wdmsys.h"
  189. #include "wdmmem.h"
  190. #include "wdmirp.h"
  191. #include "wdmevent.h"
  192. #include "wdmsem.h"
  193. #include "wdmint.h"
  194. #include "wdmlock.h"
  195. #include "wdmpower.h"
  196. #include "wdmdebug.h"
  197. #include "wdmlog.h"
  198. #include "wdmtimer.h"
  199. //#include "wdmdev.h"
  200. #endif
  201. // Specific supported devices
  202. //#include "usbdev.h"
  203. #pragma LOCKEDCODE
  204. // Declare used device callbacks...
  205. #ifndef _DEVICE_CALLBACKS_
  206. #define _DEVICE_CALLBACKS_
  207. DECLARE_CALLBACK_LONG1(open,IN PIRP);
  208. DECLARE_CALLBACK_LONG1(close,IN PIRP);
  209. DECLARE_CALLBACK_LONG1(read,IN PIRP);
  210. DECLARE_CALLBACK_LONG1(write,IN PIRP);
  211. DECLARE_CALLBACK_VOID1(startIo,IN PIRP);
  212. DECLARE_CALLBACK_LONG1(deviceControl,IN PIRP);
  213. DECLARE_CALLBACK_LONG1(flush,IN PIRP);
  214. DECLARE_CALLBACK_LONG1(cleanup,IN PIRP);
  215. DECLARE_CALLBACK_LONG1(powerRequest,IN PIRP);
  216. NTSTATUS pnpRequest(IN PDEVICE_OBJECT fdo,IN PIRP Irp);
  217. DECLARE_CALLBACK_VOID1(cancelPendingIrp,IN PIRP);
  218. VOID onSendDeviceSetPowerComplete(PDEVICE_OBJECT junk, UCHAR fcn, POWER_STATE state, PPOWER_CONTEXT context, PIO_STATUS_BLOCK pstatus);
  219. #endif
  220. #endif//KERNEL