1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate #ifndef _PKCS11_SLOT_H 28*7c478bd9Sstevel@tonic-gate #define _PKCS11_SLOT_H 29*7c478bd9Sstevel@tonic-gate 30*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 31*7c478bd9Sstevel@tonic-gate 32*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 33*7c478bd9Sstevel@tonic-gate extern "C" { 34*7c478bd9Sstevel@tonic-gate #endif 35*7c478bd9Sstevel@tonic-gate 36*7c478bd9Sstevel@tonic-gate #include "pkcs11Session.h" 37*7c478bd9Sstevel@tonic-gate 38*7c478bd9Sstevel@tonic-gate #define MECHLIST_SIZE 32 39*7c478bd9Sstevel@tonic-gate 40*7c478bd9Sstevel@tonic-gate /* 41*7c478bd9Sstevel@tonic-gate * Used to pass arguments to child threads for C_WaitForSlotEvent. 42*7c478bd9Sstevel@tonic-gate */ 43*7c478bd9Sstevel@tonic-gate typedef struct wfse_args { 44*7c478bd9Sstevel@tonic-gate 45*7c478bd9Sstevel@tonic-gate CK_FLAGS flags; 46*7c478bd9Sstevel@tonic-gate CK_VOID_PTR pReserved; 47*7c478bd9Sstevel@tonic-gate CK_SLOT_ID slotid; 48*7c478bd9Sstevel@tonic-gate 49*7c478bd9Sstevel@tonic-gate } wfse_args_t; 50*7c478bd9Sstevel@tonic-gate 51*7c478bd9Sstevel@tonic-gate typedef struct pkcs11_slot { 52*7c478bd9Sstevel@tonic-gate 53*7c478bd9Sstevel@tonic-gate CK_SLOT_ID sl_id; /* real slotID from provider */ 54*7c478bd9Sstevel@tonic-gate struct pkcs11_session *sl_sess_list; /* all open sessions */ 55*7c478bd9Sstevel@tonic-gate pthread_mutex_t sl_mutex; /* protects: sl_sess_list, */ 56*7c478bd9Sstevel@tonic-gate /* sl_tid, sl_wfse_state, */ 57*7c478bd9Sstevel@tonic-gate /* and sl_wfse_args */ 58*7c478bd9Sstevel@tonic-gate CK_FUNCTION_LIST_PTR sl_func_list; /* function entry points */ 59*7c478bd9Sstevel@tonic-gate boolean_t sl_enabledpol; /* TRUE if policy for enabled */ 60*7c478bd9Sstevel@tonic-gate CK_MECHANISM_TYPE_PTR sl_pol_mechs; /* policy restricted */ 61*7c478bd9Sstevel@tonic-gate uint_t sl_pol_count; /* policy restricted */ 62*7c478bd9Sstevel@tonic-gate boolean_t sl_norandom; /* TRUE if random is disabled */ 63*7c478bd9Sstevel@tonic-gate void *sl_dldesc; /* from dlopen */ 64*7c478bd9Sstevel@tonic-gate uint_t sl_prov_id; /* set by order read in */ 65*7c478bd9Sstevel@tonic-gate uchar_t sl_wfse_state; /* Used by C_WaitForSlotEvent */ 66*7c478bd9Sstevel@tonic-gate boolean_t sl_no_wfse; /* WaitForSlotEvent not impl */ 67*7c478bd9Sstevel@tonic-gate pthread_t sl_tid; /* Used to track child thread */ 68*7c478bd9Sstevel@tonic-gate wfse_args_t *sl_wfse_args; /* Used for WaitForSlotEvent */ 69*7c478bd9Sstevel@tonic-gate 70*7c478bd9Sstevel@tonic-gate } pkcs11_slot_t; 71*7c478bd9Sstevel@tonic-gate 72*7c478bd9Sstevel@tonic-gate /* 73*7c478bd9Sstevel@tonic-gate * State definitions used for C_WaitForSlotEvent, stored in sl_wfse_state 74*7c478bd9Sstevel@tonic-gate * for each slot. These states are mutually exclusive, ie only one should 75*7c478bd9Sstevel@tonic-gate * be set at a time. 76*7c478bd9Sstevel@tonic-gate */ 77*7c478bd9Sstevel@tonic-gate #define WFSE_CLEAR 0x0 78*7c478bd9Sstevel@tonic-gate #define WFSE_EVENT 0x1 79*7c478bd9Sstevel@tonic-gate #define WFSE_ACTIVE 0x2 80*7c478bd9Sstevel@tonic-gate 81*7c478bd9Sstevel@tonic-gate /* 82*7c478bd9Sstevel@tonic-gate * Dynamically allocated array of slots, indexed by the slotID assigned 83*7c478bd9Sstevel@tonic-gate * by the framework. st_first will be initialized to 1. Only if there 84*7c478bd9Sstevel@tonic-gate * is more than one other slot present, triggering the existence of the 85*7c478bd9Sstevel@tonic-gate * metaslot, with st_first be set to 0. st_last will be set to the 86*7c478bd9Sstevel@tonic-gate * last slotID assigned, also used for looping through the slottable. 87*7c478bd9Sstevel@tonic-gate */ 88*7c478bd9Sstevel@tonic-gate typedef struct pkcs11_slottable { 89*7c478bd9Sstevel@tonic-gate 90*7c478bd9Sstevel@tonic-gate pkcs11_slot_t **st_slots; 91*7c478bd9Sstevel@tonic-gate pthread_mutex_t st_mutex; /* Protects all data in the slottable */ 92*7c478bd9Sstevel@tonic-gate /* except for st_start_cond. */ 93*7c478bd9Sstevel@tonic-gate CK_SLOT_ID st_first; /* First used slot ID, used for loops */ 94*7c478bd9Sstevel@tonic-gate CK_SLOT_ID st_last; /* Last slot ID allocated */ 95*7c478bd9Sstevel@tonic-gate ulong_t st_cur_size; /* current memory allocated */ 96*7c478bd9Sstevel@tonic-gate pthread_cond_t st_wait_cond; /* Used for C_WaitForSlotEvent */ 97*7c478bd9Sstevel@tonic-gate CK_SLOT_ID st_event_slot; /* Slot with event */ 98*7c478bd9Sstevel@tonic-gate boolean_t st_wfse_active; /* A thread is actively running WFSE */ 99*7c478bd9Sstevel@tonic-gate boolean_t st_blocking; /* Blocking for C_WaitForSlotEvent */ 100*7c478bd9Sstevel@tonic-gate boolean_t st_list_signaled; /* Listener has been signaled */ 101*7c478bd9Sstevel@tonic-gate uint_t st_thr_count; /* Used for C_WaitForSlotEvent */ 102*7c478bd9Sstevel@tonic-gate pthread_t st_tid; 103*7c478bd9Sstevel@tonic-gate pthread_mutex_t st_start_mutex; /* wait for listener to start */ 104*7c478bd9Sstevel@tonic-gate pthread_cond_t st_start_cond; /* signal when listener has started */ 105*7c478bd9Sstevel@tonic-gate 106*7c478bd9Sstevel@tonic-gate } pkcs11_slottable_t; 107*7c478bd9Sstevel@tonic-gate 108*7c478bd9Sstevel@tonic-gate 109*7c478bd9Sstevel@tonic-gate /* 110*7c478bd9Sstevel@tonic-gate * This macro is used to quickly derefence from a framework slot ID, 111*7c478bd9Sstevel@tonic-gate * provided by an application, to the function pointers for the correct 112*7c478bd9Sstevel@tonic-gate * underlying provider. 113*7c478bd9Sstevel@tonic-gate */ 114*7c478bd9Sstevel@tonic-gate #define FUNCLIST(slotID) (slottable->st_slots[(slotID)]->sl_func_list) 115*7c478bd9Sstevel@tonic-gate 116*7c478bd9Sstevel@tonic-gate /* 117*7c478bd9Sstevel@tonic-gate * This macro is used to quickly get the slot ID associated with this 118*7c478bd9Sstevel@tonic-gate * slot ID, that is used by the underlying provider. 119*7c478bd9Sstevel@tonic-gate */ 120*7c478bd9Sstevel@tonic-gate #define TRUEID(slotID) (slottable->st_slots[(slotID)]->sl_id) 121*7c478bd9Sstevel@tonic-gate 122*7c478bd9Sstevel@tonic-gate 123*7c478bd9Sstevel@tonic-gate extern pkcs11_slottable_t *slottable; 124*7c478bd9Sstevel@tonic-gate 125*7c478bd9Sstevel@tonic-gate extern CK_RV pkcs11_slottable_initialize(); 126*7c478bd9Sstevel@tonic-gate extern CK_RV pkcs11_slottable_increase(ulong_t increase); 127*7c478bd9Sstevel@tonic-gate extern CK_RV pkcs11_slot_allocate(CK_SLOT_ID *slot); 128*7c478bd9Sstevel@tonic-gate extern CK_RV pkcs11_slottable_delete(); 129*7c478bd9Sstevel@tonic-gate extern CK_RV pkcs11_is_valid_slot(CK_SLOT_ID slot_id); 130*7c478bd9Sstevel@tonic-gate extern CK_RV pkcs11_validate_and_convert_slotid(CK_SLOT_ID slot_id, 131*7c478bd9Sstevel@tonic-gate CK_SLOT_ID *real_slot_id); 132*7c478bd9Sstevel@tonic-gate 133*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 134*7c478bd9Sstevel@tonic-gate } 135*7c478bd9Sstevel@tonic-gate #endif 136*7c478bd9Sstevel@tonic-gate 137*7c478bd9Sstevel@tonic-gate #endif /* _PKCS11_SLOT_H */ 138