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.

819 lines
22 KiB

  1. /*****************************************************************************
  2. *
  3. * $Workfile: TcpMib.cpp $
  4. *
  5. * Copyright (C) 1997 Hewlett-Packard Company.
  6. * Copyright (C) 1997 Microsoft Corporation.
  7. * All rights reserved.
  8. *
  9. * 11311 Chinden Blvd.
  10. * Boise, Idaho 83714
  11. *
  12. *****************************************************************************/
  13. #include "precomp.h"
  14. #include "snmpmgr.h"
  15. #include "stdmib.h"
  16. #include "pingicmp.h"
  17. #include "tcpmib.h"
  18. #include "status.h"
  19. ///////////////////////////////////////////////////////////////////////////////
  20. // Global definitions/declerations
  21. CTcpMib *g_pTcpMib = 0;
  22. int g_cntGlobalAlloc=0; // used for debugging purposes
  23. int g_csGlobalCount=0;
  24. // to ensure that the CTCPMib is not being deleted improperly, perform usage count on the DLL
  25. int g_cntUsage = 0;
  26. ///////////////////////////////////////////////////////////////////////////////
  27. // GetDLLInterfacePtr -- returns the pointer to the DLL interface
  28. extern "C" CTcpMibABC*
  29. GetTcpMibPtr( void )
  30. {
  31. return (g_pTcpMib);
  32. } // GetDLLInterfacePtr()
  33. ///////////////////////////////////////////////////////////////////////////////
  34. // Ping -- pings the given device
  35. // Return Codes:
  36. // NO_ERROR if ping is successfull
  37. // DEVICE_NOT_FOUND if device is not found
  38. extern "C" DWORD
  39. Ping( LPCSTR in pHost )
  40. {
  41. DWORD dwRetCode = NO_ERROR;
  42. // do icmpPing
  43. CPingICMP *pPingICMP = new CPingICMP(pHost);
  44. if ( !pPingICMP )
  45. return (dwRetCode = GetLastError()) ? dwRetCode : ERROR_OUTOFMEMORY;
  46. if ( !pPingICMP->Ping() )
  47. {
  48. dwRetCode = ERROR_DEVICE_NOT_FOUND;
  49. }
  50. delete pPingICMP;
  51. return (dwRetCode);
  52. } // Ping()
  53. ///////////////////////////////////////////////////////////////////////////////
  54. // DllMain
  55. //
  56. BOOL APIENTRY
  57. DllMain ( HANDLE in hInst,
  58. DWORD in dwReason,
  59. LPVOID in lpReserved )
  60. {
  61. switch (dwReason)
  62. {
  63. case DLL_PROCESS_ATTACH:
  64. DisableThreadLibraryCalls( hInst );
  65. g_cntUsage++; // DLL usage count
  66. if ( !g_pTcpMib)
  67. {
  68. g_pTcpMib = new CTcpMib(); // create the port manager object
  69. if (!g_pTcpMib)
  70. {
  71. return FALSE;
  72. }
  73. }
  74. return TRUE;
  75. case DLL_PROCESS_DETACH:
  76. g_cntUsage--; // DLL usage count
  77. if (g_cntUsage == 0)
  78. {
  79. if (g_pTcpMib)
  80. {
  81. delete g_pTcpMib; // FIX! do we need to worry about usage count here??
  82. g_pTcpMib = NULL;
  83. }
  84. }
  85. return TRUE;
  86. }
  87. return FALSE;
  88. } // DllMain()
  89. /*****************************************************************************
  90. *
  91. * CTcpMib implementation
  92. *
  93. *****************************************************************************/
  94. ///////////////////////////////////////////////////////////////////////////////
  95. // static functions & member initialization
  96. ///////////////////////////////////////////////////////////////////////////////
  97. // CTcpMib::CTcpMib()
  98. CTcpMib::CTcpMib( )
  99. {
  100. InitializeCriticalSection(&m_critSect);
  101. } // ::CTcpMib()
  102. ///////////////////////////////////////////////////////////////////////////////
  103. // CTcpMib::~CTcpMib()
  104. CTcpMib::~CTcpMib( )
  105. {
  106. DeleteCriticalSection(&m_critSect);
  107. } // ::~CTcpMib()
  108. ///////////////////////////////////////////////////////////////////////////////
  109. // EnterCSection -- enters the critical section
  110. void
  111. CTcpMib::EnterCSection( )
  112. {
  113. EnterCriticalSection(&m_critSect); // enter critical section
  114. } // ::EnterCSection()
  115. ///////////////////////////////////////////////////////////////////////////////
  116. // ExitCSection -- enters the critical section
  117. void
  118. CTcpMib::ExitCSection( )
  119. {
  120. LeaveCriticalSection(&m_critSect); // exit critical section
  121. } // ::ExitCSection()
  122. ///////////////////////////////////////////////////////////////////////////////
  123. // SupportsPrinterMib --
  124. //
  125. BOOL
  126. CTcpMib::
  127. SupportsPrinterMib(
  128. IN LPCSTR pHost,
  129. IN LPCSTR pCommunity,
  130. IN DWORD dwDevIndex,
  131. OUT PBOOL pbSupported
  132. )
  133. {
  134. BOOL bRet = FALSE;
  135. DWORD dwLastError = ERROR_SUCCESS;
  136. EnterCSection();
  137. if ( (dwLastError = Ping(pHost)) == NO_ERROR ) {
  138. CStdMib *pStdMib = new CStdMib(pHost, pCommunity, dwDevIndex, this);
  139. if ( pStdMib ) {
  140. *pbSupported = pStdMib->TestPrinterMIB();
  141. bRet = TRUE;
  142. delete pStdMib;
  143. }
  144. }
  145. ExitCSection();
  146. if (!bRet)
  147. SetLastError (dwLastError);
  148. return bRet;
  149. } // ::SupportsPrinterMib()
  150. ///////////////////////////////////////////////////////////////////////////////
  151. // GetDeviceDescription --
  152. //
  153. // Returns:
  154. // NO_ERROR -
  155. // ERROR_DEVICE_NOT_FOUND -
  156. // SUCCESS_DEVICE_UNKNOWN
  157. DWORD
  158. CTcpMib::
  159. GetDeviceDescription(
  160. IN LPCSTR pHost,
  161. IN LPCSTR pCommunity,
  162. IN DWORD dwDevIndex,
  163. OUT LPTSTR pszPortDesc,
  164. IN DWORD dwDescLen
  165. )
  166. {
  167. DWORD dwRet = NO_ERROR;
  168. EnterCSection();
  169. if ( Ping(pHost) == NO_ERROR ) {
  170. CStdMib *pStdMib = new CStdMib(pHost, pCommunity, dwDevIndex, this);
  171. if ( pStdMib ) {
  172. if ( !pStdMib->GetDeviceDescription(pszPortDesc, dwDescLen)){
  173. dwRet = SUCCESS_DEVICE_UNKNOWN;
  174. }
  175. delete pStdMib;
  176. }
  177. } else {
  178. dwRet = ERROR_DEVICE_NOT_FOUND;
  179. }
  180. ExitCSection();
  181. return dwRet;
  182. } // ::GetDeviceDescription()
  183. ///////////////////////////////////////////////////////////////////////////////
  184. // GetDeviceStatus --
  185. // Error Codes:
  186. // Returns the mapped printer error code to the spooler error code
  187. DWORD
  188. CTcpMib::GetDeviceStatus( LPCSTR in pHost,
  189. LPCSTR pCommunity,
  190. DWORD dwDevIndex )
  191. {
  192. DWORD dwRetCode = NO_ERROR;
  193. EnterCSection();
  194. // instantiate the CStdMib::GetDeviceType()
  195. CStdMib *pStdMib = new CStdMib(pHost, pCommunity, dwDevIndex, this);
  196. if ( pStdMib ) {
  197. dwRetCode = pStdMib->GetDeviceStatus();
  198. delete pStdMib;
  199. } else {
  200. dwRetCode = ERROR_OUTOFMEMORY;
  201. }
  202. ExitCSection();
  203. return (dwRetCode);
  204. } // ::GetDeviceStatus()
  205. ///////////////////////////////////////////////////////////////////////////////
  206. // GetJobStatus --
  207. // Error Codes:
  208. // Returns the mapped printer error code to the spooler error code
  209. DWORD
  210. CTcpMib::GetJobStatus( LPCSTR in pHost,
  211. LPCSTR in pCommunity,
  212. DWORD in dwDevIndex)
  213. {
  214. DWORD dwRetCode = NO_ERROR;
  215. EnterCSection();
  216. CStdMib *pStdMib = new CStdMib(pHost, pCommunity, dwDevIndex, this);
  217. if ( pStdMib ) {
  218. dwRetCode = pStdMib->GetJobStatus();
  219. delete pStdMib;
  220. } else {
  221. dwRetCode = ERROR_OUTOFMEMORY;
  222. }
  223. ExitCSection();
  224. return (dwRetCode);
  225. } // ::GetJobType()
  226. ///////////////////////////////////////////////////////////////////////////////
  227. // GetDeviceAddress -- gets the hardware address of the device
  228. // ERROR CODES:
  229. // NO_ERROR if successful
  230. // ERROR_NOT_ENOUGH_MEMORY if memory allocation failes
  231. // ERROR_INVALID_HANDLE if can't build the variable bindings
  232. // SNMP_ERRORSTATUS_TOOBIG if the packet returned is big
  233. // SNMP_ERRORSTATUS_NOSUCHNAME if the OID isn't supported
  234. // SNMP_ERRORSTATUS_BADVALUE
  235. // SNMP_ERRORSTATUS_READONLY
  236. // SNMP_ERRORSTATUS_GENERR
  237. // SNMP_MGMTAPI_TIMEOUT -- set by GetLastError()
  238. // SNMP_MGMTAPI_SELECT_FDERRORS -- set by GetLastError()
  239. DWORD
  240. CTcpMib::GetDeviceHWAddress( LPCSTR in pHost,
  241. LPCSTR in pCommunity,
  242. DWORD in dwDevIndex,
  243. DWORD in dwSize, // Size in characters of the HWAddress returned
  244. LPTSTR out psztHWAddress
  245. )
  246. {
  247. DWORD dwRetCode = NO_ERROR;
  248. EnterCSection();
  249. // instantiate the CStdMib::GetDeviceAddress()
  250. CStdMib *pStdMib = new CStdMib(pHost, pCommunity, dwDevIndex, this);
  251. if ( pStdMib ) {
  252. dwRetCode = pStdMib->GetDeviceHWAddress(psztHWAddress, dwSize);
  253. delete pStdMib;
  254. } else {
  255. dwRetCode = ERROR_OUTOFMEMORY;
  256. }
  257. ExitCSection();
  258. return (dwRetCode);
  259. } // ::GetDeviceAddress()
  260. ///////////////////////////////////////////////////////////////////////////////
  261. // GetDeviceInfo -- gets the device description
  262. // ERROR CODES
  263. // NO_ERROR if successful
  264. // ERROR_NOT_ENOUGH_MEMORY if memory allocation failes
  265. // ERROR_INVALID_HANDLE if can't build the variable bindings
  266. // SNMP_ERRORSTATUS_TOOBIG if the packet returned is big
  267. // SNMP_ERRORSTATUS_NOSUCHNAME if the OID isn't supported
  268. // SNMP_ERRORSTATUS_BADVALUE
  269. // SNMP_ERRORSTATUS_READONLY
  270. // SNMP_ERRORSTATUS_GENERR
  271. // SNMP_MGMTAPI_TIMEOUT -- set by GetLastError()
  272. // SNMP_MGMTAPI_SELECT_FDERRORS -- set by GetLastError()
  273. DWORD
  274. CTcpMib::GetDeviceName( LPCSTR in pHost,
  275. LPCSTR in pCommunity,
  276. DWORD in dwDevIndex,
  277. DWORD in dwSize, // Size in characters of the description returned
  278. LPTSTR out psztDescription)
  279. {
  280. DWORD dwRetCode = NO_ERROR;
  281. EnterCSection();
  282. // instantiate the CStdMib::GetDeviceInfo()
  283. CStdMib *pStdMib = new CStdMib(pHost, pCommunity, dwDevIndex, this);
  284. if ( pStdMib ) {
  285. dwRetCode = pStdMib->GetDeviceName(psztDescription, dwSize);
  286. delete pStdMib;
  287. } else {
  288. dwRetCode = ERROR_OUTOFMEMORY;
  289. }
  290. ExitCSection();
  291. return (dwRetCode);
  292. } // ::GetDeviceAddress()
  293. ///////////////////////////////////////////////////////////////////////////////
  294. // SnmpGet -- given a set of OIDs & a buffer to get the results in, it returns
  295. // the results of the SnmpGet.
  296. //
  297. // Note: This calls directly into the SnmpMgr APIs
  298. DWORD
  299. CTcpMib::SnmpGet( LPCSTR in pHost,
  300. LPCSTR in pCommunity,
  301. DWORD in dwDevIndex,
  302. AsnObjectIdentifier in *pMibObjId,
  303. RFC1157VarBindList out *pVarBindList)
  304. {
  305. DWORD dwRetCode = NO_ERROR;
  306. EnterCSection();
  307. CSnmpMgr *pSnmpMgr = new CSnmpMgr(pHost, pCommunity, dwDevIndex, pMibObjId, pVarBindList);
  308. if ( pSnmpMgr ) {
  309. if ( (dwRetCode = pSnmpMgr->GetLastError()) != SNMPAPI_NOERROR ) {
  310. dwRetCode = ERROR_SNMPAPI_ERROR;
  311. goto cleanup;
  312. }
  313. if ( (dwRetCode = pSnmpMgr->Get(pVarBindList)) != NO_ERROR ) {
  314. dwRetCode = ERROR_SNMPAPI_ERROR;
  315. goto cleanup;
  316. }
  317. } else {
  318. dwRetCode = ERROR_OUTOFMEMORY;
  319. }
  320. cleanup:
  321. if ( pSnmpMgr )
  322. delete pSnmpMgr;
  323. ExitCSection();
  324. return (dwRetCode);
  325. } // ::SnmpGet()
  326. ///////////////////////////////////////////////////////////////////////////////
  327. // SnmpGet -- given a set of OIDs & a buffer to get the results in, it returns
  328. // the results of the SnmpGet.
  329. //
  330. // Note: This calls directly into the SnmpMgr APIs
  331. DWORD
  332. CTcpMib::SnmpGet( LPCSTR in pHost,
  333. LPCSTR in pCommunity,
  334. DWORD in dwDevIndex,
  335. RFC1157VarBindList inout *pVarBindList)
  336. {
  337. DWORD dwRetCode = NO_ERROR;
  338. EnterCSection();
  339. CSnmpMgr *pSnmpMgr = new CSnmpMgr(pHost, pCommunity, dwDevIndex);
  340. if ( pSnmpMgr ) {
  341. if ( (dwRetCode = pSnmpMgr->GetLastError()) != SNMPAPI_NOERROR ) {
  342. dwRetCode = ERROR_SNMPAPI_ERROR;
  343. goto cleanup;
  344. }
  345. if ( (dwRetCode = pSnmpMgr->Get(pVarBindList)) != NO_ERROR ) {
  346. dwRetCode = ERROR_SNMPAPI_ERROR;
  347. goto cleanup;
  348. }
  349. } else {
  350. dwRetCode = ERROR_OUTOFMEMORY;
  351. }
  352. cleanup:
  353. if( pSnmpMgr )
  354. delete pSnmpMgr;
  355. ExitCSection();
  356. return (dwRetCode);
  357. } // ::SnmpGet()
  358. ///////////////////////////////////////////////////////////////////////////////
  359. // SnmpGetNext -- given a set of OIDs & a buffer to get the results in, it returns
  360. // the results of the SnmpGetNext.
  361. //
  362. // Note: This calls directly into the SnmpMgr APIs
  363. DWORD
  364. CTcpMib::SnmpGetNext( LPCSTR in pHost,
  365. LPCSTR in pCommunity,
  366. DWORD in dwDevIndex,
  367. AsnObjectIdentifier in *pMibObjId,
  368. RFC1157VarBindList out *pVarBindList)
  369. {
  370. DWORD dwRetCode = NO_ERROR;
  371. EnterCSection();
  372. CSnmpMgr *pSnmpMgr = new CSnmpMgr(pHost, pCommunity, dwDevIndex,
  373. pMibObjId, pVarBindList);
  374. if( pSnmpMgr ) {
  375. if ( (dwRetCode = pSnmpMgr->GetLastError()) != SNMPAPI_NOERROR ) {
  376. dwRetCode = ERROR_SNMPAPI_ERROR;
  377. goto cleanup;
  378. }
  379. if ( (dwRetCode = pSnmpMgr->GetNext(pVarBindList)) != NO_ERROR ) {
  380. dwRetCode = ERROR_SNMPAPI_ERROR;
  381. goto cleanup;
  382. }
  383. } else {
  384. dwRetCode = ERROR_OUTOFMEMORY;
  385. }
  386. cleanup:
  387. if ( pSnmpMgr )
  388. delete pSnmpMgr;
  389. ExitCSection();
  390. return (dwRetCode);
  391. } // ::SnmpGetNext()
  392. ///////////////////////////////////////////////////////////////////////////////
  393. // SnmpGetNext -- given a set of OIDs & a buffer to get the results in, it returns
  394. // the results of the SnmpGetNext.
  395. //
  396. // Note: This calls directly into the SnmpMgr APIs
  397. DWORD
  398. CTcpMib::SnmpGetNext( LPCSTR in pHost,
  399. LPCSTR in pCommunity,
  400. DWORD in dwDevIndex,
  401. RFC1157VarBindList inout *pVarBindList)
  402. {
  403. DWORD dwRetCode = NO_ERROR;
  404. EnterCSection();
  405. CSnmpMgr *pSnmpMgr = new CSnmpMgr(pHost, pCommunity, dwDevIndex);
  406. if ( pSnmpMgr ) {
  407. if ( (dwRetCode = pSnmpMgr->GetLastError()) != SNMPAPI_NOERROR ) {
  408. dwRetCode = ERROR_SNMPAPI_ERROR;
  409. goto cleanup;
  410. }
  411. if ( (dwRetCode = pSnmpMgr->GetNext(pVarBindList)) != NO_ERROR ) {
  412. dwRetCode = ERROR_SNMPAPI_ERROR;
  413. goto cleanup;
  414. }
  415. } else {
  416. dwRetCode = ERROR_OUTOFMEMORY;
  417. }
  418. cleanup:
  419. if ( pSnmpMgr )
  420. delete pSnmpMgr;
  421. ExitCSection();
  422. return (dwRetCode);
  423. } // ::SnmpGetNext()
  424. ///////////////////////////////////////////////////////////////////////////////
  425. // SnmpWalk -- given a set of OIDs & a buffer to get the results in, it returns
  426. // the results of the SnmpWalk.
  427. //
  428. // Note: This calls directly into the SnmpMgr APIs
  429. DWORD
  430. CTcpMib::SnmpWalk( LPCSTR in pHost,
  431. LPCSTR in pCommunity,
  432. DWORD in dwDevIndex,
  433. AsnObjectIdentifier in *pMibObjId,
  434. RFC1157VarBindList out *pVarBindList)
  435. {
  436. DWORD dwRetCode = NO_ERROR;
  437. EnterCSection();
  438. CSnmpMgr *pSnmpMgr = new CSnmpMgr(pHost, pCommunity, dwDevIndex,
  439. pMibObjId, pVarBindList);
  440. if( pSnmpMgr ) {
  441. if ( (dwRetCode = pSnmpMgr->GetLastError()) != SNMPAPI_NOERROR ) {
  442. dwRetCode = ERROR_SNMPAPI_ERROR;
  443. goto cleanup;
  444. }
  445. if ( (dwRetCode = pSnmpMgr->Walk(pVarBindList)) != NO_ERROR ) {
  446. dwRetCode = ERROR_SNMPAPI_ERROR;
  447. goto cleanup;
  448. }
  449. } else {
  450. dwRetCode = ERROR_OUTOFMEMORY;
  451. }
  452. cleanup:
  453. if ( pSnmpMgr )
  454. delete pSnmpMgr;
  455. ExitCSection();
  456. return (dwRetCode);
  457. } // ::SnmpWalk()
  458. ///////////////////////////////////////////////////////////////////////////////
  459. // SnmpWalk -- given a set of OIDs & a buffer to get the results in, it returns
  460. // the results of the SnmpWalk.
  461. //
  462. // Note: This calls directly into the SnmpMgr APIs
  463. DWORD
  464. CTcpMib::SnmpWalk( LPCSTR in pHost,
  465. LPCSTR in pCommunity,
  466. DWORD in dwDevIndex,
  467. RFC1157VarBindList inout *pVarBindList)
  468. {
  469. DWORD dwRetCode = NO_ERROR;
  470. EnterCSection();
  471. CSnmpMgr *pSnmpMgr = new CSnmpMgr(pHost, pCommunity, dwDevIndex);
  472. if( pSnmpMgr ) {
  473. if ( (dwRetCode = pSnmpMgr->GetLastError()) != SNMPAPI_NOERROR ) {
  474. dwRetCode = ERROR_SNMPAPI_ERROR;
  475. goto cleanup;
  476. }
  477. if ( (dwRetCode = pSnmpMgr->Walk(pVarBindList)) != NO_ERROR ) {
  478. dwRetCode = ERROR_SNMPAPI_ERROR;
  479. goto cleanup;
  480. }
  481. } else {
  482. dwRetCode = ERROR_OUTOFMEMORY;
  483. }
  484. cleanup:
  485. if ( pSnmpMgr )
  486. delete pSnmpMgr;
  487. ExitCSection();
  488. return (dwRetCode);
  489. } // ::SnmpWalk()
  490. ///////////////////////////////////////////////////////////////////////////////
  491. // SNMPToPrinterStatus -- Maps the received device error to the printer
  492. // error codes.
  493. // Return Values:
  494. // Spooler device error codes
  495. DWORD
  496. CTcpMib::SNMPToPrinterStatus( const DWORD in dwStatus)
  497. {
  498. DWORD dwRetCode = NO_ERROR;
  499. switch (dwStatus)
  500. {
  501. case ASYNCH_STATUS_UNKNOWN:
  502. dwRetCode = PRINTER_STATUS_NOT_AVAILABLE;
  503. break;
  504. case ASYNCH_PRINTER_ERROR:
  505. dwRetCode = PRINTER_STATUS_ERROR;
  506. break;
  507. case ASYNCH_DOOR_OPEN:
  508. dwRetCode = PRINTER_STATUS_DOOR_OPEN;
  509. break;
  510. case ASYNCH_WARMUP:
  511. dwRetCode = PRINTER_STATUS_WARMING_UP;
  512. break;
  513. case ASYNCH_RESET:
  514. case ASYNCH_INITIALIZING:
  515. dwRetCode = PRINTER_STATUS_INITIALIZING;
  516. break;
  517. case ASYNCH_OUTPUT_BIN_FULL:
  518. dwRetCode = PRINTER_STATUS_OUTPUT_BIN_FULL;
  519. break;
  520. case ASYNCH_PAPER_JAM:
  521. dwRetCode = PRINTER_STATUS_PAPER_JAM;
  522. break;
  523. case ASYNCH_TONER_GONE:
  524. dwRetCode = PRINTER_STATUS_NO_TONER;
  525. break;
  526. case ASYNCH_MANUAL_FEED:
  527. dwRetCode = PRINTER_STATUS_MANUAL_FEED;
  528. break;
  529. case ASYNCH_PAPER_OUT:
  530. dwRetCode = PRINTER_STATUS_PAPER_OUT;
  531. break;
  532. case ASYNCH_OFFLINE:
  533. dwRetCode = PRINTER_STATUS_OFFLINE;
  534. break;
  535. case ASYNCH_INTERVENTION:
  536. dwRetCode = PRINTER_STATUS_USER_INTERVENTION;
  537. break;
  538. case ASYNCH_TONER_LOW:
  539. dwRetCode = PRINTER_STATUS_TONER_LOW;
  540. break;
  541. case ASYNCH_PRINTING:
  542. dwRetCode = PRINTER_STATUS_PRINTING;
  543. break;
  544. case ASYNCH_BUSY:
  545. dwRetCode = PRINTER_STATUS_BUSY;
  546. break;
  547. case ASYNCH_ONLINE:
  548. dwRetCode = NO_ERROR;
  549. break;
  550. default:
  551. dwRetCode = PRINTER_STATUS_NOT_AVAILABLE;
  552. }
  553. return dwRetCode;
  554. } // SNMPToPrinterStatus()
  555. ///////////////////////////////////////////////////////////////////////////////
  556. // SNMPToPortStatus -- Maps the received device error to the printer
  557. // error codes.
  558. // Return Values:
  559. // Spooler device error codes
  560. BOOL
  561. CTcpMib::SNMPToPortStatus( const DWORD in dwStatus, PPORT_INFO_3 pPortInfo )
  562. {
  563. DWORD dwRetCode = NO_ERROR;
  564. pPortInfo->dwStatus = 0;
  565. pPortInfo->pszStatus = NULL;
  566. pPortInfo->dwSeverity = PORT_STATUS_TYPE_ERROR;
  567. switch (dwStatus)
  568. {
  569. case ASYNCH_DOOR_OPEN:
  570. pPortInfo->dwStatus = PORT_STATUS_DOOR_OPEN;
  571. pPortInfo->dwSeverity = PORT_STATUS_TYPE_ERROR;
  572. break;
  573. case ASYNCH_WARMUP:
  574. pPortInfo->dwStatus = PORT_STATUS_WARMING_UP;
  575. pPortInfo->dwSeverity = PORT_STATUS_TYPE_INFO;
  576. break;
  577. case ASYNCH_OUTPUT_BIN_FULL:
  578. pPortInfo->dwStatus = PORT_STATUS_OUTPUT_BIN_FULL;
  579. pPortInfo->dwSeverity = PORT_STATUS_TYPE_WARNING;
  580. break;
  581. case ASYNCH_PAPER_JAM:
  582. pPortInfo->dwStatus = PORT_STATUS_PAPER_JAM;
  583. pPortInfo->dwSeverity = PORT_STATUS_TYPE_ERROR;
  584. break;
  585. case ASYNCH_TONER_GONE:
  586. pPortInfo->dwStatus = PORT_STATUS_NO_TONER;
  587. pPortInfo->dwSeverity = PORT_STATUS_TYPE_ERROR;
  588. break;
  589. case ASYNCH_MANUAL_FEED:
  590. pPortInfo->dwStatus = PORT_STATUS_PAPER_PROBLEM;
  591. pPortInfo->dwSeverity = PORT_STATUS_TYPE_WARNING;
  592. break;
  593. case ASYNCH_PAPER_OUT:
  594. pPortInfo->dwStatus = PORT_STATUS_PAPER_OUT;
  595. pPortInfo->dwSeverity = PORT_STATUS_TYPE_ERROR;
  596. break;
  597. case ASYNCH_PRINTER_ERROR:
  598. case ASYNCH_INTERVENTION:
  599. case ASYNCH_OFFLINE:
  600. pPortInfo->dwStatus = PORT_STATUS_OFFLINE;
  601. pPortInfo->dwSeverity = PORT_STATUS_TYPE_ERROR;
  602. break;
  603. case ASYNCH_TONER_LOW:
  604. pPortInfo->dwStatus = PORT_STATUS_TONER_LOW;
  605. pPortInfo->dwSeverity = PORT_STATUS_TYPE_WARNING;
  606. break;
  607. case ASYNCH_STATUS_UNKNOWN:
  608. case ASYNCH_POWERSAVE_MODE:
  609. case ASYNCH_RESET:
  610. case ASYNCH_INITIALIZING:
  611. case ASYNCH_PRINTING:
  612. case ASYNCH_BUSY:
  613. case ASYNCH_ONLINE:
  614. default:
  615. pPortInfo->dwStatus = 0;
  616. pPortInfo->dwSeverity = PORT_STATUS_TYPE_INFO;
  617. break;
  618. }
  619. return dwRetCode;
  620. } // ::SNMPStatusToPortStatus()