Back to index

lightning-sunbird  0.9+nobinonly
Classes | Functions
slot.c File Reference
#include "ck.h"

Go to the source code of this file.

Classes

struct  NSSCKFWSlotStr

Functions

NSS_IMPLEMENT NSSCKFWSlot * nssCKFWSlot_Create (NSSCKFWInstance *fwInstance, NSSCKMDSlot *mdSlot, CK_SLOT_ID slotID, CK_RV *pError)
NSS_IMPLEMENT CK_RV nssCKFWSlot_Destroy (NSSCKFWSlot *fwSlot)
NSS_IMPLEMENT NSSCKMDSlot * nssCKFWSlot_GetMDSlot (NSSCKFWSlot *fwSlot)
NSS_IMPLEMENT NSSCKFWInstance * nssCKFWSlot_GetFWInstance (NSSCKFWSlot *fwSlot)
NSS_IMPLEMENT NSSCKMDInstance * nssCKFWSlot_GetMDInstance (NSSCKFWSlot *fwSlot)
NSS_IMPLEMENT CK_SLOT_ID nssCKFWSlot_GetSlotID (NSSCKFWSlot *fwSlot)
NSS_IMPLEMENT CK_RV nssCKFWSlot_GetSlotDescription (NSSCKFWSlot *fwSlot, CK_CHAR slotDescription[64])
NSS_IMPLEMENT CK_RV nssCKFWSlot_GetManufacturerID (NSSCKFWSlot *fwSlot, CK_CHAR manufacturerID[32])
NSS_IMPLEMENT CK_BBOOL nssCKFWSlot_GetTokenPresent (NSSCKFWSlot *fwSlot)
NSS_IMPLEMENT CK_BBOOL nssCKFWSlot_GetRemovableDevice (NSSCKFWSlot *fwSlot)
NSS_IMPLEMENT CK_BBOOL nssCKFWSlot_GetHardwareSlot (NSSCKFWSlot *fwSlot)
NSS_IMPLEMENT CK_VERSION nssCKFWSlot_GetHardwareVersion (NSSCKFWSlot *fwSlot)
NSS_IMPLEMENT CK_VERSION nssCKFWSlot_GetFirmwareVersion (NSSCKFWSlot *fwSlot)
NSS_IMPLEMENT NSSCKFWToken * nssCKFWSlot_GetToken (NSSCKFWSlot *fwSlot, CK_RV *pError)
NSS_IMPLEMENT void nssCKFWSlot_ClearToken (NSSCKFWSlot *fwSlot)
NSS_IMPLEMENT NSSCKMDSlot * NSSCKFWSlot_GetMDSlot (NSSCKFWSlot *fwSlot)
NSS_IMPLEMENT NSSCKFWInstance * NSSCKFWSlot_GetFWInstance (NSSCKFWSlot *fwSlot)
NSS_IMPLEMENT NSSCKMDInstance * NSSCKFWSlot_GetMDInstance (NSSCKFWSlot *fwSlot)

Class Documentation

struct NSSCKFWSlotStr

Definition at line 84 of file slot.c.

Collaboration diagram for NSSCKFWSlotStr:
Class Members
CK_VERSION firmwareVersion
NSSCKFWInstance * fwInstance
NSSCKFWToken * fwToken
CK_VERSION hardwareVersion
NSSUTF8 * manufacturerID
NSSCKMDInstance * mdInstance
NSSCKMDSlot * mdSlot
NSSCKFWMutex * mutex
NSSUTF8 * slotDescription
CK_SLOT_ID slotID

Function Documentation

NSS_IMPLEMENT void nssCKFWSlot_ClearToken ( NSSCKFWSlot *  fwSlot)

Definition at line 681 of file slot.c.

{
#ifdef NSSDEBUG
  if( CKR_OK != nssCKFWSlot_verifyPointer(fwSlot) ) {
    return;
  }
#endif /* NSSDEBUG */

  if( CKR_OK != nssCKFWMutex_Lock(fwSlot->mutex) ) {
    /* Now what? */
    return;
  }

  fwSlot->fwToken = (NSSCKFWToken *)NULL;
  (void)nssCKFWMutex_Unlock(fwSlot->mutex);
  return;
}
NSS_IMPLEMENT NSSCKFWSlot* nssCKFWSlot_Create ( NSSCKFWInstance *  fwInstance,
NSSCKMDSlot *  mdSlot,
CK_SLOT_ID  slotID,
CK_RV pError 
)

