Logo Search packages:      
Sourcecode: pcsc-lite version File versions

LONG SCardListReaderGroups ( SCARDCONTEXT  hContext,
LPSTR  mszGroups,
LPDWORD  pcchGroups 
)

This function returns a list of currently available reader groups on the system. mszGroups is a pointer to a character string that is allocated by the application. If the application sends mszGroups as NULL then this function will return the size of the buffer needed to allocate in pcchGroups.

The group names is a multi-string and separated by a nul character ('\0') and ended by a double nul character like "SCard$DefaultReaders\\0Group 2\\0\\0".

If *pcchGroups is equal to SCARD_AUTOALLOCATE then the function will allocate itself the needed memory. Use SCardFreeMemory() to release it.

Parameters:
[in] hContext Connection context to the PC/SC Resource Manager.
[out] mszGroups List of groups to list readers.
pcchGroups [inout] Size of multi-string buffer including NUL's.
Returns:
Error code.
Return values:
SCARD_S_SUCCESS Successful (SCARD_S_SUCCESS)
SCARD_E_INSUFFICIENT_BUFFER Reader buffer not large enough (SCARD_E_INSUFFICIENT_BUFFER)
SCARD_E_INVALID_HANDLE Invalid Scope Handle (SCARD_E_INVALID_HANDLE)
SCARD_E_NO_SERVICE The server is not runing (SCARD_E_NO_SERVICE)
 SCARDCONTEXT hContext;
 LPSTR mszGroups;
 DWORD dwGroups;
 LONG rv;
 ...
 rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext);
 rv = SCardListReaderGroups(hContext, NULL, &dwGroups);
 mszGroups = malloc(sizeof(char)*dwGroups);
 rv = SCardListReaderGroups(hContext, mszGroups, &dwGroups);

 SCARDCONTEXT hContext;
 LPSTR mszGroups;
 DWORD dwGroups;
 LONG rv;
 ...
 rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext);
 dwGroups = SCARD_AUTOALLOCATE;
 rv = SCardListReaderGroups(hContext, (LPSTR)&mszGroups, &dwGroups);
 rv = SCardFreeMemory(hContext, mszGroups);

Definition at line 3359 of file winscard_clnt.c.

References psContextMap, SCARD_AUTOALLOCATE, SCARD_E_INSUFFICIENT_BUFFER, SCARD_E_INVALID_HANDLE, SCARD_E_INVALID_PARAMETER, SCARD_E_NO_MEMORY, SCARD_S_SUCCESS, SCardCheckDaemonAvailability(), and SCardGetContextIndice().

{
      LONG rv = SCARD_S_SUCCESS;
      LONG dwContextIndex;
      char *buf = NULL;

      PROFILE_START

      /* Multi-string with two trailing \0 */
      const char ReaderGroup[] = "SCard$DefaultReaders\0";
      const int dwGroups = sizeof(ReaderGroup);

      rv = SCardCheckDaemonAvailability();
      if (rv != SCARD_S_SUCCESS)
            return rv;

      /*
       * Make sure this context has been opened
       */
      dwContextIndex = SCardGetContextIndice(hContext);
      if (dwContextIndex == -1)
            return SCARD_E_INVALID_HANDLE;

      (void)SYS_MutexLock(psContextMap[dwContextIndex].mMutex);

      /* check the context is still opened */
      dwContextIndex = SCardGetContextIndice(hContext);
      if (dwContextIndex == -1)
            /* the context is now invalid
             * -> another thread may have called SCardReleaseContext
             * -> so the mMutex has been unlocked */
            return SCARD_E_INVALID_HANDLE;

      if (SCARD_AUTOALLOCATE == *pcchGroups)
      {
            buf = malloc(dwGroups);
            if (NULL == buf)
            {
                  rv = SCARD_E_NO_MEMORY;
                  goto end;
            }
            if (NULL == mszGroups)
            {
                  rv = SCARD_E_INVALID_PARAMETER;
                  goto end;
            }
            *(char **)mszGroups = buf;
      }
      else
      {
            buf = mszGroups;

            if ((NULL != mszGroups) && (*pcchGroups < dwGroups))
            {
                  rv = SCARD_E_INSUFFICIENT_BUFFER;
                  goto end;
            }
      }

      if (buf)
            memcpy(buf, ReaderGroup, dwGroups);

end:
      *pcchGroups = dwGroups;

      (void)SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex);

      PROFILE_END(rv)

      return rv;
}


Generated by  Doxygen 1.6.0   Back to index