Back to index

lightning-sunbird  0.9+nobinonly
Defines | Functions | Variables
devslot.c File Reference
#include "nssckepv.h"
#include "devm.h"
#include "ckhelper.h"

Go to the source code of this file.

Defines

#define NSSSLOT_TOKEN_DELAY_TIME   1
#define NSSSLOT_IS_FRIENDLY(slot)   (slot->base.flags & NSSSLOT_FLAGS_FRIENDLY)

Functions

NSS_IMPLEMENT PRStatus nssSlot_Destroy (NSSSlot *slot)
void nssSlot_EnterMonitor (NSSSlot *slot)
void nssSlot_ExitMonitor (NSSSlot *slot)
NSS_IMPLEMENT void NSSSlot_Destroy (NSSSlot *slot)
NSS_IMPLEMENT NSSSlot * nssSlot_AddRef (NSSSlot *slot)
NSS_IMPLEMENT NSSUTF8nssSlot_GetName (NSSSlot *slot)
NSS_IMPLEMENT NSSUTF8nssSlot_GetTokenName (NSSSlot *slot)
NSS_IMPLEMENT void nssSlot_ResetDelay (NSSSlot *slot)
static PRBool within_token_delay_period (NSSSlot *slot)
NSS_IMPLEMENT PRBool nssSlot_IsTokenPresent (NSSSlot *slot)
NSS_IMPLEMENT voidnssSlot_GetCryptokiEPV (NSSSlot *slot)
NSS_IMPLEMENT NSSToken * nssSlot_GetToken (NSSSlot *slot)
NSS_IMPLEMENT PRStatus nssSession_EnterMonitor (nssSession *s)
NSS_IMPLEMENT PRStatus nssSession_ExitMonitor (nssSession *s)
NSS_EXTERN PRBool nssSession_IsReadWrite (nssSession *s)

Variables

static PRIntervalTime s_token_delay_time = 0
static const CK_FLAGS s_ck_readonly_flags = CKF_SERIAL_SESSION

Define Documentation

#define NSSSLOT_IS_FRIENDLY (   slot)    (slot->base.flags & NSSSLOT_FLAGS_FRIENDLY)

Definition at line 58 of file devslot.c.

Definition at line 54 of file devslot.c.


Function Documentation

Definition at line 269 of file devslot.c.

{
    if (s->lock) PZ_Lock(s->lock);
    return PR_SUCCESS;
}

Definition at line 278 of file devslot.c.

{
    return (s->lock) ? PZ_Unlock(s->lock) : PR_SUCCESS;
}

Definition at line 286 of file devslot.c.

{
    return s->isRW;
}
NSS_IMPLEMENT NSSSlot* nssSlot_AddRef ( NSSSlot *  slot)

Definition at line 106 of file devslot.c.

{
    PR_AtomicIncrement(&slot->base.refCount);
    return slot;
}
NSS_IMPLEMENT PRStatus nssSlot_Destroy ( NSSSlot *  slot)

Definition at line 68 of file devslot.c.

{
    if (slot) {
       if (PR_AtomicDecrement(&slot->base.refCount) == 0) {
           PZ_DestroyLock(slot->base.lock);
           return nssArena_Destroy(slot->base.arena);
       }
    }
    return PR_SUCCESS;
}
NSS_IMPLEMENT void NSSSlot_Destroy ( NSSSlot *  slot)

Definition at line 98 of file devslot.c.

Here is the call graph for this function:

void nssSlot_EnterMonitor ( NSSSlot *  slot)

Definition at line 82 of file devslot.c.

{
    if (slot->lock) {
       PZ_Lock(slot->lock);
    }
}
void nssSlot_ExitMonitor ( NSSSlot *  slot)

Definition at line 90 of file devslot.c.

{
    if (slot->lock) {
       PZ_Unlock(slot->lock);
    }
}

Definition at line 250 of file devslot.c.

{
    return slot->epv;
}
NSS_IMPLEMENT NSSUTF8* nssSlot_GetName ( NSSSlot *  slot)

Definition at line 115 of file devslot.c.

{
    return slot->base.name;
}
NSS_IMPLEMENT NSSToken* nssSlot_GetToken ( NSSSlot *  slot)

Definition at line 258 of file devslot.c.

{
    if (nssSlot_IsTokenPresent(slot)) {
       return nssToken_AddRef(slot->token);
    }
    return (NSSToken *)NULL;
}

Definition at line 123 of file devslot.c.

