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