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

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

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]hContextConnection context to the PC/SC Resource Manager.
[out]mszGroupsList of groups to list readers.
[in,out]pcchGroupsSize of multi-string buffer including NUL's.
Returns:
Error code.
Return values:
SCARD_S_SUCCESSSuccessful (SCARD_S_SUCCESS)
SCARD_E_INSUFFICIENT_BUFFERReader buffer not large enough (SCARD_E_INSUFFICIENT_BUFFER)
SCARD_E_INVALID_HANDLEInvalid Scope Handle (SCARD_E_INVALID_HANDLE)
SCARD_E_INVALID_PARAMETERmszGroups is NULL (SCARD_E_INVALID_PARAMETER)
SCARD_E_NO_MEMORYMemory allocation failed (SCARD_E_NO_MEMORY)
SCARD_E_NO_SERVICEThe 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 3150 of file winscard_clnt.c.

References SCARD_AUTOALLOCATE, SCARD_E_INSUFFICIENT_BUFFER, SCARD_E_INVALID_HANDLE, SCARD_E_INVALID_PARAMETER, SCARD_E_NO_MEMORY, SCARD_S_SUCCESS, and SCardGetContext().

{
      LONG rv = SCARD_S_SUCCESS;
      SCONTEXTMAP * currentContextMap;
      char *buf = NULL;

      PROFILE_START

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

      CHECK_SAME_PROCESS

      /*
       * Make sure this context has been opened
       */
      currentContextMap = SCardGetContext(hContext);
      if (NULL == currentContextMap)
            return SCARD_E_INVALID_HANDLE;

      (void)pthread_mutex_lock(currentContextMap->mMutex);

      /* check the context is still opened */
      currentContextMap = SCardGetContext(hContext);
      if (NULL == currentContextMap)
            /* 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)pthread_mutex_unlock(currentContextMap->mMutex);

    PROFILE_END(rv)

      return rv;
}

Here is the call graph for this function:


Generated by  Doxygen 1.6.0   Back to index