{
    return nssToken_GetName(slot->token);
}

Definition at line 156 of file devslot.c.

{
    CK_RV ckrv;
    PRStatus nssrv;
    /* XXX */
    nssSession *session;
    CK_SLOT_INFO slotInfo;
    void *epv;
    /* permanent slots are always present */
    if (nssSlot_IsPermanent(slot)) {
       return PR_TRUE;
    }
    /* avoid repeated calls to check token status within set interval */
    if (within_token_delay_period(slot)) {
       return (PRBool)((slot->ckFlags & CKF_TOKEN_PRESENT) != 0);
    }

    /* First obtain the slot info */
    epv = slot->epv;
    if (!epv) {
       return PR_FALSE;
    }
    nssSlot_EnterMonitor(slot);
    ckrv = CKAPI(epv)->C_GetSlotInfo(slot->slotID, &slotInfo);
    nssSlot_ExitMonitor(slot);
    if (ckrv != CKR_OK) {
       slot->token->base.name[0] = 0; /* XXX */
       return PR_FALSE;
    }
    slot->ckFlags = slotInfo.flags;
    /* check for the presence of the token */
    if ((slot->ckFlags & CKF_TOKEN_PRESENT) == 0) {
       if (!slot->token) {
           /* token was ne'er present */
           return PR_FALSE;
       }
       session = nssToken_GetDefaultSession(slot->token);
       nssSession_EnterMonitor(session);
       /* token is not present */
       if (session->handle != CK_INVALID_SESSION) {
           /* session is valid, close and invalidate it */
           CKAPI(epv)->C_CloseSession(session->handle);
           session->handle = CK_INVALID_SESSION;
       }
       nssSession_ExitMonitor(session);
       if (slot->token->base.name[0] != 0) {
           /* notify the high-level cache that the token is removed */
           slot->token->base.name[0] = 0; /* XXX */
           nssToken_NotifyCertsNotVisible(slot->token);
       }
       slot->token->base.name[0] = 0; /* XXX */
       /* clear the token cache */
       nssToken_Remove(slot->token);
       return PR_FALSE;
    }
    /* token is present, use the session info to determine if the card
     * has been removed and reinserted.
     */
    session = nssToken_GetDefaultSession(slot->token);
    nssSession_EnterMonitor(session);
    if (session->handle != CK_INVALID_SESSION) {
       CK_SESSION_INFO sessionInfo;
       ckrv = CKAPI(epv)->C_GetSessionInfo(session->handle, &sessionInfo);
       if (ckrv != CKR_OK) {
           /* session is screwy, close and invalidate it */
           CKAPI(epv)->C_CloseSession(session->handle);
           session->handle = CK_INVALID_SESSION;
       }
    }
    nssSession_ExitMonitor(session);
    /* token not removed, finished */
    if (session->handle != CK_INVALID_SESSION) {
       return PR_TRUE;
    } else {
       /* the token has been removed, and reinserted, or the slot contains
        * a token it doesn't recognize. invalidate all the old
        * information we had on this token, if we can't refresh, clear
        * the present flag */
       nssToken_NotifyCertsNotVisible(slot->token);
       nssToken_Remove(slot->token);
       /* token has been removed, need to refresh with new session */
       nssrv = nssSlot_Refresh(slot);
       if (nssrv != PR_SUCCESS) {
           slot->token->base.name[0] = 0; /* XXX */
           slot->ckFlags &= ~CKF_TOKEN_PRESENT;
           return PR_FALSE;
       }
       return PR_TRUE;
    }
}
NSS_IMPLEMENT void nssSlot_ResetDelay ( NSSSlot *  slot)

Definition at line 131 of file devslot.c.

{
    slot->lastTokenPing = 0;
}
static PRBool within_token_delay_period ( NSSSlot *  slot) [static]

Definition at line 139 of file devslot.c.

{
    PRIntervalTime time, lastTime;
    /* Set the delay time for checking the token presence */
    if (s_token_delay_time == 0) {
       s_token_delay_time = PR_SecondsToInterval(NSSSLOT_TOKEN_DELAY_TIME);
    }
    time = PR_IntervalNow();
    lastTime = slot->lastTokenPing;
    if ((lastTime) && ((time - lastTime) < s_token_delay_time)) {
       return PR_TRUE;
    }
    slot->lastTokenPing = time;
    return PR_FALSE;
}

Here is the caller graph for this function:


Variable Documentation

Definition at line 65 of file devslot.c.

Definition at line 62 of file devslot.c.