Definition at line 163 of file slot.c.

{
  NSSCKFWSlot *fwSlot;
  NSSCKMDInstance *mdInstance;
  NSSArena *arena;

#ifdef NSSDEBUG
  if( (CK_RV *)NULL == pError ) {
    return (NSSCKFWSlot *)NULL;
  }

  *pError = nssCKFWInstance_verifyPointer(fwInstance);
  if( CKR_OK != *pError ) {
    return (NSSCKFWSlot *)NULL;
  }
#endif /* NSSDEBUG */

  mdInstance = nssCKFWInstance_GetMDInstance(fwInstance);
  if( (NSSCKMDInstance *)NULL == mdInstance ) {
    *pError = CKR_GENERAL_ERROR;
    return (NSSCKFWSlot *)NULL;
  }

  arena = nssCKFWInstance_GetArena(fwInstance, pError);
  if( (NSSArena *)NULL == arena ) {
    if( CKR_OK == *pError ) {
      *pError = CKR_GENERAL_ERROR;
    }
  }

  fwSlot = nss_ZNEW(arena, NSSCKFWSlot);
  if( (NSSCKFWSlot *)NULL == fwSlot ) {
    *pError = CKR_HOST_MEMORY;
    return (NSSCKFWSlot *)NULL;
  }

  fwSlot->mdSlot = mdSlot;
  fwSlot->fwInstance = fwInstance;
  fwSlot->mdInstance = mdInstance;
  fwSlot->slotID = slotID;

  fwSlot->mutex = nssCKFWInstance_CreateMutex(fwInstance, arena, pError);
  if( (NSSCKFWMutex *)NULL == fwSlot->mutex ) {
    if( CKR_OK == *pError ) {
      *pError = CKR_GENERAL_ERROR;
    }
    (void)nss_ZFreeIf(fwSlot);
    return (NSSCKFWSlot *)NULL;
  }

  if( (void *)NULL != (void *)mdSlot->Initialize ) {
    *pError = CKR_OK;
    *pError = mdSlot->Initialize(mdSlot, fwSlot, mdInstance, fwInstance);
    if( CKR_OK != *pError ) {
      (void)nssCKFWMutex_Destroy(fwSlot->mutex);
      (void)nss_ZFreeIf(fwSlot);
      return (NSSCKFWSlot *)NULL;
    }
  }

#ifdef DEBUG
  *pError = slot_add_pointer(fwSlot);
  if( CKR_OK != *pError ) {
    if( (void *)NULL != (void *)mdSlot->Destroy ) {
      mdSlot->Destroy(mdSlot, fwSlot, mdInstance, fwInstance);
    }

    (void)nssCKFWMutex_Destroy(fwSlot->mutex);
    (void)nss_ZFreeIf(fwSlot);
    return (NSSCKFWSlot *)NULL;
  }
#endif /* DEBUG */

  return fwSlot;
}
NSS_IMPLEMENT CK_RV nssCKFWSlot_Destroy ( NSSCKFWSlot *  fwSlot)

Definition at line 250 of file slot.c.

{
  CK_RV error = CKR_OK;

#ifdef NSSDEBUG
  error = nssCKFWSlot_verifyPointer(fwSlot);
  if( CKR_OK != error ) {
    return error;
  }
#endif /* NSSDEBUG */
  if (fwSlot->fwToken) {
    nssCKFWToken_Destroy(fwSlot->fwToken);
  }

  (void)nssCKFWMutex_Destroy(fwSlot->mutex);

  if( (void *)NULL != (void *)fwSlot->mdSlot->Destroy ) {
    fwSlot->mdSlot->Destroy(fwSlot->mdSlot, fwSlot, 
      fwSlot->mdInstance, fwSlot->fwInstance);
  }

#ifdef DEBUG
  error = slot_remove_pointer(fwSlot);
#endif /* DEBUG */
  (void)nss_ZFreeIf(fwSlot);
  return error;
}

Definition at line 580 of file slot.c.

