Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | /* |
michael@0 | 6 | * slot.c |
michael@0 | 7 | * |
michael@0 | 8 | * This file implements the NSSCKFWSlot type and methods. |
michael@0 | 9 | */ |
michael@0 | 10 | |
michael@0 | 11 | #ifndef CK_T |
michael@0 | 12 | #include "ck.h" |
michael@0 | 13 | #endif /* CK_T */ |
michael@0 | 14 | |
michael@0 | 15 | /* |
michael@0 | 16 | * NSSCKFWSlot |
michael@0 | 17 | * |
michael@0 | 18 | * -- create/destroy -- |
michael@0 | 19 | * nssCKFWSlot_Create |
michael@0 | 20 | * nssCKFWSlot_Destroy |
michael@0 | 21 | * |
michael@0 | 22 | * -- public accessors -- |
michael@0 | 23 | * NSSCKFWSlot_GetMDSlot |
michael@0 | 24 | * NSSCKFWSlot_GetFWInstance |
michael@0 | 25 | * NSSCKFWSlot_GetMDInstance |
michael@0 | 26 | * |
michael@0 | 27 | * -- implement public accessors -- |
michael@0 | 28 | * nssCKFWSlot_GetMDSlot |
michael@0 | 29 | * nssCKFWSlot_GetFWInstance |
michael@0 | 30 | * nssCKFWSlot_GetMDInstance |
michael@0 | 31 | * |
michael@0 | 32 | * -- private accessors -- |
michael@0 | 33 | * nssCKFWSlot_GetSlotID |
michael@0 | 34 | * nssCKFWSlot_ClearToken |
michael@0 | 35 | * |
michael@0 | 36 | * -- module fronts -- |
michael@0 | 37 | * nssCKFWSlot_GetSlotDescription |
michael@0 | 38 | * nssCKFWSlot_GetManufacturerID |
michael@0 | 39 | * nssCKFWSlot_GetTokenPresent |
michael@0 | 40 | * nssCKFWSlot_GetRemovableDevice |
michael@0 | 41 | * nssCKFWSlot_GetHardwareSlot |
michael@0 | 42 | * nssCKFWSlot_GetHardwareVersion |
michael@0 | 43 | * nssCKFWSlot_GetFirmwareVersion |
michael@0 | 44 | * nssCKFWSlot_InitToken |
michael@0 | 45 | * nssCKFWSlot_GetToken |
michael@0 | 46 | */ |
michael@0 | 47 | |
michael@0 | 48 | struct NSSCKFWSlotStr { |
michael@0 | 49 | NSSCKFWMutex *mutex; |
michael@0 | 50 | NSSCKMDSlot *mdSlot; |
michael@0 | 51 | NSSCKFWInstance *fwInstance; |
michael@0 | 52 | NSSCKMDInstance *mdInstance; |
michael@0 | 53 | CK_SLOT_ID slotID; |
michael@0 | 54 | |
michael@0 | 55 | /* |
michael@0 | 56 | * Everything above is set at creation time, and then not modified. |
michael@0 | 57 | * The invariants the mutex protects are: |
michael@0 | 58 | * |
michael@0 | 59 | * 1) Each of the cached descriptions (versions, etc.) are in an |
michael@0 | 60 | * internally consistant state. |
michael@0 | 61 | * |
michael@0 | 62 | * 2) The fwToken points to the token currently in the slot, and |
michael@0 | 63 | * it is in a consistant state. |
michael@0 | 64 | * |
michael@0 | 65 | * Note that the calls accessing the cached descriptions will |
michael@0 | 66 | * call the NSSCKMDSlot methods with the mutex locked. Those |
michael@0 | 67 | * methods may then call the public NSSCKFWSlot routines. Those |
michael@0 | 68 | * public routines only access the constant data above, so there's |
michael@0 | 69 | * no problem. But be careful if you add to this object; mutexes |
michael@0 | 70 | * are in general not reentrant, so don't create deadlock situations. |
michael@0 | 71 | */ |
michael@0 | 72 | |
michael@0 | 73 | NSSUTF8 *slotDescription; |
michael@0 | 74 | NSSUTF8 *manufacturerID; |
michael@0 | 75 | CK_VERSION hardwareVersion; |
michael@0 | 76 | CK_VERSION firmwareVersion; |
michael@0 | 77 | NSSCKFWToken *fwToken; |
michael@0 | 78 | }; |
michael@0 | 79 | |
michael@0 | 80 | #ifdef DEBUG |
michael@0 | 81 | /* |
michael@0 | 82 | * But first, the pointer-tracking stuff. |
michael@0 | 83 | * |
michael@0 | 84 | * NOTE: the pointer-tracking support in NSS/base currently relies |
michael@0 | 85 | * upon NSPR's CallOnce support. That, however, relies upon NSPR's |
michael@0 | 86 | * locking, which is tied into the runtime. We need a pointer-tracker |
michael@0 | 87 | * implementation that uses the locks supplied through C_Initialize. |
michael@0 | 88 | * That support, however, can be filled in later. So for now, I'll |
michael@0 | 89 | * just do this routines as no-ops. |
michael@0 | 90 | */ |
michael@0 | 91 | |
michael@0 | 92 | static CK_RV |
michael@0 | 93 | slot_add_pointer |
michael@0 | 94 | ( |
michael@0 | 95 | const NSSCKFWSlot *fwSlot |
michael@0 | 96 | ) |
michael@0 | 97 | { |
michael@0 | 98 | return CKR_OK; |
michael@0 | 99 | } |
michael@0 | 100 | |
michael@0 | 101 | static CK_RV |
michael@0 | 102 | slot_remove_pointer |
michael@0 | 103 | ( |
michael@0 | 104 | const NSSCKFWSlot *fwSlot |
michael@0 | 105 | ) |
michael@0 | 106 | { |
michael@0 | 107 | return CKR_OK; |
michael@0 | 108 | } |
michael@0 | 109 | |
michael@0 | 110 | NSS_IMPLEMENT CK_RV |
michael@0 | 111 | nssCKFWSlot_verifyPointer |
michael@0 | 112 | ( |
michael@0 | 113 | const NSSCKFWSlot *fwSlot |
michael@0 | 114 | ) |
michael@0 | 115 | { |
michael@0 | 116 | return CKR_OK; |
michael@0 | 117 | } |
michael@0 | 118 | |
michael@0 | 119 | #endif /* DEBUG */ |
michael@0 | 120 | |
michael@0 | 121 | /* |
michael@0 | 122 | * nssCKFWSlot_Create |
michael@0 | 123 | * |
michael@0 | 124 | */ |
michael@0 | 125 | NSS_IMPLEMENT NSSCKFWSlot * |
michael@0 | 126 | nssCKFWSlot_Create |
michael@0 | 127 | ( |
michael@0 | 128 | NSSCKFWInstance *fwInstance, |
michael@0 | 129 | NSSCKMDSlot *mdSlot, |
michael@0 | 130 | CK_SLOT_ID slotID, |
michael@0 | 131 | CK_RV *pError |
michael@0 | 132 | ) |
michael@0 | 133 | { |
michael@0 | 134 | NSSCKFWSlot *fwSlot; |
michael@0 | 135 | NSSCKMDInstance *mdInstance; |
michael@0 | 136 | NSSArena *arena; |
michael@0 | 137 | |
michael@0 | 138 | #ifdef NSSDEBUG |
michael@0 | 139 | if (!pError) { |
michael@0 | 140 | return (NSSCKFWSlot *)NULL; |
michael@0 | 141 | } |
michael@0 | 142 | |
michael@0 | 143 | *pError = nssCKFWInstance_verifyPointer(fwInstance); |
michael@0 | 144 | if( CKR_OK != *pError ) { |
michael@0 | 145 | return (NSSCKFWSlot *)NULL; |
michael@0 | 146 | } |
michael@0 | 147 | #endif /* NSSDEBUG */ |
michael@0 | 148 | |
michael@0 | 149 | mdInstance = nssCKFWInstance_GetMDInstance(fwInstance); |
michael@0 | 150 | if (!mdInstance) { |
michael@0 | 151 | *pError = CKR_GENERAL_ERROR; |
michael@0 | 152 | return (NSSCKFWSlot *)NULL; |
michael@0 | 153 | } |
michael@0 | 154 | |
michael@0 | 155 | arena = nssCKFWInstance_GetArena(fwInstance, pError); |
michael@0 | 156 | if (!arena) { |
michael@0 | 157 | if( CKR_OK == *pError ) { |
michael@0 | 158 | *pError = CKR_GENERAL_ERROR; |
michael@0 | 159 | } |
michael@0 | 160 | } |
michael@0 | 161 | |
michael@0 | 162 | fwSlot = nss_ZNEW(arena, NSSCKFWSlot); |
michael@0 | 163 | if (!fwSlot) { |
michael@0 | 164 | *pError = CKR_HOST_MEMORY; |
michael@0 | 165 | return (NSSCKFWSlot *)NULL; |
michael@0 | 166 | } |
michael@0 | 167 | |
michael@0 | 168 | fwSlot->mdSlot = mdSlot; |
michael@0 | 169 | fwSlot->fwInstance = fwInstance; |
michael@0 | 170 | fwSlot->mdInstance = mdInstance; |
michael@0 | 171 | fwSlot->slotID = slotID; |
michael@0 | 172 | |
michael@0 | 173 | fwSlot->mutex = nssCKFWInstance_CreateMutex(fwInstance, arena, pError); |
michael@0 | 174 | if (!fwSlot->mutex) { |
michael@0 | 175 | if( CKR_OK == *pError ) { |
michael@0 | 176 | *pError = CKR_GENERAL_ERROR; |
michael@0 | 177 | } |
michael@0 | 178 | (void)nss_ZFreeIf(fwSlot); |
michael@0 | 179 | return (NSSCKFWSlot *)NULL; |
michael@0 | 180 | } |
michael@0 | 181 | |
michael@0 | 182 | if (mdSlot->Initialize) { |
michael@0 | 183 | *pError = CKR_OK; |
michael@0 | 184 | *pError = mdSlot->Initialize(mdSlot, fwSlot, mdInstance, fwInstance); |
michael@0 | 185 | if( CKR_OK != *pError ) { |
michael@0 | 186 | (void)nssCKFWMutex_Destroy(fwSlot->mutex); |
michael@0 | 187 | (void)nss_ZFreeIf(fwSlot); |
michael@0 | 188 | return (NSSCKFWSlot *)NULL; |
michael@0 | 189 | } |
michael@0 | 190 | } |
michael@0 | 191 | |
michael@0 | 192 | #ifdef DEBUG |
michael@0 | 193 | *pError = slot_add_pointer(fwSlot); |
michael@0 | 194 | if( CKR_OK != *pError ) { |
michael@0 | 195 | if (mdSlot->Destroy) { |
michael@0 | 196 | mdSlot->Destroy(mdSlot, fwSlot, mdInstance, fwInstance); |
michael@0 | 197 | } |
michael@0 | 198 | |
michael@0 | 199 | (void)nssCKFWMutex_Destroy(fwSlot->mutex); |
michael@0 | 200 | (void)nss_ZFreeIf(fwSlot); |
michael@0 | 201 | return (NSSCKFWSlot *)NULL; |
michael@0 | 202 | } |
michael@0 | 203 | #endif /* DEBUG */ |
michael@0 | 204 | |
michael@0 | 205 | return fwSlot; |
michael@0 | 206 | } |
michael@0 | 207 | |
michael@0 | 208 | /* |
michael@0 | 209 | * nssCKFWSlot_Destroy |
michael@0 | 210 | * |
michael@0 | 211 | */ |
michael@0 | 212 | NSS_IMPLEMENT CK_RV |
michael@0 | 213 | nssCKFWSlot_Destroy |
michael@0 | 214 | ( |
michael@0 | 215 | NSSCKFWSlot *fwSlot |
michael@0 | 216 | ) |
michael@0 | 217 | { |
michael@0 | 218 | CK_RV error = CKR_OK; |
michael@0 | 219 | |
michael@0 | 220 | #ifdef NSSDEBUG |
michael@0 | 221 | error = nssCKFWSlot_verifyPointer(fwSlot); |
michael@0 | 222 | if( CKR_OK != error ) { |
michael@0 | 223 | return error; |
michael@0 | 224 | } |
michael@0 | 225 | #endif /* NSSDEBUG */ |
michael@0 | 226 | if (fwSlot->fwToken) { |
michael@0 | 227 | nssCKFWToken_Destroy(fwSlot->fwToken); |
michael@0 | 228 | } |
michael@0 | 229 | |
michael@0 | 230 | (void)nssCKFWMutex_Destroy(fwSlot->mutex); |
michael@0 | 231 | |
michael@0 | 232 | if (fwSlot->mdSlot->Destroy) { |
michael@0 | 233 | fwSlot->mdSlot->Destroy(fwSlot->mdSlot, fwSlot, |
michael@0 | 234 | fwSlot->mdInstance, fwSlot->fwInstance); |
michael@0 | 235 | } |
michael@0 | 236 | |
michael@0 | 237 | #ifdef DEBUG |
michael@0 | 238 | error = slot_remove_pointer(fwSlot); |
michael@0 | 239 | #endif /* DEBUG */ |
michael@0 | 240 | (void)nss_ZFreeIf(fwSlot); |
michael@0 | 241 | return error; |
michael@0 | 242 | } |
michael@0 | 243 | |
michael@0 | 244 | /* |
michael@0 | 245 | * nssCKFWSlot_GetMDSlot |
michael@0 | 246 | * |
michael@0 | 247 | */ |
michael@0 | 248 | NSS_IMPLEMENT NSSCKMDSlot * |
michael@0 | 249 | nssCKFWSlot_GetMDSlot |
michael@0 | 250 | ( |
michael@0 | 251 | NSSCKFWSlot *fwSlot |
michael@0 | 252 | ) |
michael@0 | 253 | { |
michael@0 | 254 | #ifdef NSSDEBUG |
michael@0 | 255 | if( CKR_OK != nssCKFWSlot_verifyPointer(fwSlot) ) { |
michael@0 | 256 | return (NSSCKMDSlot *)NULL; |
michael@0 | 257 | } |
michael@0 | 258 | #endif /* NSSDEBUG */ |
michael@0 | 259 | |
michael@0 | 260 | return fwSlot->mdSlot; |
michael@0 | 261 | } |
michael@0 | 262 | |
michael@0 | 263 | /* |
michael@0 | 264 | * nssCKFWSlot_GetFWInstance |
michael@0 | 265 | * |
michael@0 | 266 | */ |
michael@0 | 267 | |
michael@0 | 268 | NSS_IMPLEMENT NSSCKFWInstance * |
michael@0 | 269 | nssCKFWSlot_GetFWInstance |
michael@0 | 270 | ( |
michael@0 | 271 | NSSCKFWSlot *fwSlot |
michael@0 | 272 | ) |
michael@0 | 273 | { |
michael@0 | 274 | #ifdef NSSDEBUG |
michael@0 | 275 | if( CKR_OK != nssCKFWSlot_verifyPointer(fwSlot) ) { |
michael@0 | 276 | return (NSSCKFWInstance *)NULL; |
michael@0 | 277 | } |
michael@0 | 278 | #endif /* NSSDEBUG */ |
michael@0 | 279 | |
michael@0 | 280 | return fwSlot->fwInstance; |
michael@0 | 281 | } |
michael@0 | 282 | |
michael@0 | 283 | /* |
michael@0 | 284 | * nssCKFWSlot_GetMDInstance |
michael@0 | 285 | * |
michael@0 | 286 | */ |
michael@0 | 287 | |
michael@0 | 288 | NSS_IMPLEMENT NSSCKMDInstance * |
michael@0 | 289 | nssCKFWSlot_GetMDInstance |
michael@0 | 290 | ( |
michael@0 | 291 | NSSCKFWSlot *fwSlot |
michael@0 | 292 | ) |
michael@0 | 293 | { |
michael@0 | 294 | #ifdef NSSDEBUG |
michael@0 | 295 | if( CKR_OK != nssCKFWSlot_verifyPointer(fwSlot) ) { |
michael@0 | 296 | return (NSSCKMDInstance *)NULL; |
michael@0 | 297 | } |
michael@0 | 298 | #endif /* NSSDEBUG */ |
michael@0 | 299 | |
michael@0 | 300 | return fwSlot->mdInstance; |
michael@0 | 301 | } |
michael@0 | 302 | |
michael@0 | 303 | /* |
michael@0 | 304 | * nssCKFWSlot_GetSlotID |
michael@0 | 305 | * |
michael@0 | 306 | */ |
michael@0 | 307 | NSS_IMPLEMENT CK_SLOT_ID |
michael@0 | 308 | nssCKFWSlot_GetSlotID |
michael@0 | 309 | ( |
michael@0 | 310 | NSSCKFWSlot *fwSlot |
michael@0 | 311 | ) |
michael@0 | 312 | { |
michael@0 | 313 | #ifdef NSSDEBUG |
michael@0 | 314 | if( CKR_OK != nssCKFWSlot_verifyPointer(fwSlot) ) { |
michael@0 | 315 | return (CK_SLOT_ID)0; |
michael@0 | 316 | } |
michael@0 | 317 | #endif /* NSSDEBUG */ |
michael@0 | 318 | |
michael@0 | 319 | return fwSlot->slotID; |
michael@0 | 320 | } |
michael@0 | 321 | |
michael@0 | 322 | /* |
michael@0 | 323 | * nssCKFWSlot_GetSlotDescription |
michael@0 | 324 | * |
michael@0 | 325 | */ |
michael@0 | 326 | NSS_IMPLEMENT CK_RV |
michael@0 | 327 | nssCKFWSlot_GetSlotDescription |
michael@0 | 328 | ( |
michael@0 | 329 | NSSCKFWSlot *fwSlot, |
michael@0 | 330 | CK_CHAR slotDescription[64] |
michael@0 | 331 | ) |
michael@0 | 332 | { |
michael@0 | 333 | CK_RV error = CKR_OK; |
michael@0 | 334 | |
michael@0 | 335 | #ifdef NSSDEBUG |
michael@0 | 336 | if( (CK_CHAR_PTR)NULL == slotDescription ) { |
michael@0 | 337 | return CKR_ARGUMENTS_BAD; |
michael@0 | 338 | } |
michael@0 | 339 | |
michael@0 | 340 | error = nssCKFWSlot_verifyPointer(fwSlot); |
michael@0 | 341 | if( CKR_OK != error ) { |
michael@0 | 342 | return error; |
michael@0 | 343 | } |
michael@0 | 344 | #endif /* NSSDEBUG */ |
michael@0 | 345 | |
michael@0 | 346 | error = nssCKFWMutex_Lock(fwSlot->mutex); |
michael@0 | 347 | if( CKR_OK != error ) { |
michael@0 | 348 | return error; |
michael@0 | 349 | } |
michael@0 | 350 | |
michael@0 | 351 | if (!fwSlot->slotDescription) { |
michael@0 | 352 | if (fwSlot->mdSlot->GetSlotDescription) { |
michael@0 | 353 | fwSlot->slotDescription = fwSlot->mdSlot->GetSlotDescription( |
michael@0 | 354 | fwSlot->mdSlot, fwSlot, fwSlot->mdInstance, |
michael@0 | 355 | fwSlot->fwInstance, &error); |
michael@0 | 356 | if ((!fwSlot->slotDescription) && (CKR_OK != error)) { |
michael@0 | 357 | goto done; |
michael@0 | 358 | } |
michael@0 | 359 | } else { |
michael@0 | 360 | fwSlot->slotDescription = (NSSUTF8 *) ""; |
michael@0 | 361 | } |
michael@0 | 362 | } |
michael@0 | 363 | |
michael@0 | 364 | (void)nssUTF8_CopyIntoFixedBuffer(fwSlot->slotDescription, (char *)slotDescription, 64, ' '); |
michael@0 | 365 | error = CKR_OK; |
michael@0 | 366 | |
michael@0 | 367 | done: |
michael@0 | 368 | (void)nssCKFWMutex_Unlock(fwSlot->mutex); |
michael@0 | 369 | return error; |
michael@0 | 370 | } |
michael@0 | 371 | |
michael@0 | 372 | /* |
michael@0 | 373 | * nssCKFWSlot_GetManufacturerID |
michael@0 | 374 | * |
michael@0 | 375 | */ |
michael@0 | 376 | NSS_IMPLEMENT CK_RV |
michael@0 | 377 | nssCKFWSlot_GetManufacturerID |
michael@0 | 378 | ( |
michael@0 | 379 | NSSCKFWSlot *fwSlot, |
michael@0 | 380 | CK_CHAR manufacturerID[32] |
michael@0 | 381 | ) |
michael@0 | 382 | { |
michael@0 | 383 | CK_RV error = CKR_OK; |
michael@0 | 384 | |
michael@0 | 385 | #ifdef NSSDEBUG |
michael@0 | 386 | if( (CK_CHAR_PTR)NULL == manufacturerID ) { |
michael@0 | 387 | return CKR_ARGUMENTS_BAD; |
michael@0 | 388 | } |
michael@0 | 389 | |
michael@0 | 390 | error = nssCKFWSlot_verifyPointer(fwSlot); |
michael@0 | 391 | if( CKR_OK != error ) { |
michael@0 | 392 | return error; |
michael@0 | 393 | } |
michael@0 | 394 | #endif /* NSSDEBUG */ |
michael@0 | 395 | |
michael@0 | 396 | error = nssCKFWMutex_Lock(fwSlot->mutex); |
michael@0 | 397 | if( CKR_OK != error ) { |
michael@0 | 398 | return error; |
michael@0 | 399 | } |
michael@0 | 400 | |
michael@0 | 401 | if (!fwSlot->manufacturerID) { |
michael@0 | 402 | if (fwSlot->mdSlot->GetManufacturerID) { |
michael@0 | 403 | fwSlot->manufacturerID = fwSlot->mdSlot->GetManufacturerID( |
michael@0 | 404 | fwSlot->mdSlot, fwSlot, fwSlot->mdInstance, |
michael@0 | 405 | fwSlot->fwInstance, &error); |
michael@0 | 406 | if ((!fwSlot->manufacturerID) && (CKR_OK != error)) { |
michael@0 | 407 | goto done; |
michael@0 | 408 | } |
michael@0 | 409 | } else { |
michael@0 | 410 | fwSlot->manufacturerID = (NSSUTF8 *) ""; |
michael@0 | 411 | } |
michael@0 | 412 | } |
michael@0 | 413 | |
michael@0 | 414 | (void)nssUTF8_CopyIntoFixedBuffer(fwSlot->manufacturerID, (char *)manufacturerID, 32, ' '); |
michael@0 | 415 | error = CKR_OK; |
michael@0 | 416 | |
michael@0 | 417 | done: |
michael@0 | 418 | (void)nssCKFWMutex_Unlock(fwSlot->mutex); |
michael@0 | 419 | return error; |
michael@0 | 420 | } |
michael@0 | 421 | |
michael@0 | 422 | /* |
michael@0 | 423 | * nssCKFWSlot_GetTokenPresent |
michael@0 | 424 | * |
michael@0 | 425 | */ |
michael@0 | 426 | NSS_IMPLEMENT CK_BBOOL |
michael@0 | 427 | nssCKFWSlot_GetTokenPresent |
michael@0 | 428 | ( |
michael@0 | 429 | NSSCKFWSlot *fwSlot |
michael@0 | 430 | ) |
michael@0 | 431 | { |
michael@0 | 432 | #ifdef NSSDEBUG |
michael@0 | 433 | if( CKR_OK != nssCKFWSlot_verifyPointer(fwSlot) ) { |
michael@0 | 434 | return CK_FALSE; |
michael@0 | 435 | } |
michael@0 | 436 | #endif /* NSSDEBUG */ |
michael@0 | 437 | |
michael@0 | 438 | if (!fwSlot->mdSlot->GetTokenPresent) { |
michael@0 | 439 | return CK_TRUE; |
michael@0 | 440 | } |
michael@0 | 441 | |
michael@0 | 442 | return fwSlot->mdSlot->GetTokenPresent(fwSlot->mdSlot, fwSlot, |
michael@0 | 443 | fwSlot->mdInstance, fwSlot->fwInstance); |
michael@0 | 444 | } |
michael@0 | 445 | |
michael@0 | 446 | /* |
michael@0 | 447 | * nssCKFWSlot_GetRemovableDevice |
michael@0 | 448 | * |
michael@0 | 449 | */ |
michael@0 | 450 | NSS_IMPLEMENT CK_BBOOL |
michael@0 | 451 | nssCKFWSlot_GetRemovableDevice |
michael@0 | 452 | ( |
michael@0 | 453 | NSSCKFWSlot *fwSlot |
michael@0 | 454 | ) |
michael@0 | 455 | { |
michael@0 | 456 | #ifdef NSSDEBUG |
michael@0 | 457 | if( CKR_OK != nssCKFWSlot_verifyPointer(fwSlot) ) { |
michael@0 | 458 | return CK_FALSE; |
michael@0 | 459 | } |
michael@0 | 460 | #endif /* NSSDEBUG */ |
michael@0 | 461 | |
michael@0 | 462 | if (!fwSlot->mdSlot->GetRemovableDevice) { |
michael@0 | 463 | return CK_FALSE; |
michael@0 | 464 | } |
michael@0 | 465 | |
michael@0 | 466 | return fwSlot->mdSlot->GetRemovableDevice(fwSlot->mdSlot, fwSlot, |
michael@0 | 467 | fwSlot->mdInstance, fwSlot->fwInstance); |
michael@0 | 468 | } |
michael@0 | 469 | |
michael@0 | 470 | /* |
michael@0 | 471 | * nssCKFWSlot_GetHardwareSlot |
michael@0 | 472 | * |
michael@0 | 473 | */ |
michael@0 | 474 | NSS_IMPLEMENT CK_BBOOL |
michael@0 | 475 | nssCKFWSlot_GetHardwareSlot |
michael@0 | 476 | ( |
michael@0 | 477 | NSSCKFWSlot *fwSlot |
michael@0 | 478 | ) |
michael@0 | 479 | { |
michael@0 | 480 | #ifdef NSSDEBUG |
michael@0 | 481 | if( CKR_OK != nssCKFWSlot_verifyPointer(fwSlot) ) { |
michael@0 | 482 | return CK_FALSE; |
michael@0 | 483 | } |
michael@0 | 484 | #endif /* NSSDEBUG */ |
michael@0 | 485 | |
michael@0 | 486 | if (!fwSlot->mdSlot->GetHardwareSlot) { |
michael@0 | 487 | return CK_FALSE; |
michael@0 | 488 | } |
michael@0 | 489 | |
michael@0 | 490 | return fwSlot->mdSlot->GetHardwareSlot(fwSlot->mdSlot, fwSlot, |
michael@0 | 491 | fwSlot->mdInstance, fwSlot->fwInstance); |
michael@0 | 492 | } |
michael@0 | 493 | |
michael@0 | 494 | /* |
michael@0 | 495 | * nssCKFWSlot_GetHardwareVersion |
michael@0 | 496 | * |
michael@0 | 497 | */ |
michael@0 | 498 | NSS_IMPLEMENT CK_VERSION |
michael@0 | 499 | nssCKFWSlot_GetHardwareVersion |
michael@0 | 500 | ( |
michael@0 | 501 | NSSCKFWSlot *fwSlot |
michael@0 | 502 | ) |
michael@0 | 503 | { |
michael@0 | 504 | CK_VERSION rv; |
michael@0 | 505 | |
michael@0 | 506 | #ifdef NSSDEBUG |
michael@0 | 507 | if( CKR_OK != nssCKFWSlot_verifyPointer(fwSlot) ) { |
michael@0 | 508 | rv.major = rv.minor = 0; |
michael@0 | 509 | return rv; |
michael@0 | 510 | } |
michael@0 | 511 | #endif /* NSSDEBUG */ |
michael@0 | 512 | |
michael@0 | 513 | if( CKR_OK != nssCKFWMutex_Lock(fwSlot->mutex) ) { |
michael@0 | 514 | rv.major = rv.minor = 0; |
michael@0 | 515 | return rv; |
michael@0 | 516 | } |
michael@0 | 517 | |
michael@0 | 518 | if( (0 != fwSlot->hardwareVersion.major) || |
michael@0 | 519 | (0 != fwSlot->hardwareVersion.minor) ) { |
michael@0 | 520 | rv = fwSlot->hardwareVersion; |
michael@0 | 521 | goto done; |
michael@0 | 522 | } |
michael@0 | 523 | |
michael@0 | 524 | if (fwSlot->mdSlot->GetHardwareVersion) { |
michael@0 | 525 | fwSlot->hardwareVersion = fwSlot->mdSlot->GetHardwareVersion( |
michael@0 | 526 | fwSlot->mdSlot, fwSlot, fwSlot->mdInstance, fwSlot->fwInstance); |
michael@0 | 527 | } else { |
michael@0 | 528 | fwSlot->hardwareVersion.major = 0; |
michael@0 | 529 | fwSlot->hardwareVersion.minor = 1; |
michael@0 | 530 | } |
michael@0 | 531 | |
michael@0 | 532 | rv = fwSlot->hardwareVersion; |
michael@0 | 533 | done: |
michael@0 | 534 | (void)nssCKFWMutex_Unlock(fwSlot->mutex); |
michael@0 | 535 | return rv; |
michael@0 | 536 | } |
michael@0 | 537 | |
michael@0 | 538 | /* |
michael@0 | 539 | * nssCKFWSlot_GetFirmwareVersion |
michael@0 | 540 | * |
michael@0 | 541 | */ |
michael@0 | 542 | NSS_IMPLEMENT CK_VERSION |
michael@0 | 543 | nssCKFWSlot_GetFirmwareVersion |
michael@0 | 544 | ( |
michael@0 | 545 | NSSCKFWSlot *fwSlot |
michael@0 | 546 | ) |
michael@0 | 547 | { |
michael@0 | 548 | CK_VERSION rv; |
michael@0 | 549 | |
michael@0 | 550 | #ifdef NSSDEBUG |
michael@0 | 551 | if( CKR_OK != nssCKFWSlot_verifyPointer(fwSlot) ) { |
michael@0 | 552 | rv.major = rv.minor = 0; |
michael@0 | 553 | return rv; |
michael@0 | 554 | } |
michael@0 | 555 | #endif /* NSSDEBUG */ |
michael@0 | 556 | |
michael@0 | 557 | if( CKR_OK != nssCKFWMutex_Lock(fwSlot->mutex) ) { |
michael@0 | 558 | rv.major = rv.minor = 0; |
michael@0 | 559 | return rv; |
michael@0 | 560 | } |
michael@0 | 561 | |
michael@0 | 562 | if( (0 != fwSlot->firmwareVersion.major) || |
michael@0 | 563 | (0 != fwSlot->firmwareVersion.minor) ) { |
michael@0 | 564 | rv = fwSlot->firmwareVersion; |
michael@0 | 565 | goto done; |
michael@0 | 566 | } |
michael@0 | 567 | |
michael@0 | 568 | if (fwSlot->mdSlot->GetFirmwareVersion) { |
michael@0 | 569 | fwSlot->firmwareVersion = fwSlot->mdSlot->GetFirmwareVersion( |
michael@0 | 570 | fwSlot->mdSlot, fwSlot, fwSlot->mdInstance, fwSlot->fwInstance); |
michael@0 | 571 | } else { |
michael@0 | 572 | fwSlot->firmwareVersion.major = 0; |
michael@0 | 573 | fwSlot->firmwareVersion.minor = 1; |
michael@0 | 574 | } |
michael@0 | 575 | |
michael@0 | 576 | rv = fwSlot->firmwareVersion; |
michael@0 | 577 | done: |
michael@0 | 578 | (void)nssCKFWMutex_Unlock(fwSlot->mutex); |
michael@0 | 579 | return rv; |
michael@0 | 580 | } |
michael@0 | 581 | |
michael@0 | 582 | /* |
michael@0 | 583 | * nssCKFWSlot_GetToken |
michael@0 | 584 | * |
michael@0 | 585 | */ |
michael@0 | 586 | NSS_IMPLEMENT NSSCKFWToken * |
michael@0 | 587 | nssCKFWSlot_GetToken |
michael@0 | 588 | ( |
michael@0 | 589 | NSSCKFWSlot *fwSlot, |
michael@0 | 590 | CK_RV *pError |
michael@0 | 591 | ) |
michael@0 | 592 | { |
michael@0 | 593 | NSSCKMDToken *mdToken; |
michael@0 | 594 | NSSCKFWToken *fwToken; |
michael@0 | 595 | |
michael@0 | 596 | #ifdef NSSDEBUG |
michael@0 | 597 | if (!pError) { |
michael@0 | 598 | return (NSSCKFWToken *)NULL; |
michael@0 | 599 | } |
michael@0 | 600 | |
michael@0 | 601 | *pError = nssCKFWSlot_verifyPointer(fwSlot); |
michael@0 | 602 | if( CKR_OK != *pError ) { |
michael@0 | 603 | return (NSSCKFWToken *)NULL; |
michael@0 | 604 | } |
michael@0 | 605 | #endif /* NSSDEBUG */ |
michael@0 | 606 | |
michael@0 | 607 | *pError = nssCKFWMutex_Lock(fwSlot->mutex); |
michael@0 | 608 | if( CKR_OK != *pError ) { |
michael@0 | 609 | return (NSSCKFWToken *)NULL; |
michael@0 | 610 | } |
michael@0 | 611 | |
michael@0 | 612 | if (!fwSlot->fwToken) { |
michael@0 | 613 | if (!fwSlot->mdSlot->GetToken) { |
michael@0 | 614 | *pError = CKR_GENERAL_ERROR; |
michael@0 | 615 | fwToken = (NSSCKFWToken *)NULL; |
michael@0 | 616 | goto done; |
michael@0 | 617 | } |
michael@0 | 618 | |
michael@0 | 619 | mdToken = fwSlot->mdSlot->GetToken(fwSlot->mdSlot, fwSlot, |
michael@0 | 620 | fwSlot->mdInstance, fwSlot->fwInstance, pError); |
michael@0 | 621 | if (!mdToken) { |
michael@0 | 622 | if( CKR_OK == *pError ) { |
michael@0 | 623 | *pError = CKR_GENERAL_ERROR; |
michael@0 | 624 | } |
michael@0 | 625 | return (NSSCKFWToken *)NULL; |
michael@0 | 626 | } |
michael@0 | 627 | |
michael@0 | 628 | fwToken = nssCKFWToken_Create(fwSlot, mdToken, pError); |
michael@0 | 629 | fwSlot->fwToken = fwToken; |
michael@0 | 630 | } else { |
michael@0 | 631 | fwToken = fwSlot->fwToken; |
michael@0 | 632 | } |
michael@0 | 633 | |
michael@0 | 634 | done: |
michael@0 | 635 | (void)nssCKFWMutex_Unlock(fwSlot->mutex); |
michael@0 | 636 | return fwToken; |
michael@0 | 637 | } |
michael@0 | 638 | |
michael@0 | 639 | /* |
michael@0 | 640 | * nssCKFWSlot_ClearToken |
michael@0 | 641 | * |
michael@0 | 642 | */ |
michael@0 | 643 | NSS_IMPLEMENT void |
michael@0 | 644 | nssCKFWSlot_ClearToken |
michael@0 | 645 | ( |
michael@0 | 646 | NSSCKFWSlot *fwSlot |
michael@0 | 647 | ) |
michael@0 | 648 | { |
michael@0 | 649 | #ifdef NSSDEBUG |
michael@0 | 650 | if( CKR_OK != nssCKFWSlot_verifyPointer(fwSlot) ) { |
michael@0 | 651 | return; |
michael@0 | 652 | } |
michael@0 | 653 | #endif /* NSSDEBUG */ |
michael@0 | 654 | |
michael@0 | 655 | if( CKR_OK != nssCKFWMutex_Lock(fwSlot->mutex) ) { |
michael@0 | 656 | /* Now what? */ |
michael@0 | 657 | return; |
michael@0 | 658 | } |
michael@0 | 659 | |
michael@0 | 660 | fwSlot->fwToken = (NSSCKFWToken *)NULL; |
michael@0 | 661 | (void)nssCKFWMutex_Unlock(fwSlot->mutex); |
michael@0 | 662 | return; |
michael@0 | 663 | } |
michael@0 | 664 | |
michael@0 | 665 | /* |
michael@0 | 666 | * NSSCKFWSlot_GetMDSlot |
michael@0 | 667 | * |
michael@0 | 668 | */ |
michael@0 | 669 | |
michael@0 | 670 | NSS_IMPLEMENT NSSCKMDSlot * |
michael@0 | 671 | NSSCKFWSlot_GetMDSlot |
michael@0 | 672 | ( |
michael@0 | 673 | NSSCKFWSlot *fwSlot |
michael@0 | 674 | ) |
michael@0 | 675 | { |
michael@0 | 676 | #ifdef DEBUG |
michael@0 | 677 | if( CKR_OK != nssCKFWSlot_verifyPointer(fwSlot) ) { |
michael@0 | 678 | return (NSSCKMDSlot *)NULL; |
michael@0 | 679 | } |
michael@0 | 680 | #endif /* DEBUG */ |
michael@0 | 681 | |
michael@0 | 682 | return nssCKFWSlot_GetMDSlot(fwSlot); |
michael@0 | 683 | } |
michael@0 | 684 | |
michael@0 | 685 | /* |
michael@0 | 686 | * NSSCKFWSlot_GetFWInstance |
michael@0 | 687 | * |
michael@0 | 688 | */ |
michael@0 | 689 | |
michael@0 | 690 | NSS_IMPLEMENT NSSCKFWInstance * |
michael@0 | 691 | NSSCKFWSlot_GetFWInstance |
michael@0 | 692 | ( |
michael@0 | 693 | NSSCKFWSlot *fwSlot |
michael@0 | 694 | ) |
michael@0 | 695 | { |
michael@0 | 696 | #ifdef DEBUG |
michael@0 | 697 | if( CKR_OK != nssCKFWSlot_verifyPointer(fwSlot) ) { |
michael@0 | 698 | return (NSSCKFWInstance *)NULL; |
michael@0 | 699 | } |
michael@0 | 700 | #endif /* DEBUG */ |
michael@0 | 701 | |
michael@0 | 702 | return nssCKFWSlot_GetFWInstance(fwSlot); |
michael@0 | 703 | } |
michael@0 | 704 | |
michael@0 | 705 | /* |
michael@0 | 706 | * NSSCKFWSlot_GetMDInstance |
michael@0 | 707 | * |
michael@0 | 708 | */ |
michael@0 | 709 | |
michael@0 | 710 | NSS_IMPLEMENT NSSCKMDInstance * |
michael@0 | 711 | NSSCKFWSlot_GetMDInstance |
michael@0 | 712 | ( |
michael@0 | 713 | NSSCKFWSlot *fwSlot |
michael@0 | 714 | ) |
michael@0 | 715 | { |
michael@0 | 716 | #ifdef DEBUG |
michael@0 | 717 | if( CKR_OK != nssCKFWSlot_verifyPointer(fwSlot) ) { |
michael@0 | 718 | return (NSSCKMDInstance *)NULL; |
michael@0 | 719 | } |
michael@0 | 720 | #endif /* DEBUG */ |
michael@0 | 721 | |
michael@0 | 722 | return nssCKFWSlot_GetMDInstance(fwSlot); |
michael@0 | 723 | } |