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.

312 lines
8.9 KiB

  1. /*-----------------------------------------------------------------------
  2. opstr.c - Option Strings. These are strings which define the options
  3. associated with the driver at the three levels: driver, device, port.
  4. This code is special, in that the source may be used for both driver
  5. and setup program, so consists only of the strings which can be shared
  6. in source code.
  7. This has expanded to other code which should be shared by
  8. both setup program and driver.
  9. Copyright 1998 Comtrol(TM) Corporation.
  10. |-----------------------------------------------------------------------*/
  11. #include "precomp.h"
  12. // driver options
  13. const char szVerboseLog[] = {"VerboseLog"};
  14. const char szNumDevices[] = {"NumDevices"};
  15. const char szNoPnpPorts[] = {"NoPnpPorts"};
  16. const char szScanRate[] = {"ScanRate"};
  17. const char szModemCountry[] = {"ModemCountry"};
  18. const char szGlobalRS485[] = {"GlobalRS485Options"};
  19. // device options
  20. //const char szStartComIndex[] = {"StartComIndex"};
  21. const char szNumPorts[] = {"NumPorts"};
  22. const char szMacAddr[] = {"MacAddr"};
  23. const char szBackupServer[] = {"BackupServer"};
  24. const char szBackupTimer[] = {"BackupTimer"};
  25. const char szName[] = {"Name"};
  26. const char szModelName[] = {"ModelName"};
  27. const char szIoAddress[] = {"IoAddress"};
  28. const char szModemDevice[] = {"ModemDevice"};
  29. const char szHubDevice[] = {"HubDevice"};
  30. // port options
  31. const char szWaitOnTx[] = {"WaitOnTx"};
  32. const char szRS485Override[] = {"RS485Override"};
  33. const char szRS485Low[] = {"RS485Low"};
  34. const char szTxCloseTime[] = {"TxCloseTime"};
  35. const char szLockBaud[] = {"LockBaud"};
  36. const char szMap2StopsTo1[] = {"Map2StopsTo1"};
  37. const char szMapCdToDsr[] = {"MapCdToDsr"};
  38. const char szRingEmulate[] = {"RingEmulate"};
  39. Our_Options driver_options[] = {
  40. // driver options
  41. {szVerboseLog, OP_VerboseLog , OP_T_DWORD, OP_F_VSRK},
  42. {szNumDevices, OP_NumDevices , OP_T_DWORD, OP_F_VSRK},
  43. #ifdef NT50
  44. {szNoPnpPorts, OP_NoPnpPorts , OP_T_DWORD, OP_F_VSRK},
  45. #endif
  46. {szScanRate, OP_ScanRate , OP_T_DWORD, OP_F_VSRK},
  47. {szModemCountry, OP_ModemCountry , OP_T_DWORD, OP_F_VSRK},
  48. {szGlobalRS485, OP_GlobalRS485 , OP_T_DWORD, OP_F_VSRK},
  49. {NULL,0,0,0}
  50. };
  51. Our_Options device_options[] = {
  52. // device options
  53. // {szStartComIndex, OP_StartComIndex, OP_T_DWORD , OP_F_VSRK},
  54. {szNumPorts, OP_NumPorts , OP_T_DWORD , OP_F_VSRK},
  55. #ifdef S_VS
  56. {szMacAddr, OP_MacAddr , OP_T_STRING, OP_F_VS},
  57. {szBackupServer, OP_BackupServer , OP_T_DWORD , OP_F_VS},
  58. {szBackupTimer, OP_BackupTimer , OP_T_DWORD , OP_F_VS},
  59. #endif
  60. {szName, OP_Name , OP_T_STRING, OP_F_VSRK},
  61. {szModelName, OP_ModelName , OP_T_STRING, OP_F_VSRK},
  62. #ifdef S_RK
  63. #ifndef NT50
  64. {szIoAddress, OP_IoAddress , OP_T_DWORD , OP_F_RK},
  65. #endif
  66. #endif
  67. {szModemDevice, OP_ModemDevice , OP_T_DWORD , OP_F_VSRK},
  68. {szHubDevice, OP_HubDevice , OP_T_DWORD , OP_F_VS},
  69. {NULL,0,0,0}
  70. };
  71. Our_Options port_options[] = {
  72. // port options
  73. {szWaitOnTx, OP_WaitOnTx , OP_T_DWORD, OP_F_VSRK},
  74. {szRS485Override, OP_RS485Override, OP_T_DWORD, OP_F_VSRK},
  75. {szRS485Low, OP_RS485Low , OP_T_DWORD, OP_F_VSRK},
  76. {szTxCloseTime, OP_TxCloseTime , OP_T_DWORD, OP_F_VSRK},
  77. {szLockBaud, OP_LockBaud , OP_T_DWORD, OP_F_VSRK},
  78. {szMap2StopsTo1, OP_Map2StopsTo1 , OP_T_DWORD, OP_F_VSRK},
  79. {szMapCdToDsr, OP_MapCdToDsr , OP_T_DWORD, OP_F_VSRK},
  80. {szName, OP_PortName , OP_T_STRING, OP_F_VSRK},
  81. {szRingEmulate, OP_RingEmulate , OP_T_DWORD, OP_F_VSRK},
  82. {NULL,0,0,0}
  83. };
  84. #define INFO_WANT_NUMPORTS 0
  85. #define INFO_WANT_MODEM_DEVICE 1
  86. #define INFO_WANT_HUB_DEVICE 2
  87. #define INFO_WANT_PORTS_PER_AIOP 3
  88. #define INFO_WANT_DEF_CLOCK_PRESC 4
  89. static int IdToInfo(int id, int *ret_dword, int info_wanted);
  90. /*-----------------------------------------------------------------
  91. IdToInfo -
  92. |------------------------------------------------------------------*/
  93. static int IdToInfo(int id, int *ret_val, int info_wanted)
  94. {
  95. int num_ports = 8;
  96. int modem_device = 0;
  97. int hub_device = 0;
  98. int ret_stat = 0; // ok
  99. switch (id)
  100. {
  101. case PCI_DEVICE_RPLUS2:
  102. case PCI_DEVICE_422RPLUS2:
  103. num_ports = 2;
  104. break;
  105. case PCI_DEVICE_RPLUS4:
  106. num_ports = 4;
  107. break;
  108. case PCI_DEVICE_4Q :
  109. num_ports = 4;
  110. break;
  111. case PCI_DEVICE_RMODEM4:
  112. num_ports = 4;
  113. modem_device = 1;
  114. break;
  115. case PCI_DEVICE_8RJ :
  116. num_ports = 8;
  117. break;
  118. case PCI_DEVICE_4RJ :
  119. num_ports = 4;
  120. break;
  121. case PCI_DEVICE_8O :
  122. num_ports = 8;
  123. break;
  124. case PCI_DEVICE_8I :
  125. num_ports = 8;
  126. break;
  127. case PCI_DEVICE_RPLUS8:
  128. num_ports = 8;
  129. break;
  130. case PCI_DEVICE_SIEMENS8:
  131. num_ports = 8;
  132. break;
  133. case PCI_DEVICE_16I :
  134. num_ports = 16;
  135. break;
  136. case PCI_DEVICE_SIEMENS16:
  137. num_ports = 16;
  138. break;
  139. case PCI_DEVICE_32I :
  140. num_ports = 32;
  141. break;
  142. case PCI_DEVICE_RMODEM6 :
  143. num_ports = 6;
  144. modem_device = 1;
  145. break;
  146. case ISA_DEVICE_RPORT4: // rocketport
  147. num_ports = 4;
  148. break;
  149. case ISA_DEVICE_RPORT8:
  150. num_ports = 8;
  151. break;
  152. case ISA_DEVICE_RPORT16:
  153. num_ports = 16;
  154. break;
  155. case ISA_DEVICE_RPORT32:
  156. num_ports = 32;
  157. break;
  158. case ISA_DEVICE_RMODEM4: // rocketmodem isa
  159. num_ports = 4;
  160. modem_device = 1;
  161. break;
  162. case ISA_DEVICE_RMODEM8: // rocketmodem isa
  163. num_ports = 8;
  164. modem_device = 1;
  165. break;
  166. case NET_DEVICE_VS1000:
  167. num_ports = 16; // vs1000, base is 16, expandable
  168. break;
  169. case NET_DEVICE_VS2000: // vs2000, base is 8?
  170. num_ports = 8;
  171. modem_device = 1;
  172. break;
  173. case NET_DEVICE_RHUB8: // vshub-8 port
  174. num_ports = 8;
  175. hub_device = 1;
  176. break;
  177. case NET_DEVICE_RHUB4: // vshub-4 port
  178. num_ports = 4;
  179. hub_device = 1;
  180. break;
  181. default:
  182. ret_stat = 1; // err, unknown device
  183. break;
  184. }
  185. switch (info_wanted)
  186. {
  187. case INFO_WANT_NUMPORTS:
  188. *ret_val = num_ports;
  189. break;
  190. case INFO_WANT_MODEM_DEVICE:
  191. *ret_val = modem_device;
  192. break;
  193. case INFO_WANT_HUB_DEVICE:
  194. *ret_val = hub_device;
  195. break;
  196. #if 0
  197. case INFO_WANT_PORTS_PER_AIOP:
  198. if (PortsPerAiop > num_ports)
  199. PortsPerAiop = num_ports;
  200. *ret_val = PortsPerAiop;
  201. case INFO_WANT_DEF_CLOCK_PRESC:
  202. *ret_val = clk_prescaler;
  203. break;
  204. #endif
  205. default:
  206. ret_stat = 2; // unkown info request
  207. break;
  208. }
  209. return ret_stat;
  210. }
  211. /*-----------------------------------------------------------------
  212. id_to_num_ports - pci model-id number used, rest come from NT5 .inf
  213. files.
  214. |------------------------------------------------------------------*/
  215. int id_to_num_ports(int id)
  216. {
  217. int stat;
  218. int num_ports;
  219. stat = IdToInfo(id, &num_ports, INFO_WANT_NUMPORTS);
  220. return num_ports;
  221. }
  222. /*-----------------------------------------------------------------
  223. IsHubDevice -
  224. |------------------------------------------------------------------*/
  225. int IsHubDevice(int Hardware_ID)
  226. {
  227. int stat;
  228. int ishub;
  229. stat = IdToInfo(Hardware_ID, &ishub, INFO_WANT_HUB_DEVICE);
  230. return ishub;
  231. }
  232. /*-----------------------------------------------------------------
  233. IsModemDevice -
  234. |------------------------------------------------------------------*/
  235. int IsModemDevice(int Hardware_ID)
  236. {
  237. int stat;
  238. int ismodemdev;
  239. stat = IdToInfo(Hardware_ID, &ismodemdev, INFO_WANT_MODEM_DEVICE);
  240. return ismodemdev;
  241. }
  242. /*-----------------------------------------------------------------
  243. HdwIDStrToID - Parse the hardware ID string obtained by the WinNT
  244. Pnp system.
  245. This is broke if we ever get ID's starting digit >= HEX(A,B..)
  246. |------------------------------------------------------------------*/
  247. int HdwIDStrToID(int *Hardware_ID, char *idstr)
  248. {
  249. char *s = idstr;
  250. #define _IS_STR_DIGIT(c) ((c >= '0') && (c <= '9'))
  251. #define _IS_STR_LET_D(c) ((c == 'D') || (c == 'd'))
  252. if (strlen(s) < 12) // a isa hardware id
  253. {
  254. while ( (*s != 0) && (!_IS_STR_DIGIT(*s)) ) // find digit
  255. ++s;
  256. }
  257. else // a pci hardware id
  258. {
  259. while ( (*s != 0) && (!_IS_STR_LET_D(*s)) ) // find "DEV_
  260. ++s;
  261. if (*s != 0)
  262. ++s; // pass up the 'D'
  263. while ( (*s != 0) && (!_IS_STR_DIGIT(*s)) ) // find digit
  264. ++s;
  265. // asume we found "DEV_000X"
  266. }
  267. if (*s == 0)
  268. {
  269. *Hardware_ID = 0; // unknown
  270. return 1; // err
  271. }
  272. *Hardware_ID = gethint(s, NULL);
  273. return 0; // ok
  274. }