{
  CK_VERSION rv;

#ifdef NSSDEBUG
  if( CKR_OK != nssCKFWSlot_verifyPointer(fwSlot) ) {
    rv.major = rv.minor = 0;
    return rv;
  }
#endif /* NSSDEBUG */

  if( CKR_OK != nssCKFWMutex_Lock(fwSlot->mutex) ) {
    rv.major = rv.minor = 0;
    return rv;
  }

  if( (0 != fwSlot->firmwareVersion.major) ||
      (0 != fwSlot->firmwareVersion.minor) ) {
    rv = fwSlot->firmwareVersion;
    goto done;
  }

  if( (void *)NULL != (void *)fwSlot->mdSlot->GetFirmwareVersion ) {
    fwSlot->firmwareVersion = fwSlot->mdSlot->GetFirmwareVersion(
      fwSlot->mdSlot, fwSlot, fwSlot->mdInstance, fwSlot->fwInstance);
  } else {
    fwSlot->firmwareVersion.major = 0;
    fwSlot->firmwareVersion.minor = 1;
  }

  rv = fwSlot->firmwareVersion;
 done:
  (void)nssCKFWMutex_Unlock(fwSlot->mutex);
  return rv;
}
NSS_IMPLEMENT NSSCKFWInstance* nssCKFWSlot_GetFWInstance ( NSSCKFWSlot *  fwSlot)

Definition at line 306 of file slot.c.

{
#ifdef NSSDEBUG
  if( CKR_OK != nssCKFWSlot_verifyPointer(fwSlot) ) {
    return (NSSCKFWInstance *)NULL;
  }
#endif /* NSSDEBUG */

  return fwSlot->fwInstance;
}
NSS_IMPLEMENT NSSCKFWInstance* NSSCKFWSlot_GetFWInstance ( NSSCKFWSlot *  fwSlot)

Definition at line 728 of file slot.c.

{
#ifdef DEBUG
  if( CKR_OK != nssCKFWSlot_verifyPointer(fwSlot) ) {
    return (NSSCKFWInstance *)NULL;
  }
#endif /* DEBUG */

  return nssCKFWSlot_GetFWInstance(fwSlot);
}

Definition at line 512 of file slot.c.

{
#ifdef NSSDEBUG
  if( CKR_OK != nssCKFWSlot_verifyPointer(fwSlot) ) {
    return CK_FALSE;
  }
#endif /* NSSDEBUG */

  if( (void *)NULL == (void *)fwSlot->mdSlot->GetHardwareSlot ) {
    return CK_FALSE;
  }

  return fwSlot->mdSlot->GetHardwareSlot(fwSlot->mdSlot, fwSlot,
    fwSlot->mdInstance, fwSlot->fwInstance);
}

Definition at line 536 of file slot.c.

{
  CK_VERSION rv;

#ifdef NSSDEBUG
  if( CKR_OK != nssCKFWSlot_verifyPointer(fwSlot) ) {
    rv.major = rv.minor = 0;
    return rv;
  }
#endif /* NSSDEBUG */

  if( CKR_OK != nssCKFWMutex_Lock(fwSlot->mutex) ) {
    rv.major = rv.minor = 0;
    return rv;
  }

  if( (0 != fwSlot->hardwareVersion.major) ||
      (0 != fwSlot->hardwareVersion.minor) ) {
    rv = fwSlot->hardwareVersion;
    goto done;
  }

  if( (void *)NULL != (void *)fwSlot->mdSlot->GetHardwareVersion ) {
    fwSlot->hardwareVersion = fwSlot->mdSlot->GetHardwareVersion(
      fwSlot->mdSlot, fwSlot, fwSlot->mdInstance, fwSlot->fwInstance);
  } else {
    fwSlot->hardwareVersion.major = 0;
    fwSlot->hardwareVersion.minor = 1;
  }

  rv = fwSlot->hardwareVersion;
 done:
  (void)nssCKFWMutex_Unlock(fwSlot->mutex);
  return rv;
}
NSS_IMPLEMENT CK_RV nssCKFWSlot_GetManufacturerID ( NSSCKFWSlot *  fwSlot,
CK_CHAR  manufacturerID[32] 
)

