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 #ifdef __cplusplus 31*7c478bd9Sstevel@tonic-gate extern "C" { 32*7c478bd9Sstevel@tonic-gate #endif 33*7c478bd9Sstevel@tonic-gate 34*7c478bd9Sstevel@tonic-gate #include "pkcs11Session.h" 35*7c478bd9Sstevel@tonic-gate 36*7c478bd9Sstevel@tonic-gate #define MECHLIST_SIZE 32 37*7c478bd9Sstevel@tonic-gate 38*7c478bd9Sstevel@tonic-gate /* 39*7c478bd9Sstevel@tonic-gate * Used to pass arguments to child threads for C_WaitForSlotEvent. 40*7c478bd9Sstevel@tonic-gate */ 41*7c478bd9Sstevel@tonic-gate typedef struct wfse_args { 42*7c478bd9Sstevel@tonic-gate 43*7c478bd9Sstevel@tonic-gate CK_FLAGS flags; 44*7c478bd9Sstevel@tonic-gate CK_VOID_PTR pReserved; 45*7c478bd9Sstevel@tonic-gate CK_SLOT_ID slotid; 46*7c478bd9Sstevel@tonic-gate 47*7c478bd9Sstevel@tonic-gate } wfse_args_t; 48*7c478bd9Sstevel@tonic-gate 49*7c478bd9Sstevel@tonic-gate typedef struct pkcs11_slot { 50*7c478bd9Sstevel@tonic-gate 51*7c478bd9Sstevel@tonic-gate CK_SLOT_ID sl_id; /* real slotID from provider */ 52*7c478bd9Sstevel@tonic-gate struct pkcs11_session *sl_sess_list; /* all open sessions */ 53*7c478bd9Sstevel@tonic-gate pthread_mutex_t sl_mutex; /* protects: sl_sess_list, */ 54*7c478bd9Sstevel@tonic-gate /* sl_tid, sl_wfse_state, */ 55*7c478bd9Sstevel@tonic-gate /* and sl_wfse_args */ 56*7c478bd9Sstevel@tonic-gate CK_FUNCTION_LIST_PTR sl_func_list; /* function entry points */ 57*7c478bd9Sstevel@tonic-gate boolean_t sl_enabledpol; /* TRUE if policy for enabled */ 58*7c478bd9Sstevel@tonic-gate CK_MECHANISM_TYPE_PTR sl_pol_mechs; /* policy restricted */ 59*7c478bd9Sstevel@tonic-gate uint_t sl_pol_count; /* policy restricted */ 60*7c478bd9Sstevel@tonic-gate boolean_t sl_norandom; /* TRUE if random is disabled */ 61*7c478bd9Sstevel@tonic-gate void *sl_dldesc; /* from dlopen */ 62*7c478bd9Sstevel@tonic-gate uint_t sl_prov_id; /* set by order read in */ 63*7c478bd9Sstevel@tonic-gate uchar_t sl_wfse_state; /* Used by C_WaitForSlotEvent */ 64*7c478bd9Sstevel@tonic-gate boolean_t sl_no_wfse; /* WaitForSlotEvent not impl */ 65*7c478bd9Sstevel@tonic-gate pthread_t sl_tid; /* Used to track child thread */ 66*7c478bd9Sstevel@tonic-gate wfse_args_t *sl_wfse_args; /* Used for WaitForSlotEvent */ 67*7c478bd9Sstevel@tonic-gate 68*7c478bd9Sstevel@tonic-gate } pkcs11_slot_t; 69*7c478bd9Sstevel@tonic-gate 70*7c478bd9Sstevel@tonic-gate /* 71*7c478bd9Sstevel@tonic-gate * State definitions used for C_WaitForSlotEvent, stored in sl_wfse_state 72*7c478bd9Sstevel@tonic-gate * for each slot. These states are mutually exclusive, ie only one should 73*7c478bd9Sstevel@tonic-gate * be set at a time. 74*7c478bd9Sstevel@tonic-gate */ 75*7c478bd9Sstevel@tonic-gate #define WFSE_CLEAR 0x0 76*7c478bd9Sstevel@tonic-gate #define WFSE_EVENT 0x1 77*7c478bd9Sstevel@tonic-gate #define WFSE_ACTIVE 0x2 78*7c478bd9Sstevel@tonic-gate 79*7c478bd9Sstevel@tonic-gate /* 80*7c478bd9Sstevel@tonic-gate * Dynamically allocated array of slots, indexed by the slotID assigned 81*7c478bd9Sstevel@tonic-gate * by the framework. st_first will be initialized to 1. Only if there 82*7c478bd9Sstevel@tonic-gate * is more than one other slot present, triggering the existence of the 83*7c478bd9Sstevel@tonic-gate * metaslot, with st_first be set to 0. st_last will be set to the 84*7c478bd9Sstevel@tonic-gate * last slotID assigned, also used for looping through the slottable. 85*7c478bd9Sstevel@tonic-gate */ 86*7c478bd9Sstevel@tonic-gate typedef struct pkcs11_slottable { 87*7c478bd9Sstevel@tonic-gate 88*7c478bd9Sstevel@tonic-gate pkcs11_slot_t **st_slots; 89*7c478bd9Sstevel@tonic-gate pthread_mutex_t st_mutex; /* Protects all data in the slottable */ 90*7c478bd9Sstevel@tonic-gate /* except for st_start_cond. */ 91*7c478bd9Sstevel@tonic-gate CK_SLOT_ID st_first; /* First used slot ID, used for loops */ 92*7c478bd9Sstevel@tonic-gate CK_SLOT_ID st_last; /* Last slot ID allocated */ 93*7c478bd9Sstevel@tonic-gate ulong_t st_cur_size; /* current memory allocated */ 94*7c478bd9Sstevel@tonic-gate pthread_cond_t st_wait_cond; /* Used for C_WaitForSlotEvent */ 95*7c478bd9Sstevel@tonic-gate CK_SLOT_ID st_event_slot; /* Slot with event */ 96*7c478bd9Sstevel@tonic-gate boolean_t st_wfse_active; /* A thread is actively running WFSE */ 97*7c478bd9Sstevel@tonic-gate boolean_t st_blocking; /* Blocking for C_WaitForSlotEvent */ 98*7c478bd9Sstevel@tonic-gate boolean_t st_list_signaled; /* Listener has been signaled */ 99*7c478bd9Sstevel@tonic-gate uint_t st_thr_count; /* Used for C_WaitForSlotEvent */ 100*7c478bd9Sstevel@tonic-gate pthread_t st_tid; 101*7c478bd9Sstevel@tonic-gate pthread_mutex_t st_start_mutex; /* wait for listener to start */ 102*7c478bd9Sstevel@tonic-gate pthread_cond_t st_start_cond; /* signal when listener has started */ 103*7c478bd9Sstevel@tonic-gate 104*7c478bd9Sstevel@tonic-gate } pkcs11_slottable_t; 105*7c478bd9Sstevel@tonic-gate 106*7c478bd9Sstevel@tonic-gate 107*7c478bd9Sstevel@tonic-gate /* 108*7c478bd9Sstevel@tonic-gate * This macro is used to quickly derefence from a framework slot ID, 109*7c478bd9Sstevel@tonic-gate * provided by an application, to the function pointers for the correct 110*7c478bd9Sstevel@tonic-gate * underlying provider. 111*7c478bd9Sstevel@tonic-gate */ 112*7c478bd9Sstevel@tonic-gate #define FUNCLIST(slotID) (slottable->st_slots[(slotID)]->sl_func_list) 113*7c478bd9Sstevel@tonic-gate 114*7c478bd9Sstevel@tonic-gate /* 115*7c478bd9Sstevel@tonic-gate * This macro is used to quickly get the slot ID associated with this 116*7c478bd9Sstevel@tonic-gate * slot ID, that is used by the underlying provider. 117*7c478bd9Sstevel@tonic-gate */ 118*7c478bd9Sstevel@tonic-gate #define TRUEID(slotID) (slottable->st_slots[(slotID)]->sl_id) 119*7c478bd9Sstevel@tonic-gate 120*7c478bd9Sstevel@tonic-gate 121*7c478bd9Sstevel@tonic-gate extern pkcs11_slottable_t *slottable; 122*7c478bd9Sstevel@tonic-gate 123*7c478bd9Sstevel@tonic-gate extern CK_RV pkcs11_slottable_initialize(); 124*7c478bd9Sstevel@tonic-gate extern CK_RV pkcs11_slottable_increase(ulong_t increase); 125*7c478bd9Sstevel@tonic-gate extern CK_RV pkcs11_slot_allocate(CK_SLOT_ID *slot); 126*7c478bd9Sstevel@tonic-gate extern CK_RV pkcs11_slottable_delete(); 127*7c478bd9Sstevel@tonic-gate extern CK_RV pkcs11_is_valid_slot(CK_SLOT_ID slot_id); 128*7c478bd9Sstevel@tonic-gate extern CK_RV pkcs11_validate_and_convert_slotid(CK_SLOT_ID slot_id, 129*7c478bd9Sstevel@tonic-gate CK_SLOT_ID *real_slot_id); 130*7c478bd9Sstevel@tonic-gate 131*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 132*7c478bd9Sstevel@tonic-gate } 133*7c478bd9Sstevel@tonic-gate #endif 134*7c478bd9Sstevel@tonic-gate 135*7c478bd9Sstevel@tonic-gate #endif /* _PKCS11_SLOT_H */ 136