| 1 | /*************************************************************************** |
|---|
| 2 | * Copyright (c) 2003-2010, Broadcom Corporation |
|---|
| 3 | * All Rights Reserved |
|---|
| 4 | * Confidential Property of Broadcom Corporation |
|---|
| 5 | * |
|---|
| 6 | * THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE |
|---|
| 7 | * AGREEMENT BETWEEN THE USER AND BROADCOM. YOU HAVE NO RIGHT TO USE OR |
|---|
| 8 | * EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT. |
|---|
| 9 | * |
|---|
| 10 | * $brcm_Workfile: bsettop_smartcard.c $ |
|---|
| 11 | * $brcm_Revision: 15 $ |
|---|
| 12 | * $brcm_Date: 8/4/10 12:17p $ |
|---|
| 13 | * |
|---|
| 14 | * Module Description: |
|---|
| 15 | * |
|---|
| 16 | * Revision History: |
|---|
| 17 | * |
|---|
| 18 | * $brcm_Log: /BSEAV/api/src/nexus/bsettop_smartcard.c $ |
|---|
| 19 | * |
|---|
| 20 | * 15 8/4/10 12:17p VISHK |
|---|
| 21 | * SW7125-478: NEXUS_Smartcard_SetParamsFromAtr() is not completed |
|---|
| 22 | * |
|---|
| 23 | * 14 12/8/08 3:56p vishk |
|---|
| 24 | * PR 49706: second smartcard module not working |
|---|
| 25 | * |
|---|
| 26 | * 13 10/10/08 1:19p tmontoya |
|---|
| 27 | * PR47512: bsmartcard_read() returns Nexus error codes... |
|---|
| 28 | * |
|---|
| 29 | * 12 9/11/08 2:20p vishk |
|---|
| 30 | * PR 45615: ISO smartcard channel settings not correct and not |
|---|
| 31 | * configurable. |
|---|
| 32 | * PR 29851: Smartcard functions need to allow more parameter changes |
|---|
| 33 | * |
|---|
| 34 | * 11 8/22/08 1:54p vishk |
|---|
| 35 | * PR 45615: ISO smartcard channel settings not correct and not |
|---|
| 36 | * configurable. |
|---|
| 37 | * PR 29851: Smartcard functions need to allow more parameter changes |
|---|
| 38 | * |
|---|
| 39 | * 10 8/22/08 11:39a vishk |
|---|
| 40 | * PR 45615: ISO smartcard channel settings not correct and not |
|---|
| 41 | * configurable. |
|---|
| 42 | * PR 29851: Smartcard functions need to allow more parameter changes |
|---|
| 43 | * |
|---|
| 44 | * 9 8/19/08 2:33p vishk |
|---|
| 45 | * PR 45615: ISO smartcard channel settings not correct and not |
|---|
| 46 | * configurable. |
|---|
| 47 | * PR 29851: Smartcard functions need to allow more parameter changes |
|---|
| 48 | * |
|---|
| 49 | * 8 8/19/08 1:59p vishk |
|---|
| 50 | * PR 45615: ISO smartcard channel settings not correct and not |
|---|
| 51 | * configurable. |
|---|
| 52 | * PR 29851: Smartcard functions need to allow more parameter changes |
|---|
| 53 | * |
|---|
| 54 | * 7 7/25/08 7:12p vishk |
|---|
| 55 | * PR 45044: bsmartcard_close() Seg-Faults using the handle returned by |
|---|
| 56 | * bsmartcard_open() |
|---|
| 57 | * |
|---|
| 58 | * 6 6/18/08 10:06p erickson |
|---|
| 59 | * PR36068: fix warning |
|---|
| 60 | * |
|---|
| 61 | * 5 5/29/08 8:48a erickson |
|---|
| 62 | * PR39453: 3548/3556 updates |
|---|
| 63 | * |
|---|
| 64 | * 4 5/20/08 4:27p erickson |
|---|
| 65 | * PR40034: support platforms with no smartcard |
|---|
| 66 | * |
|---|
| 67 | * 3 5/16/08 7:22p vishk |
|---|
| 68 | * PR 40034: Develop Nexus Smartcard Interface/Module. |
|---|
| 69 | * PR 40016: bsettop_smartcard: Develop SettopAPI-to-Nexus shim layer |
|---|
| 70 | * |
|---|
| 71 | * 2 3/25/08 10:13a jgarrett |
|---|
| 72 | * PR 40857: Adding stubs for thunk layer |
|---|
| 73 | * |
|---|
| 74 | * 1 10/15/07 2:36p erickson |
|---|
| 75 | * PR36068: initial |
|---|
| 76 | * |
|---|
| 77 | ***************************************************************************/ |
|---|
| 78 | #include "bsettop_impl.h" |
|---|
| 79 | |
|---|
| 80 | BDBG_MODULE(smartcard); |
|---|
| 81 | |
|---|
| 82 | struct bsmartcard { |
|---|
| 83 | BDBG_OBJECT(bsmartcard) |
|---|
| 84 | #if NEXUS_HAS_SMARTCARD |
|---|
| 85 | NEXUS_SmartcardHandle nSmartcard; |
|---|
| 86 | #endif |
|---|
| 87 | bsmartcard_settings_t settings; |
|---|
| 88 | BKNI_EventHandle insertCardEvent; |
|---|
| 89 | b_event_id_t insertCardEventId; |
|---|
| 90 | BKNI_EventHandle removeCardEvent; |
|---|
| 91 | b_event_id_t removeCardEventId; |
|---|
| 92 | }; |
|---|
| 93 | |
|---|
| 94 | #if NEXUS_HAS_SMARTCARD |
|---|
| 95 | struct bsmartcard cliChannel[NEXUS_NUM_SMARTCARD_CHANNELS]; |
|---|
| 96 | #endif |
|---|
| 97 | |
|---|
| 98 | void bsmartcard_settings_init( |
|---|
| 99 | bsmartcard_settings_t *settings |
|---|
| 100 | ) |
|---|
| 101 | { |
|---|
| 102 | /* TODO: Real Impl */ |
|---|
| 103 | BDBG_ASSERT(NULL != settings); |
|---|
| 104 | BKNI_Memset(settings, 0, sizeof(*settings)); |
|---|
| 105 | |
|---|
| 106 | settings->protocol = bsmartcard_protocol_t0; |
|---|
| 107 | settings->standard = bsmartcard_standard_nds; |
|---|
| 108 | settings->ffactor = 1; |
|---|
| 109 | settings->dfactor = 1; |
|---|
| 110 | settings->ext_clock_divisor = 1; |
|---|
| 111 | settings->tx_retries = 4; |
|---|
| 112 | settings->rx_retries = 4; |
|---|
| 113 | settings->work_wait_time.value = 9600; |
|---|
| 114 | settings->block_wait_time.value = 971; |
|---|
| 115 | settings->extra_guard_time.value= 2; |
|---|
| 116 | settings->block_guard_time.value = 22; |
|---|
| 117 | settings->time_out.value= 5000; |
|---|
| 118 | settings->time_out.unit= bsmartcard_timer_unit_msec; |
|---|
| 119 | settings->sc_pres_dbinfo.db_width = 7; |
|---|
| 120 | settings->sc_pres_dbinfo.sc_pres_mode = bsmartcard_sc_presmode_mask; |
|---|
| 121 | |
|---|
| 122 | settings->callback_context = NULL; |
|---|
| 123 | settings->card_insertion = NULL; |
|---|
| 124 | settings->card_removal = NULL; |
|---|
| 125 | } |
|---|
| 126 | |
|---|
| 127 | bresult bsmartcard_init(void) |
|---|
| 128 | { |
|---|
| 129 | #if NEXUS_HAS_SMARTCARD |
|---|
| 130 | BKNI_Memset(cliChannel, 0, sizeof(cliChannel)); |
|---|
| 131 | #endif |
|---|
| 132 | return b_ok; |
|---|
| 133 | } |
|---|
| 134 | |
|---|
| 135 | void bsmartcard_get_settings( |
|---|
| 136 | bsmartcard_t smartcard, |
|---|
| 137 | bsmartcard_settings_t *settings |
|---|
| 138 | ) |
|---|
| 139 | { |
|---|
| 140 | #if NEXUS_HAS_SMARTCARD |
|---|
| 141 | settings = &smartcard->settings; |
|---|
| 142 | #else |
|---|
| 143 | BSTD_UNUSED(smartcard); |
|---|
| 144 | BSTD_UNUSED(settings); |
|---|
| 145 | BSETTOP_ERROR(berr_not_supported); |
|---|
| 146 | #endif |
|---|
| 147 | } |
|---|
| 148 | |
|---|
| 149 | bresult bsmartcard_set_settings( |
|---|
| 150 | bsmartcard_t smartcard, |
|---|
| 151 | const bsmartcard_settings_t *settings |
|---|
| 152 | ) |
|---|
| 153 | { |
|---|
| 154 | #if NEXUS_HAS_SMARTCARD |
|---|
| 155 | |
|---|
| 156 | NEXUS_Error rc; |
|---|
| 157 | NEXUS_SmartcardSettings nsettings; |
|---|
| 158 | |
|---|
| 159 | NEXUS_Smartcard_GetSettings(smartcard->nSmartcard, &nsettings); |
|---|
| 160 | |
|---|
| 161 | switch (settings->standard) { |
|---|
| 162 | case bsmartcard_standard_nds: |
|---|
| 163 | nsettings.standard = NEXUS_SmartcardStandard_eNds; |
|---|
| 164 | break; |
|---|
| 165 | case bsmartcard_standard_iso: |
|---|
| 166 | nsettings.standard = NEXUS_SmartcardStandard_eIso; |
|---|
| 167 | break; |
|---|
| 168 | case bsmartcard_standard_emv2000: |
|---|
| 169 | nsettings.standard = NEXUS_SmartcardStandard_eEmv2000; |
|---|
| 170 | break; |
|---|
| 171 | case bsmartcard_standard_irdeto: |
|---|
| 172 | nsettings.standard = NEXUS_SmartcardStandard_eIrdeto; |
|---|
| 173 | break; |
|---|
| 174 | default: |
|---|
| 175 | nsettings.standard = NEXUS_SmartcardStandard_eUnknown; |
|---|
| 176 | break; |
|---|
| 177 | } |
|---|
| 178 | |
|---|
| 179 | BDBG_CASSERT(NEXUS_SmartcardProtocol_eT14 == bsmartcard_standard_irdeto); |
|---|
| 180 | nsettings.protocol = settings->protocol; |
|---|
| 181 | |
|---|
| 182 | nsettings.fFactor = settings->ffactor; |
|---|
| 183 | nsettings.dFactor = settings->dfactor; |
|---|
| 184 | nsettings.extClockDivisor = settings->ext_clock_divisor; |
|---|
| 185 | nsettings.txRetries = settings->tx_retries; |
|---|
| 186 | nsettings.rxRetries = settings->rx_retries; |
|---|
| 187 | |
|---|
| 188 | BDBG_CASSERT(NEXUS_TimerUnit_eMilliSec == bsmartcard_timer_unit_msec); |
|---|
| 189 | nsettings.workWaitTime.value = settings->work_wait_time.value; |
|---|
| 190 | nsettings.workWaitTime.unit = settings->work_wait_time.unit; |
|---|
| 191 | nsettings.blockWaitTime.value = settings->block_wait_time.value; |
|---|
| 192 | nsettings.blockWaitTime.unit = settings->block_wait_time.unit; |
|---|
| 193 | nsettings.extraGuardTime.value = settings->extra_guard_time.value; |
|---|
| 194 | nsettings.extraGuardTime.unit = settings->extra_guard_time.unit; |
|---|
| 195 | nsettings.blockGuardTime.value = settings->block_guard_time.value; |
|---|
| 196 | nsettings.blockGuardTime.unit = settings->block_guard_time.unit; |
|---|
| 197 | nsettings.characterWaitTime = settings->character_wait_time; |
|---|
| 198 | |
|---|
| 199 | BDBG_CASSERT(NEXUS_EdcEncode_eCrc == bsmartcard_edc_encode_crc); |
|---|
| 200 | nsettings.edcSetting.edcEncode = settings->edc_setting.edc_encode; |
|---|
| 201 | nsettings.edcSetting.isEnabled = settings->edc_setting.is_enabled; |
|---|
| 202 | nsettings.timeOut.value = settings->time_out.value; |
|---|
| 203 | nsettings.timeOut.unit = settings->time_out.unit; |
|---|
| 204 | nsettings.autoDeactiveReq = settings->auto_deactive_req; |
|---|
| 205 | nsettings.nullFilter = settings->null_filter; |
|---|
| 206 | |
|---|
| 207 | BDBG_CASSERT(NEXUS_ScPresMode_eMask == bsmartcard_sc_presmode_mask); |
|---|
| 208 | nsettings.scPresDbInfo.scPresMode = settings->sc_pres_dbinfo.sc_pres_mode; |
|---|
| 209 | nsettings.scPresDbInfo.isEnabled = settings->sc_pres_dbinfo.is_enabled; |
|---|
| 210 | nsettings.scPresDbInfo.dbWidth = settings->sc_pres_dbinfo.db_width; |
|---|
| 211 | |
|---|
| 212 | BDBG_CASSERT(NEXUS_ResetCardAction_eReceiveAndDecode == bsmartcard_reset_card_receive_decode); |
|---|
| 213 | nsettings.resetCardAction = settings->reset_card_action; |
|---|
| 214 | nsettings.blockWaitTimeExt.value = settings->block_wait_time_ext.value; |
|---|
| 215 | nsettings.blockWaitTimeExt.unit = settings->block_wait_time_ext.unit; |
|---|
| 216 | nsettings.isPresHigh = settings->is_pres_high; |
|---|
| 217 | |
|---|
| 218 | smartcard->settings = *settings; |
|---|
| 219 | |
|---|
| 220 | rc = NEXUS_Smartcard_SetSettings(smartcard->nSmartcard, &nsettings); |
|---|
| 221 | if (rc) return BERR_TRACE(rc); |
|---|
| 222 | |
|---|
| 223 | return b_ok; |
|---|
| 224 | #else |
|---|
| 225 | BSTD_UNUSED(smartcard); |
|---|
| 226 | BSTD_UNUSED(settings); |
|---|
| 227 | return BSETTOP_ERROR(berr_not_supported); |
|---|
| 228 | #endif |
|---|
| 229 | |
|---|
| 230 | } |
|---|
| 231 | |
|---|
| 232 | |
|---|
| 233 | #if NEXUS_HAS_SMARTCARD |
|---|
| 234 | static void bsmartcard_insert_p_callback(void *context) |
|---|
| 235 | { |
|---|
| 236 | bsmartcard_t smartcard = context; |
|---|
| 237 | if (smartcard->settings.card_insertion) { |
|---|
| 238 | b_unlock(); |
|---|
| 239 | smartcard->settings.card_insertion(smartcard->settings.callback_context); |
|---|
| 240 | b_lock(); |
|---|
| 241 | } |
|---|
| 242 | } |
|---|
| 243 | |
|---|
| 244 | static void bsmartcard_remove_p_callback(void *context) |
|---|
| 245 | { |
|---|
| 246 | bsmartcard_t smartcard = context; |
|---|
| 247 | if (smartcard->settings.card_removal) { |
|---|
| 248 | b_unlock(); |
|---|
| 249 | smartcard->settings.card_removal(smartcard->settings.callback_context); |
|---|
| 250 | b_lock(); |
|---|
| 251 | } |
|---|
| 252 | } |
|---|
| 253 | |
|---|
| 254 | void bsmartcard_p_event(void *context, int param) |
|---|
| 255 | { |
|---|
| 256 | BSTD_UNUSED(param); |
|---|
| 257 | BKNI_SetEvent((BKNI_EventHandle)context); |
|---|
| 258 | } |
|---|
| 259 | #endif |
|---|
| 260 | |
|---|
| 261 | bsmartcard_t bsmartcard_open( |
|---|
| 262 | bobject_t smartcard_id, /* smartcard object id */ |
|---|
| 263 | const bsmartcard_settings_t *settings /* smartcard settings */ |
|---|
| 264 | ) |
|---|
| 265 | { |
|---|
| 266 | #if NEXUS_HAS_SMARTCARD |
|---|
| 267 | unsigned int index; |
|---|
| 268 | NEXUS_SmartcardSettings smartcardSettings; |
|---|
| 269 | |
|---|
| 270 | BDBG_ASSERT(settings); |
|---|
| 271 | |
|---|
| 272 | index = B_ID_GET_INDEX(smartcard_id); |
|---|
| 273 | |
|---|
| 274 | if (index >= NEXUS_NUM_SMARTCARD_CHANNELS) { |
|---|
| 275 | BSETTOP_ERROR(berr_invalid_parameter); |
|---|
| 276 | return NULL; |
|---|
| 277 | } |
|---|
| 278 | |
|---|
| 279 | if (cliChannel[index].nSmartcard) { |
|---|
| 280 | /* already open */ |
|---|
| 281 | return NULL; |
|---|
| 282 | } |
|---|
| 283 | |
|---|
| 284 | NEXUS_Smartcard_GetDefaultSettings(&smartcardSettings); |
|---|
| 285 | |
|---|
| 286 | cliChannel[index].settings.card_insertion = settings->card_insertion; |
|---|
| 287 | cliChannel[index].settings.card_removal = settings->card_removal; |
|---|
| 288 | cliChannel[index].settings.callback_context = settings->callback_context; |
|---|
| 289 | |
|---|
| 290 | |
|---|
| 291 | switch (settings->standard) { |
|---|
| 292 | case bsmartcard_standard_nds: |
|---|
| 293 | smartcardSettings.standard = NEXUS_SmartcardStandard_eNds; |
|---|
| 294 | break; |
|---|
| 295 | case bsmartcard_standard_iso: |
|---|
| 296 | smartcardSettings.standard = NEXUS_SmartcardStandard_eIso; |
|---|
| 297 | break; |
|---|
| 298 | case bsmartcard_standard_irdeto: |
|---|
| 299 | smartcardSettings.standard = NEXUS_SmartcardStandard_eEmv2000; |
|---|
| 300 | break; |
|---|
| 301 | default: |
|---|
| 302 | smartcardSettings.standard = NEXUS_SmartcardStandard_eUnknown; |
|---|
| 303 | break; |
|---|
| 304 | } |
|---|
| 305 | |
|---|
| 306 | smartcardSettings.protocol = settings->protocol; |
|---|
| 307 | smartcardSettings.fFactor = settings->ffactor; |
|---|
| 308 | smartcardSettings.dFactor = settings->dfactor; |
|---|
| 309 | smartcardSettings.extClockDivisor = settings->ext_clock_divisor; |
|---|
| 310 | smartcardSettings.txRetries = settings->tx_retries; |
|---|
| 311 | smartcardSettings.rxRetries = settings->rx_retries; |
|---|
| 312 | smartcardSettings.workWaitTime.unit= settings->work_wait_time.unit; |
|---|
| 313 | smartcardSettings.workWaitTime.value= settings->work_wait_time.value; |
|---|
| 314 | smartcardSettings.blockWaitTime.unit= settings->block_wait_time.unit; |
|---|
| 315 | smartcardSettings.blockWaitTime.value= settings->block_wait_time.value; |
|---|
| 316 | smartcardSettings.extraGuardTime.unit= settings->extra_guard_time.unit; |
|---|
| 317 | smartcardSettings.extraGuardTime.value= settings->extra_guard_time.value; |
|---|
| 318 | smartcardSettings.blockGuardTime.unit= settings->block_guard_time.unit; |
|---|
| 319 | smartcardSettings.blockGuardTime.value= settings->block_guard_time.value; |
|---|
| 320 | smartcardSettings.characterWaitTime = settings->character_wait_time; |
|---|
| 321 | smartcardSettings.edcSetting.edcEncode = settings->edc_setting.edc_encode; |
|---|
| 322 | smartcardSettings.edcSetting.isEnabled = settings->edc_setting.is_enabled; |
|---|
| 323 | smartcardSettings.timeOut.unit = settings->time_out.unit; |
|---|
| 324 | smartcardSettings.timeOut.value = settings->time_out.value; |
|---|
| 325 | smartcardSettings.autoDeactiveReq = settings->auto_deactive_req; |
|---|
| 326 | smartcardSettings.nullFilter = settings->null_filter; |
|---|
| 327 | smartcardSettings.scPresDbInfo.dbWidth = settings->sc_pres_dbinfo.db_width; |
|---|
| 328 | smartcardSettings.scPresDbInfo.isEnabled = settings->sc_pres_dbinfo.is_enabled; |
|---|
| 329 | smartcardSettings.scPresDbInfo.scPresMode = settings->sc_pres_dbinfo.sc_pres_mode; |
|---|
| 330 | smartcardSettings.resetCardAction = settings->reset_card_action; |
|---|
| 331 | smartcardSettings.blockWaitTimeExt.unit = settings->block_wait_time_ext.unit; |
|---|
| 332 | smartcardSettings.blockWaitTimeExt.value = settings->block_wait_time_ext.value; |
|---|
| 333 | smartcardSettings.isPresHigh = settings->is_pres_high; |
|---|
| 334 | |
|---|
| 335 | BKNI_CreateEvent(&cliChannel[index].insertCardEvent); |
|---|
| 336 | cliChannel[index].insertCardEventId = b_event_register(cliChannel[index].insertCardEvent, bsmartcard_insert_p_callback, &cliChannel[index]); |
|---|
| 337 | if (!cliChannel[index].insertCardEventId) { |
|---|
| 338 | goto error; |
|---|
| 339 | } |
|---|
| 340 | |
|---|
| 341 | BKNI_CreateEvent(&cliChannel[index].removeCardEvent); |
|---|
| 342 | cliChannel[index].removeCardEventId = b_event_register(cliChannel[index].removeCardEvent, bsmartcard_remove_p_callback, &cliChannel[index]); |
|---|
| 343 | if (!cliChannel[index].removeCardEventId) { |
|---|
| 344 | goto error; |
|---|
| 345 | } |
|---|
| 346 | smartcardSettings.insertCard.callback = bsmartcard_p_event; |
|---|
| 347 | smartcardSettings.insertCard.context = cliChannel[index].insertCardEvent; |
|---|
| 348 | |
|---|
| 349 | smartcardSettings.removeCard.callback = bsmartcard_p_event; |
|---|
| 350 | smartcardSettings.removeCard.context = cliChannel[index].removeCardEvent; |
|---|
| 351 | |
|---|
| 352 | cliChannel[index].nSmartcard = NEXUS_Smartcard_Open(index, &smartcardSettings); |
|---|
| 353 | if (!cliChannel[index].nSmartcard) { |
|---|
| 354 | return NULL; |
|---|
| 355 | } |
|---|
| 356 | |
|---|
| 357 | return &cliChannel[index]; |
|---|
| 358 | |
|---|
| 359 | error: |
|---|
| 360 | if(cliChannel[index].insertCardEvent) |
|---|
| 361 | BKNI_DestroyEvent(cliChannel[index].insertCardEvent); |
|---|
| 362 | if(cliChannel[index].removeCardEvent) |
|---|
| 363 | BKNI_DestroyEvent(cliChannel[index].removeCardEvent); |
|---|
| 364 | |
|---|
| 365 | return NULL; |
|---|
| 366 | #else |
|---|
| 367 | BSTD_UNUSED(smartcard_id); |
|---|
| 368 | BSTD_UNUSED(settings); |
|---|
| 369 | BSETTOP_ERROR(berr_not_supported); |
|---|
| 370 | return NULL; |
|---|
| 371 | #endif |
|---|
| 372 | } |
|---|
| 373 | |
|---|
| 374 | void bsmartcard_close( |
|---|
| 375 | bsmartcard_t smartcard /* handle returned by bsmartcard_open */ |
|---|
| 376 | ) |
|---|
| 377 | { |
|---|
| 378 | #if NEXUS_HAS_SMARTCARD |
|---|
| 379 | BDBG_MSG(("assert(smartcard)")); |
|---|
| 380 | BDBG_ASSERT(smartcard); |
|---|
| 381 | |
|---|
| 382 | b_event_unregister(smartcard->insertCardEventId); |
|---|
| 383 | b_event_unregister(smartcard->removeCardEventId); |
|---|
| 384 | |
|---|
| 385 | if(smartcard->insertCardEvent) |
|---|
| 386 | BKNI_DestroyEvent(smartcard->insertCardEvent); |
|---|
| 387 | if(smartcard->removeCardEvent) |
|---|
| 388 | BKNI_DestroyEvent(smartcard->removeCardEvent); |
|---|
| 389 | |
|---|
| 390 | BDBG_MSG(("bsmartcard_close")); |
|---|
| 391 | NEXUS_Smartcard_Close(smartcard->nSmartcard); |
|---|
| 392 | smartcard->nSmartcard=NULL; |
|---|
| 393 | #else |
|---|
| 394 | BSTD_UNUSED(smartcard); |
|---|
| 395 | BSETTOP_ERROR(berr_not_supported); |
|---|
| 396 | #endif |
|---|
| 397 | } |
|---|
| 398 | |
|---|
| 399 | bresult bsmartcard_read( |
|---|
| 400 | bsmartcard_t smartcard, /* handle returned by bsmartcard_open */ |
|---|
| 401 | void *data, /* [out,size_is(length)] memory to read into */ |
|---|
| 402 | size_t length, /* maximum number of bytes to read */ |
|---|
| 403 | size_t *length_read /* [out] amount of data read into memory */ |
|---|
| 404 | ) |
|---|
| 405 | { |
|---|
| 406 | #if NEXUS_HAS_SMARTCARD |
|---|
| 407 | NEXUS_Error rc; |
|---|
| 408 | |
|---|
| 409 | rc = NEXUS_Smartcard_Read(smartcard->nSmartcard, data, length, length_read); |
|---|
| 410 | if (rc) BSETTOP_ERROR(berr_external_error); |
|---|
| 411 | |
|---|
| 412 | return b_ok; |
|---|
| 413 | #else |
|---|
| 414 | BSTD_UNUSED(smartcard); |
|---|
| 415 | BSTD_UNUSED(data); |
|---|
| 416 | BSTD_UNUSED(length); |
|---|
| 417 | BSTD_UNUSED(length_read); |
|---|
| 418 | return BSETTOP_ERROR(berr_not_supported); |
|---|
| 419 | #endif |
|---|
| 420 | } |
|---|
| 421 | |
|---|
| 422 | bresult bsmartcard_write( |
|---|
| 423 | bsmartcard_t smartcard, /* handle returned by bsmartcard_open */ |
|---|
| 424 | const void *data, /* [size_is(length)] memory to write from */ |
|---|
| 425 | size_t length, /* maximum number of bytes to write */ |
|---|
| 426 | size_t *length_written /* [out] amount of data written */ |
|---|
| 427 | ) |
|---|
| 428 | { |
|---|
| 429 | #if NEXUS_HAS_SMARTCARD |
|---|
| 430 | NEXUS_Error rc; |
|---|
| 431 | |
|---|
| 432 | rc = NEXUS_Smartcard_Write(smartcard->nSmartcard, data, length, length_written); |
|---|
| 433 | if (rc) BSETTOP_ERROR(berr_external_error); |
|---|
| 434 | |
|---|
| 435 | return b_ok; |
|---|
| 436 | #else |
|---|
| 437 | BSTD_UNUSED(smartcard); |
|---|
| 438 | BSTD_UNUSED(data); |
|---|
| 439 | BSTD_UNUSED(length); |
|---|
| 440 | BSTD_UNUSED(length_written); |
|---|
| 441 | return BSETTOP_ERROR(berr_not_supported); |
|---|
| 442 | #endif |
|---|
| 443 | } |
|---|
| 444 | |
|---|
| 445 | bresult bsmartcard_get_status( |
|---|
| 446 | bsmartcard_t smartcard, |
|---|
| 447 | bsmartcard_status *status /* [out] Fills in the status information. */ |
|---|
| 448 | ) |
|---|
| 449 | { |
|---|
| 450 | #if NEXUS_HAS_SMARTCARD |
|---|
| 451 | NEXUS_Error rc; |
|---|
| 452 | NEXUS_SmartcardStatus nStatus; |
|---|
| 453 | |
|---|
| 454 | |
|---|
| 455 | rc = NEXUS_Smartcard_GetStatus(smartcard->nSmartcard, &nStatus); |
|---|
| 456 | if (rc) BSETTOP_ERROR(berr_external_error); |
|---|
| 457 | |
|---|
| 458 | status->card_present = nStatus.cardPresent; |
|---|
| 459 | status->err = nStatus.err; |
|---|
| 460 | status->state = nStatus.state; |
|---|
| 461 | |
|---|
| 462 | return b_ok; |
|---|
| 463 | #else |
|---|
| 464 | BSTD_UNUSED(smartcard); |
|---|
| 465 | BSTD_UNUSED(status); |
|---|
| 466 | return BSETTOP_ERROR(berr_not_supported); |
|---|
| 467 | #endif |
|---|
| 468 | } |
|---|
| 469 | |
|---|
| 470 | bresult bsmartcard_reset_card( |
|---|
| 471 | bsmartcard_t smartcard, /* handle returned by bsmartcard_open */ |
|---|
| 472 | void *data, /* [out,size_is(length)] pointer to memory that can be read into */ |
|---|
| 473 | size_t length, /* maximum number of bytes pointed to by data */ |
|---|
| 474 | size_t *length_read /* [out] length of data read into the data field. */ |
|---|
| 475 | ) |
|---|
| 476 | { |
|---|
| 477 | #if NEXUS_HAS_SMARTCARD |
|---|
| 478 | NEXUS_Error rc; |
|---|
| 479 | rc = NEXUS_Smartcard_ResetCard(smartcard->nSmartcard, data, length, length_read); |
|---|
| 480 | if (rc) return BSETTOP_ERROR(berr_external_error); |
|---|
| 481 | |
|---|
| 482 | return b_ok; |
|---|
| 483 | #else |
|---|
| 484 | BSTD_UNUSED(smartcard); |
|---|
| 485 | BSTD_UNUSED(data); |
|---|
| 486 | BSTD_UNUSED(length); |
|---|
| 487 | BSTD_UNUSED(length_read); |
|---|
| 488 | return BSETTOP_ERROR(berr_not_supported); |
|---|
| 489 | #endif |
|---|
| 490 | } |
|---|
| 491 | |
|---|
| 492 | bresult bsmartcard_reset( |
|---|
| 493 | bsmartcard_t smartcard, /* handle returned by bsmartcard_open */ |
|---|
| 494 | bool warm_reset /* true for a warm reset, false for a cold reset */ |
|---|
| 495 | ) |
|---|
| 496 | { |
|---|
| 497 | #if NEXUS_HAS_SMARTCARD |
|---|
| 498 | NEXUS_Error rc; |
|---|
| 499 | rc = NEXUS_Smartcard_Reset(smartcard->nSmartcard, warm_reset); |
|---|
| 500 | if (rc) BSETTOP_ERROR(berr_external_error); |
|---|
| 501 | |
|---|
| 502 | return b_ok; |
|---|
| 503 | #else |
|---|
| 504 | BSTD_UNUSED(smartcard); |
|---|
| 505 | BSTD_UNUSED(warm_reset); |
|---|
| 506 | return BSETTOP_ERROR(berr_not_supported); |
|---|
| 507 | #endif |
|---|
| 508 | } |
|---|
| 509 | |
|---|
| 510 | bresult bsmartcard_detect_card( /* name changed: was bsmartcard_detectCardPres */ |
|---|
| 511 | bsmartcard_t smartcard |
|---|
| 512 | ) |
|---|
| 513 | { |
|---|
| 514 | #if NEXUS_HAS_SMARTCARD |
|---|
| 515 | NEXUS_Error rc; |
|---|
| 516 | rc = NEXUS_Smartcard_DetectCard( smartcard->nSmartcard); |
|---|
| 517 | if (rc) BSETTOP_ERROR(berr_external_error); |
|---|
| 518 | |
|---|
| 519 | return b_ok; |
|---|
| 520 | #else |
|---|
| 521 | BSTD_UNUSED(smartcard); |
|---|
| 522 | return BSETTOP_ERROR(berr_not_supported); |
|---|
| 523 | #endif |
|---|
| 524 | } |
|---|
| 525 | |
|---|
| 526 | void bsmartcard_shutdown(void) |
|---|
| 527 | { |
|---|
| 528 | return; |
|---|
| 529 | } |
|---|
| 530 | |
|---|