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.

360 lines
8.5 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. pcmcmd.c
  5. Abstract:
  6. This program converses with the PCMCIA support driver to display
  7. tuple and other information.
  8. Author:
  9. Bob Rinne
  10. Environment:
  11. User process.
  12. Notes:
  13. Revision History:
  14. Ravisankar Pudipeddi (ravisp) June 27 1997
  15. - command line options & support for multiple controllers
  16. Neil Sandlin (neilsa) Sept 20, 1998
  17. - more commands
  18. --*/
  19. #include <pch.h>
  20. //
  21. // Procedures
  22. //
  23. NTSTATUS
  24. OpenDevice(
  25. IN PUCHAR DeviceName,
  26. IN OUT PHANDLE HandlePtr
  27. )
  28. /*++
  29. Routine Description:
  30. This routine will open the device.
  31. Arguments:
  32. DeviceName - ASCI string of device path to open.
  33. HandlePtr - A pointer to a location for the handle returned on a
  34. successful open.
  35. Return Value:
  36. NTSTATUS
  37. --*/
  38. {
  39. OBJECT_ATTRIBUTES objectAttributes;
  40. STRING NtFtName;
  41. IO_STATUS_BLOCK status_block;
  42. UNICODE_STRING unicodeDeviceName;
  43. NTSTATUS status;
  44. RtlInitString(&NtFtName,
  45. DeviceName);
  46. (VOID)RtlAnsiStringToUnicodeString(&unicodeDeviceName,
  47. &NtFtName,
  48. TRUE);
  49. memset(&objectAttributes, 0, sizeof(OBJECT_ATTRIBUTES));
  50. InitializeObjectAttributes(&objectAttributes,
  51. &unicodeDeviceName,
  52. OBJ_CASE_INSENSITIVE,
  53. NULL,
  54. NULL);
  55. status = NtOpenFile(HandlePtr,
  56. SYNCHRONIZE | FILE_READ_DATA | FILE_WRITE_DATA,
  57. &objectAttributes,
  58. &status_block,
  59. FILE_SHARE_READ | FILE_SHARE_WRITE,
  60. FILE_SYNCHRONOUS_IO_ALERT );
  61. RtlFreeUnicodeString(&unicodeDeviceName);
  62. return status;
  63. } // OpenDevice
  64. PUCHAR Controllers[] = {
  65. "PcmciaIntelCompatible",
  66. "PcmciaCardBusCompatible",
  67. "PcmciaElcController",
  68. "PcmciaDatabook",
  69. "PcmciaPciPcmciaBridge",
  70. "PcmciaCirrusLogic",
  71. "PcmciaTI",
  72. "PcmciaTopic",
  73. "PcmciaRicoh",
  74. "PcmciaDatabookCB",
  75. "PcmciaOpti",
  76. "PcmciaTrid",
  77. "PcmciaO2Micro",
  78. "PcmciaNEC",
  79. "PcmciaNEC_98",
  80. };
  81. VOID
  82. DumpSocketInfo(
  83. HANDLE Handle,
  84. ULONG Slot,
  85. PUCHAR Buffer,
  86. ULONG BufferSize
  87. )
  88. /*++
  89. Routine Description:
  90. Arguments:
  91. Return Value:
  92. --*/
  93. {
  94. NTSTATUS status;
  95. IO_STATUS_BLOCK statusBlock;
  96. PCMCIA_SOCKET_INFORMATION commandBlock;
  97. ULONG index;
  98. ULONG ctlClass, ctlModel, ctlRev;
  99. memset(&commandBlock, 0, sizeof(commandBlock));
  100. commandBlock.Socket = (USHORT) Slot;
  101. status = NtDeviceIoControlFile(Handle,
  102. NULL,
  103. NULL,
  104. NULL,
  105. &statusBlock,
  106. IOCTL_SOCKET_INFORMATION,
  107. &commandBlock,
  108. sizeof(commandBlock),
  109. &commandBlock,
  110. sizeof(commandBlock));
  111. if (NT_SUCCESS(status)) {
  112. printf("Basic Information for Socket %d:\n", Slot);
  113. printf(" Manufacturer = %s\n", commandBlock.Manufacturer);
  114. printf(" Identifier = %s\n", commandBlock.Identifier);
  115. printf(" TupleCRC = %x\n", commandBlock.TupleCrc);
  116. printf(" DriverName = %s\n", commandBlock.DriverName);
  117. printf(" Function ID = %d\n", commandBlock.DeviceFunctionId);
  118. ctlClass = PcmciaClassFromControllerType(commandBlock.ControllerType);
  119. if (ctlClass >= sizeof(Controllers)/sizeof(PUCHAR)) {
  120. printf(" ControllerType = Unknown (%x)\n", commandBlock.ControllerType);
  121. } else {
  122. printf(" ControllerType(%x) = %s", commandBlock.ControllerType,
  123. Controllers[ctlClass]);
  124. ctlModel = PcmciaModelFromControllerType(commandBlock.ControllerType);
  125. ctlRev = PcmciaRevisionFromControllerType(commandBlock.ControllerType);
  126. if (ctlModel) {
  127. printf("%d", ctlModel);
  128. }
  129. if (ctlRev) {
  130. printf(", rev(%d)", ctlRev);
  131. }
  132. printf("\n");
  133. }
  134. if (commandBlock.CardInSocket) {
  135. printf(" Card In Socket\n");
  136. }
  137. if (commandBlock.CardEnabled) {
  138. printf(" Card Enabled\n");
  139. }
  140. }
  141. }
  142. NTSTATUS
  143. ProcessCommands(IN ULONG DeviceNumber,
  144. IN ULONG slotNumberMin,
  145. IN ULONG slotNumberMax,
  146. IN ULONG Commands
  147. )
  148. {
  149. NTSTATUS status;
  150. HANDLE handle;
  151. PUCHAR buffer;
  152. UCHAR deviceName[128];
  153. ULONG slotNumber;
  154. sprintf(deviceName, "%s%d", PCMCIA_DEVICE_NAME, DeviceNumber);
  155. status = OpenDevice(deviceName, &handle);
  156. if (!NT_SUCCESS(status)) {
  157. return status;
  158. }
  159. buffer = malloc(BUFFER_SIZE);
  160. if (!buffer) {
  161. printf("Unable to malloc\n");
  162. return STATUS_NO_MEMORY;
  163. }
  164. printf("\n** PC-Card information for PCMCIA controller %s **\n\n", deviceName);
  165. for (slotNumber = slotNumberMin; slotNumber <= slotNumberMax; slotNumber++) {
  166. if (Commands & CMD_DUMP_TUPLES) {
  167. DumpCIS(handle, slotNumber, buffer, BUFFER_SIZE);
  168. }
  169. if (!Commands || (Commands & CMD_DUMP_SOCKET_INFO)) {
  170. DumpSocketInfo(handle, slotNumber, buffer, BUFFER_SIZE);
  171. }
  172. }
  173. NtClose(handle);
  174. return STATUS_SUCCESS;
  175. }
  176. int __cdecl
  177. main(
  178. int argc,
  179. char *argv[]
  180. )
  181. /*++
  182. Routine Description:
  183. Arguments:
  184. Return Value:
  185. --*/
  186. {
  187. ULONG deviceNumber = 0;
  188. ULONG slotNumber = 0;
  189. NTSTATUS status;
  190. BOOLEAN error = FALSE;
  191. CHAR c;
  192. BOOLEAN allControllers = TRUE, allSlots = TRUE, registers = FALSE, configuration = FALSE;
  193. ULONG slotNumberMin, slotNumberMax;
  194. ULONG Commands = 0;
  195. extern PUCHAR optarg;
  196. while ((c = getopt(argc, argv, "d:s:crti?")) != EOF) {
  197. switch (c) {
  198. case 'd': {
  199. allControllers = FALSE;
  200. deviceNumber = atoi(optarg);
  201. break;
  202. }
  203. case 's': {
  204. allSlots = FALSE;
  205. slotNumber = atoi(optarg);
  206. break;
  207. }
  208. case 't': {
  209. Commands |= CMD_DUMP_TUPLES;
  210. break;
  211. }
  212. case 'i': {
  213. Commands |= CMD_DUMP_IRQ_SCAN_INFO;
  214. break;
  215. }
  216. case '?': {
  217. error = TRUE;
  218. break;
  219. }
  220. case 0: {
  221. error = TRUE;
  222. printf("Error in command line options\n");
  223. break;
  224. }
  225. default: {
  226. error = TRUE;
  227. break;
  228. }
  229. }
  230. }
  231. if (error) {
  232. printf("Usage: pcmcmd [-[d <arg>] [s <arg>][c][r][t]]\n");
  233. printf("Issues commands to the pc-card (PCMCIA) driver\n");
  234. printf("-d ControllerNumber specifies PCMCIA controller number (zero-based)\n");
  235. printf("-s SocketNumber specifies PCMCIA socket number (zero-based)\n");
  236. printf("-t Dumps the CIS tuples of the PC-Card\n");
  237. printf("-i Dumps irq detection info\n");
  238. return (1);
  239. }
  240. if (Commands & CMD_DUMP_IRQ_SCAN_INFO) {
  241. DumpIrqScanInfo();
  242. if (!(Commands & ~CMD_DUMP_IRQ_SCAN_INFO)) {
  243. return(0);
  244. }
  245. }
  246. if (allSlots) {
  247. //
  248. // Probe all slots
  249. //
  250. slotNumberMin = 0;
  251. slotNumberMax = 7;
  252. } else {
  253. //
  254. // Probe only the specified slot
  255. //
  256. slotNumberMin = slotNumberMax = slotNumber;
  257. }
  258. if (allControllers) {
  259. deviceNumber = 0;
  260. do {
  261. status = ProcessCommands(deviceNumber++, slotNumberMin, slotNumberMax, Commands);
  262. } while (NT_SUCCESS(status));
  263. deviceNumber--; // set back to last device processed
  264. if (status != STATUS_OBJECT_NAME_NOT_FOUND) {
  265. printf("Failed for Pcmcia controller number %d: status 0x%x\n", deviceNumber, status);
  266. } else if (deviceNumber == 0) {
  267. printf("Error - no active Pcmcia controllers found\n");
  268. }
  269. } else {
  270. status = ProcessCommands(deviceNumber, slotNumberMin, slotNumberMax, Commands);
  271. if (!NT_SUCCESS(status)) {
  272. printf("Failed for Pcmcia controller number %d: status 0x%x\n", deviceNumber, status);
  273. }
  274. };
  275. return (0);
  276. }