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.

533 lines
14 KiB

  1. /*****************************************************************************
  2. *
  3. * Copyright (c) 1996-1999 Microsoft Corporation
  4. *
  5. * @doc
  6. * @module actisys.c | IrSIR NDIS Miniport Driver
  7. * @comm
  8. *
  9. *-----------------------------------------------------------------------------
  10. *
  11. * Author: Stan Adermann (stana)
  12. *
  13. * Date: 10/30/1997 (created)
  14. *
  15. * Contents: ACTiSYS dongle specific code for initialization,
  16. * deinit, and setting the baud rate of the device.
  17. *
  18. *****************************************************************************/
  19. #include "irsir.h"
  20. #include "dongle.h"
  21. #define ACT200L_IRDA_SPEEDS ( \
  22. NDIS_IRDA_SPEED_2400 | \
  23. NDIS_IRDA_SPEED_9600 | \
  24. NDIS_IRDA_SPEED_19200 | \
  25. NDIS_IRDA_SPEED_38400 | \
  26. NDIS_IRDA_SPEED_57600 | \
  27. NDIS_IRDA_SPEED_115200 \
  28. )
  29. #define MS(d) ((d)*1000)
  30. #if 0
  31. static UCHAR Act200LReset[] = { 0xf0 };
  32. static UCHAR Act200LSetIrDAMode[] = { 0x03, 0x47, 0x53, 0x64, 0x76, 0xD1, 0x56, 0xD0 };
  33. static UCHAR Act200LSetSpeed2400[] = { 0x03, 0x47, 0x53, 0x64, 0x76, 0xD1, 0x56, 0xD0, 0x8F, 0x95, 0x11 };
  34. static UCHAR Act200LSetSpeed9600[] = { 0x03, 0x47, 0x53, 0x64, 0x76, 0xD1, 0x56, 0xD0, 0x87, 0x91, 0x11 };
  35. static UCHAR Act200LSetSpeed19200[] = { 0x03, 0x47, 0x53, 0x64, 0x76, 0xD1, 0x56, 0xD0, 0x8B, 0x90, 0x11 };
  36. static UCHAR Act200LSetSpeed38400[] = { 0x03, 0x47, 0x53, 0x64, 0x76, 0xD1, 0x56, 0xD0, 0x85, 0x90, 0x11 };
  37. static UCHAR Act200LSetSpeed57600[] = { 0x03, 0x47, 0x53, 0x64, 0x76, 0xD1, 0x56, 0xD0, 0x83, 0x90, 0x11 };
  38. static UCHAR Act200LSetSpeed115200[] = { 0x03, 0x47, 0x53, 0x64, 0x76, 0xD1, 0x56, 0xD0, 0x81, 0x90, 0x11 };
  39. #else
  40. static UCHAR Act200LReset[] = { 0xf0 };
  41. static UCHAR Act200LSetIrDAMode[] = { 0x0B, 0x53, 0x47, 0x63, 0x74, 0xD1, 0x56, 0xD0 };
  42. static UCHAR Act200LSetSpeed2400[] = { 0x8F, 0x95, 0x11 };
  43. static UCHAR Act200LSetSpeed9600[] = { 0x87, 0x91, 0x11 };
  44. static UCHAR Act200LSetSpeed19200[] = { 0x8B, 0x90, 0x11 };
  45. static UCHAR Act200LSetSpeed38400[] = { 0x85, 0x90, 0x11 };
  46. static UCHAR Act200LSetSpeed57600[] = { 0x83, 0x90, 0x11 };
  47. static UCHAR Act200LSetSpeed115200[] = { 0x81, 0x90, 0x11 };
  48. #endif
  49. static BOOLEAN ACT200L_Reset(IN PDEVICE_OBJECT pSerialDevObj)
  50. {
  51. ULONG BytesRead, BytesWritten;
  52. UCHAR Response;
  53. BOOLEAN Reset = FALSE;
  54. UINT i;
  55. DEBUGMSG(DBG_FUNC, ("+ACT200L_Reset\n"));
  56. (void)SerialPurge(pSerialDevObj);
  57. SerialSetTimeouts(pSerialDevObj, &SerialTimeoutsInit);
  58. for (i=0; i<5 && !Reset; i++)
  59. {
  60. (void)SerialSetDTR(pSerialDevObj);
  61. (void)SerialSetRTS(pSerialDevObj);
  62. NdisMSleep(MS(100));
  63. (void)SerialClrRTS(pSerialDevObj);
  64. (void)SerialSetBreakOn(pSerialDevObj);
  65. NdisMSleep(MS(60));
  66. (void)SerialSetBreakOff(pSerialDevObj);
  67. (void)SerialSetRTS(pSerialDevObj);
  68. NdisMSleep(MS(60));
  69. (void)SerialClrDTR(pSerialDevObj);
  70. NdisMSleep(MS(20));
  71. (void)SerialSynchronousWrite(pSerialDevObj,
  72. Act200LReset,
  73. sizeof(Act200LReset),
  74. &BytesWritten);
  75. (void)SerialSynchronousRead(pSerialDevObj,
  76. &Response,
  77. 1,
  78. &BytesRead);
  79. if (BytesRead==1 && (Response==0xF4 || Response==0xF5))
  80. {
  81. Reset = TRUE;
  82. }
  83. else
  84. {
  85. DEBUGMSG(DBG_ERROR, ("ACT200L failed to reset %d %d %x!\n", i, BytesRead, Response));
  86. }
  87. }
  88. DEBUGMSG(DBG_FUNC, ("-ACT200L_Reset\n"));
  89. return Reset;
  90. }
  91. static BOOLEAN
  92. ACT200L_WriteCommand(IN PDEVICE_OBJECT pSerialDevObj,
  93. IN PUCHAR pCommand, UINT Length)
  94. {
  95. SerialSetTimeouts(pSerialDevObj, &SerialTimeoutsInit);
  96. while (Length--)
  97. {
  98. UCHAR Response;
  99. ULONG BytesRead;
  100. ULONG BytesWritten = 0;
  101. NTSTATUS Status;
  102. (void)SerialSynchronousWrite(pSerialDevObj,
  103. pCommand,
  104. 1,
  105. &BytesWritten);
  106. if (BytesWritten!=1)
  107. {
  108. return FALSE;
  109. }
  110. Status = SerialSynchronousRead(pSerialDevObj,
  111. &Response,
  112. 1,
  113. &BytesRead);
  114. if (Status!=STATUS_SUCCESS || Response!=*pCommand)
  115. {
  116. if (BytesRead)
  117. {
  118. DEBUGMSG(DBG_ERROR, ("Expected: %02X Got: %02X\n", *pCommand, Response));
  119. }
  120. return FALSE;
  121. }
  122. pCommand++;
  123. }
  124. return TRUE;
  125. }
  126. NDIS_STATUS
  127. ACT200L_QueryCaps(
  128. OUT PDONGLE_CAPABILITIES pDongleCaps
  129. )
  130. {
  131. pDongleCaps->supportedSpeedsMask = ACT200L_IRDA_SPEEDS;
  132. pDongleCaps->turnAroundTime_usec = 100;
  133. pDongleCaps->extraBOFsRequired = 0;
  134. return NDIS_STATUS_SUCCESS;
  135. }
  136. static BOOLEAN ACT200L_SetIrDAMode(IN PDEVICE_OBJECT pSerialDevObj)
  137. {
  138. UINT Attempts;
  139. BOOLEAN Result = FALSE;
  140. for (Attempts=0; !Result && Attempts<5; Attempts++)
  141. {
  142. if (ACT200L_Reset(pSerialDevObj) &&
  143. ACT200L_WriteCommand(pSerialDevObj, Act200LSetIrDAMode, sizeof(Act200LSetIrDAMode)) &&
  144. ACT200L_WriteCommand(pSerialDevObj, Act200LSetSpeed9600, sizeof(Act200LSetSpeed9600)))
  145. {
  146. Result = TRUE;
  147. }
  148. }
  149. // Return with chip in command mode.
  150. return Result;
  151. }
  152. /*****************************************************************************
  153. *
  154. * Function: ACT200L_Init
  155. *
  156. * Synopsis: Initialize the ACTiSYS 200L dongle.
  157. *
  158. * Arguments:
  159. *
  160. * Returns: NDIS_STATUS_SUCCESS
  161. * DONGLE_CAPABILITIES
  162. *
  163. * Algorithm:
  164. *
  165. * History: dd-mm-yyyy Author Comment
  166. * 10/2/1996 stana author
  167. *
  168. * Notes:
  169. *
  170. *****************************************************************************/
  171. NDIS_STATUS
  172. ACT200L_Init(
  173. IN PDEVICE_OBJECT pSerialDevObj
  174. )
  175. {
  176. ULONG BytesRead, BytesWritten;
  177. UCHAR Response;
  178. BOOLEAN Reset = FALSE;
  179. UINT i;
  180. DEBUGMSG(DBG_FUNC, ("+ACT200L_Init\n"));
  181. if (!ACT200L_SetIrDAMode(pSerialDevObj))
  182. {
  183. DEBUGMSG(DBG_ERROR, ("ACT200L wouldn't SetIrDAMode! Giving up.\n"));
  184. return NDIS_STATUS_FAILURE;
  185. }
  186. // Clear command mode.
  187. (void)SerialSetDTR(pSerialDevObj);
  188. NdisMSleep(MS(50));
  189. DEBUGMSG(DBG_FUNC, ("-ACT200L_Init\n"));
  190. return NDIS_STATUS_SUCCESS;
  191. }
  192. /*****************************************************************************
  193. *
  194. * Function: ACT200L_Deinit
  195. *
  196. * Synopsis: The ACT200L dongle doesn't require any special deinit, but for
  197. * purposes of being symmetrical with other dongles...
  198. *
  199. * Arguments:
  200. *
  201. * Returns:
  202. *
  203. * Algorithm:
  204. *
  205. * History: dd-mm-yyyy Author Comment
  206. * 10/2/1996 stana author
  207. *
  208. * Notes:
  209. *
  210. *
  211. *****************************************************************************/
  212. VOID
  213. ACT200L_Deinit(
  214. IN PDEVICE_OBJECT pSerialDevObj
  215. )
  216. {
  217. DEBUGMSG(DBG_FUNC, ("+ACT200L_Deinit\n"));
  218. (void)SerialSetDTR(pSerialDevObj);
  219. (void)SerialClrRTS(pSerialDevObj);
  220. NdisMSleep(MS(50));
  221. DEBUGMSG(DBG_FUNC, ("-ACT200L_Deinit\n"));
  222. return;
  223. }
  224. /*****************************************************************************
  225. *
  226. * Function: ACT200L_SetSpeed
  227. *
  228. * Synopsis: set the baud rate of the ACT200L dongle
  229. *
  230. * Arguments:
  231. *
  232. * Returns: NDIS_STATUS_SUCCESS if bitsPerSec = 9600 || 19200 || 115200
  233. * NDIS_STATUS_FAILURE otherwise
  234. *
  235. * Algorithm:
  236. *
  237. * History: dd-mm-yyyy Author Comment
  238. * 10/2/1996 stana author
  239. *
  240. * Notes:
  241. * The caller of this function should set the baud rate of the
  242. * serial driver (UART) to 9600 first to ensure that dongle
  243. * receives the commands.
  244. *
  245. *
  246. *****************************************************************************/
  247. NDIS_STATUS
  248. ACT200L_SetSpeed(
  249. IN PDEVICE_OBJECT pSerialDevObj,
  250. IN UINT bitsPerSec,
  251. IN UINT currentSpeed
  252. )
  253. {
  254. ULONG WaitMask = SERIAL_EV_TXEMPTY;
  255. UCHAR *SetSpeedString;
  256. ULONG SetSpeedStringLength, BytesWritten;
  257. ULONG Speed9600 = 9600;
  258. BOOLEAN Result;
  259. DEBUGMSG(DBG_FUNC, ("+ACT200L_SetSpeed\n"));
  260. switch (bitsPerSec)
  261. {
  262. #define MAKECASE(speed) \
  263. case speed: SetSpeedString = Act200LSetSpeed##speed; SetSpeedStringLength = sizeof(Act200LSetSpeed##speed); break;
  264. MAKECASE(2400)
  265. MAKECASE(9600)
  266. MAKECASE(19200)
  267. MAKECASE(38400)
  268. MAKECASE(57600)
  269. MAKECASE(115200)
  270. default:
  271. return NDIS_STATUS_FAILURE;
  272. }
  273. (void)SerialPurge(pSerialDevObj);
  274. (void)SerialClrDTR(pSerialDevObj);
  275. NdisMSleep(MS(50));
  276. if (!ACT200L_WriteCommand(pSerialDevObj, SetSpeedString, SetSpeedStringLength))
  277. {
  278. DEBUGMSG(DBG_ERROR, ("SetSpeed failed first try.\n"));
  279. if (!ACT200L_SetIrDAMode(pSerialDevObj) ||
  280. !ACT200L_WriteCommand(pSerialDevObj, SetSpeedString, SetSpeedStringLength))
  281. {
  282. return NDIS_STATUS_FAILURE;
  283. }
  284. }
  285. NdisMSleep(MS(50));
  286. (void)SerialSetDTR(pSerialDevObj);
  287. DEBUGMSG(DBG_FUNC, ("-ACT200L_SetSpeed\n"));
  288. return NDIS_STATUS_SUCCESS;
  289. }
  290. #define ACT220L_IRDA_SPEEDS (NDIS_IRDA_SPEED_9600 | \
  291. NDIS_IRDA_SPEED_19200 | \
  292. NDIS_IRDA_SPEED_57600 | \
  293. NDIS_IRDA_SPEED_115200)
  294. NDIS_STATUS
  295. ACT220L_QueryCaps(
  296. OUT PDONGLE_CAPABILITIES pDongleCaps
  297. )
  298. {
  299. DEBUGMSG(DBG_FUNC, ("+ACT220L_QueryCaps\n"));
  300. pDongleCaps->supportedSpeedsMask = ACT220L_IRDA_SPEEDS;
  301. pDongleCaps->turnAroundTime_usec = 100;
  302. pDongleCaps->extraBOFsRequired = 0;
  303. DEBUGMSG(DBG_FUNC, ("-ACT220L_QueryCaps\n"));
  304. return NDIS_STATUS_SUCCESS;
  305. }
  306. #define ACT220LPLUS_IRDA_SPEEDS (ACT220L_IRDA_SPEEDS | NDIS_IRDA_SPEED_38400)
  307. NDIS_STATUS
  308. ACT220LPlus_QueryCaps(
  309. OUT PDONGLE_CAPABILITIES pDongleCaps
  310. )
  311. {
  312. DEBUGMSG(DBG_FUNC, ("+ACT220LPlus_QueryCaps\n"));
  313. pDongleCaps->supportedSpeedsMask = ACT220LPLUS_IRDA_SPEEDS;
  314. pDongleCaps->turnAroundTime_usec = 100;
  315. pDongleCaps->extraBOFsRequired = 0;
  316. DEBUGMSG(DBG_FUNC, ("-ACT220LPlus_QueryCaps\n"));
  317. return NDIS_STATUS_SUCCESS;
  318. }
  319. /*****************************************************************************
  320. *
  321. * Function: ACT220L_Init
  322. *
  323. * Synopsis: Initialize the ACTiSYS 200L dongle.
  324. *
  325. * Arguments:
  326. *
  327. * Returns: NDIS_STATUS_SUCCESS
  328. * DONGLE_CAPABILITIES
  329. *
  330. * Algorithm:
  331. *
  332. * History: dd-mm-yyyy Author Comment
  333. * 10/31/1997 stana author
  334. *
  335. * Notes:
  336. *
  337. *****************************************************************************/
  338. NDIS_STATUS
  339. ACT220L_Init(IN PDEVICE_OBJECT pSerialDevObj)
  340. {
  341. ULONG BytesRead, BytesWritten;
  342. UCHAR Response;
  343. BOOLEAN Reset = FALSE;
  344. UINT i;
  345. DEBUGMSG(DBG_FUNC, ("+ACT220L_Init\n"));
  346. (void)SerialSetDTR(pSerialDevObj);
  347. (void)SerialSetRTS(pSerialDevObj);
  348. NdisMSleep(MS(50));
  349. (void)SerialClrDTR(pSerialDevObj);
  350. (void)SerialSetDTR(pSerialDevObj);
  351. DEBUGMSG(DBG_FUNC, ("-ACT220L_Init\n"));
  352. return NDIS_STATUS_SUCCESS;
  353. }
  354. /*****************************************************************************
  355. *
  356. * Function: ACT220L_Deinit
  357. *
  358. * Synopsis: The ACT220L dongle doesn't require any special deinit, but for
  359. * purposes of being symmetrical with other dongles...
  360. *
  361. * Arguments:
  362. *
  363. * Returns:
  364. *
  365. * Algorithm:
  366. *
  367. * History: dd-mm-yyyy Author Comment
  368. * 10/2/1996 stana author
  369. *
  370. * Notes:
  371. *
  372. *
  373. *****************************************************************************/
  374. VOID
  375. ACT220L_Deinit(
  376. IN PDEVICE_OBJECT pSerialDevObj
  377. )
  378. {
  379. DEBUGMSG(DBG_FUNC, ("+ACT220L_Deinit\n"));
  380. (void)SerialClrDTR(pSerialDevObj);
  381. (void)SerialClrRTS(pSerialDevObj);
  382. DEBUGMSG(DBG_FUNC, ("-ACT220L_Deinit\n"));
  383. return;
  384. }
  385. /*****************************************************************************
  386. *
  387. * Function: ACT220L_SetSpeed
  388. *
  389. * Synopsis: set the baud rate of the ACT220L dongle
  390. *
  391. * Arguments:
  392. *
  393. * Returns: NDIS_STATUS_SUCCESS if bitsPerSec = 9600 || 19200 || 115200
  394. * NDIS_STATUS_FAILURE otherwise
  395. *
  396. * Algorithm:
  397. *
  398. * History: dd-mm-yyyy Author Comment
  399. * 10/2/1996 stana author
  400. *
  401. * Notes:
  402. * The caller of this function should set the baud rate of the
  403. * serial driver (UART) to 9600 first to ensure that dongle
  404. * receives the commands.
  405. *
  406. *
  407. *****************************************************************************/
  408. NDIS_STATUS
  409. ACT220L_SetSpeed(
  410. IN PDEVICE_OBJECT pSerialDevObj,
  411. IN UINT bitsPerSec,
  412. IN UINT currentSpeed
  413. )
  414. {
  415. ULONG NumToggles;
  416. DEBUGMSG(DBG_FUNC, ("+ACT220L_SetSpeed\n"));
  417. if (bitsPerSec==currentSpeed)
  418. {
  419. return NDIS_STATUS_SUCCESS;
  420. }
  421. //
  422. // We will need to 'count up' from 9600 Kbaud.
  423. //
  424. switch (bitsPerSec){
  425. case 9600: NumToggles = 0; break;
  426. case 19200: NumToggles = 1; break;
  427. case 57600: NumToggles = 2; break;
  428. case 115200: NumToggles = 3; break;
  429. case 38400: NumToggles = 4; break;
  430. default:
  431. /*
  432. * Illegal speed
  433. */
  434. return NDIS_STATUS_FAILURE;
  435. }
  436. //
  437. // Set speed to 9600
  438. //
  439. NdisStallExecution(1);
  440. (void)SerialClrDTR(pSerialDevObj);
  441. NdisStallExecution(1);
  442. (void)SerialSetDTR(pSerialDevObj);
  443. while (NumToggles--)
  444. {
  445. NdisStallExecution(1);
  446. (void)SerialClrRTS(pSerialDevObj);
  447. NdisStallExecution(1);
  448. (void)SerialSetRTS(pSerialDevObj);
  449. }
  450. DEBUGMSG(DBG_FUNC, ("-ACT220L_SetSpeed\n"));
  451. return NDIS_STATUS_SUCCESS;
  452. }