Definition at line 414 of file slot.c.

{
  CK_RV error = CKR_OK;

#ifdef NSSDEBUG
  if( (CK_CHAR_PTR)NULL == manufacturerID ) {
    return CKR_ARGUMENTS_BAD;
  }

  error = nssCKFWSlot_verifyPointer(fwSlot);
  if( CKR_OK != error ) {
    return error;
  }
#endif /* NSSDEBUG */

  error = nssCKFWMutex_Lock(fwSlot->mutex);
  if( CKR_OK != error ) {
    return error;
  }

  if( (NSSUTF8 *)NULL == fwSlot->manufacturerID ) {
    if( (void *)NULL != (void *)fwSlot->mdSlot->GetManufacturerID ) {
      fwSlot->manufacturerID = fwSlot->mdSlot->GetManufacturerID(
        fwSlot->mdSlot, fwSlot, fwSlot->mdInstance, 
        fwSlot->fwInstance, &error);
      if( ((NSSUTF8 *)NULL == fwSlot->manufacturerID) && (CKR_OK != error) ) {
        goto done;
      }
    } else {
      fwSlot->manufacturerID = (NSSUTF8 *) "";
    }
  }

  (void)nssUTF8_CopyIntoFixedBuffer(fwSlot->manufacturerID, (char *)manufacturerID, 32, ' ');
  error = CKR_OK;

 done:
  (void)nssCKFWMutex_Unlock(fwSlot->mutex);
  return error;
}
NSS_IMPLEMENT NSSCKMDInstance* nssCKFWSlot_GetMDInstance ( NSSCKFWSlot *  fwSlot)

Definition at line 326 of file slot.c.

{
#ifdef NSSDEBUG
  if( CKR_OK != nssCKFWSlot_verifyPointer(fwSlot) ) {
    return (NSSCKMDInstance *)NULL;
  }
#endif /* NSSDEBUG */

  return fwSlot->mdInstance;
}
NSS_IMPLEMENT NSSCKMDInstance* NSSCKFWSlot_GetMDInstance ( NSSCKFWSlot *  fwSlot)

Definition at line 748 of file slot.c.

{
#ifdef DEBUG
  if( CKR_OK != nssCKFWSlot_verifyPointer(fwSlot) ) {
    return (NSSCKMDInstance *)NULL;
  }
#endif /* DEBUG */

  return nssCKFWSlot_GetMDInstance(fwSlot);
}
NSS_IMPLEMENT NSSCKMDSlot* nssCKFWSlot_GetMDSlot ( NSSCKFWSlot *  fwSlot)

Definition at line 286 of file slot.c.

{
#ifdef NSSDEBUG
  if( CKR_OK != nssCKFWSlot_verifyPointer(fwSlot) ) {
    return (NSSCKMDSlot *)NULL;
  }
#endif /* NSSDEBUG */

  return fwSlot->mdSlot;
}
NSS_IMPLEMENT NSSCKMDSlot* NSSCKFWSlot_GetMDSlot ( NSSCKFWSlot *  fwSlot)

Definition at line 708 of file slot.c.

{
#ifdef DEBUG
  if( CKR_OK != nssCKFWSlot_verifyPointer(fwSlot) ) {
    return (NSSCKMDSlot *)NULL;
  }
#endif /* DEBUG */

  return nssCKFWSlot_GetMDSlot(fwSlot);
}

Definition at line 488 of file slot.c.

{
#ifdef NSSDEBUG
  if( CKR_OK != nssCKFWSlot_verifyPointer(fwSlot) ) {
    return CK_FALSE;
  }
#endif /* NSSDEBUG */

  if( (void *)NULL == (void *)fwSlot->mdSlot->GetRemovableDevice ) {
    return CK_FALSE;
  }

  return fwSlot->mdSlot->GetRemovableDevice(fwSlot->mdSlot, fwSlot,
    fwSlot->mdInstance, fwSlot->fwInstance);
}
NSS_IMPLEMENT CK_RV nssCKFWSlot_GetSlotDescription ( NSSCKFWSlot *  fwSlot,
CK_CHAR  slotDescription[64] 
)

Definition at line 364 of file slot.c.

{
  CK_RV error = CKR_OK;

#ifdef NSSDEBUG
  if( (CK_CHAR_PTR)NULL == slotDescription ) {
    return CKR_ARGUMENTS_BAD;
  }

  error = nssCKFWSlot_verifyPointer(fwSlot);
  if( CKR_OK != error ) {
    return error;
  }
#endif /* NSSDEBUG */

  error = nssCKFWMutex_Lock(fwSlot->mutex);
  if( CKR_OK != error ) {
    return error;
  }

  if( (NSSUTF8 *)NULL == fwSlot->slotDescription ) {
    if( (void *)NULL != (void *)fwSlot->mdSlot->GetSlotDescription ) {
      fwSlot->slotDescription = fwSlot->mdSlot->GetSlotDescription(
        fwSlot->mdSlot, fwSlot, fwSlot->mdInstance, 
        fwSlot->fwInstance, &error);
      if( ((NSSUTF8 *)NULL == fwSlot->slotDescription) && (CKR_OK != error) ) {
        goto done;
      }
    } else {
      fwSlot->slotDescription = (NSSUTF8 *) "";
    }
  }

  (void)nssUTF8_CopyIntoFixedBuffer(fwSlot->slotDescription, (char *)slotDescription, 64, ' ');
  error = CKR_OK;

 done:
  (void)nssCKFWMutex_Unlock(fwSlot->mutex);
  return error;
}
NSS_IMPLEMENT CK_SLOT_ID nssCKFWSlot_GetSlotID ( NSSCKFWSlot *  fwSlot)

Definition at line 345 of file slot.c.

{
#ifdef NSSDEBUG
  if( CKR_OK != nssCKFWSlot_verifyPointer(fwSlot) ) {
    return (CK_SLOT_ID)0;
  }
#endif /* NSSDEBUG */

  return fwSlot->slotID;
}
NSS_IMPLEMENT NSSCKFWToken* nssCKFWSlot_GetToken ( NSSCKFWSlot *  fwSlot,
CK_RV pError 
)

Definition at line 624 of file slot.c.

{
  NSSCKMDToken *mdToken;
  NSSCKFWToken *fwToken;

#ifdef NSSDEBUG
  if( (CK_RV *)NULL == pError ) {
    return (NSSCKFWToken *)NULL;
  }

  *pError = nssCKFWSlot_verifyPointer(fwSlot);
  if( CKR_OK != *pError ) {
    return (NSSCKFWToken *)NULL;
  }
#endif /* NSSDEBUG */

  *pError = nssCKFWMutex_Lock(fwSlot->mutex);
  if( CKR_OK != *pError ) {
    return (NSSCKFWToken *)NULL;
  }

  if( (NSSCKFWToken *)NULL == fwSlot->fwToken ) {
    if( (void *)NULL == (void *)fwSlot->mdSlot->GetToken ) {
      *pError = CKR_GENERAL_ERROR;
      fwToken = (NSSCKFWToken *)NULL;
      goto done;
    }

    mdToken = fwSlot->mdSlot->GetToken(fwSlot->mdSlot, fwSlot,
      fwSlot->mdInstance, fwSlot->fwInstance, pError);
    if( (NSSCKMDToken *)NULL == mdToken ) {
      if( CKR_OK == *pError ) {
        *pError = CKR_GENERAL_ERROR;
      }
      return (NSSCKFWToken *)NULL;
    }

    fwToken = nssCKFWToken_Create(fwSlot, mdToken, pError);
    fwSlot->fwToken = fwToken;
  } else {
    fwToken = fwSlot->fwToken;
  }

 done:
  (void)nssCKFWMutex_Unlock(fwSlot->mutex);
  return fwToken;
}

Definition at line 464 of file slot.c.

{
#ifdef NSSDEBUG
  if( CKR_OK != nssCKFWSlot_verifyPointer(fwSlot) ) {
    return CK_FALSE;
  }
#endif /* NSSDEBUG */

  if( (void *)NULL == (void *)fwSlot->mdSlot->GetTokenPresent ) {
    return CK_TRUE;
  }

  return fwSlot->mdSlot->GetTokenPresent(fwSlot->mdSlot, fwSlot,
    fwSlot->mdInstance, fwSlot->fwInstance);
}