| 1 | /*************************************************************************** |
|---|
| 2 | * Copyright (c) 2009-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: $ |
|---|
| 11 | * $brcm_Revision: $ |
|---|
| 12 | * $brcm_Date: $ |
|---|
| 13 | * |
|---|
| 14 | * Module Description: |
|---|
| 15 | * |
|---|
| 16 | * Revision History: |
|---|
| 17 | * |
|---|
| 18 | * $brcm_Log: $ |
|---|
| 19 | * |
|---|
| 20 | ***************************************************************************/ |
|---|
| 21 | #ifndef BSETTOP_SMARTCARD_H__ |
|---|
| 22 | #define BSETTOP_SMARTCARD_H__ |
|---|
| 23 | |
|---|
| 24 | #include "bsettop_types.h" |
|---|
| 25 | |
|---|
| 26 | #ifdef __cplusplus |
|---|
| 27 | extern "C" |
|---|
| 28 | { |
|---|
| 29 | #endif |
|---|
| 30 | |
|---|
| 31 | /*=************************* |
|---|
| 32 | Smartcard (bsmartcard_t) supports a read/write interface to the smartcard along with |
|---|
| 33 | reset functions. |
|---|
| 34 | |
|---|
| 35 | Asynchronous I/O is not supported yet. |
|---|
| 36 | ****************************/ |
|---|
| 37 | |
|---|
| 38 | /* |
|---|
| 39 | Summary: |
|---|
| 40 | Smartcard handle returned by bsmartcard_open. |
|---|
| 41 | */ |
|---|
| 42 | typedef struct bsmartcard *bsmartcard_t; |
|---|
| 43 | |
|---|
| 44 | /* |
|---|
| 45 | Summary: |
|---|
| 46 | Smartcard protocol enum definition. |
|---|
| 47 | */ |
|---|
| 48 | typedef enum bsmartcard_protocol { |
|---|
| 49 | bsmartcard_protocol_unknown, |
|---|
| 50 | bsmartcard_protocol_t0, |
|---|
| 51 | bsmartcard_protocol_t1, |
|---|
| 52 | bsmartcard_protocol_t14 |
|---|
| 53 | } bsmartcard_protocol; |
|---|
| 54 | |
|---|
| 55 | /* |
|---|
| 56 | Summary: |
|---|
| 57 | Smartcard standard enum definition. |
|---|
| 58 | */ |
|---|
| 59 | typedef enum bsmartcard_standard { |
|---|
| 60 | bsmartcard_standard_nds, |
|---|
| 61 | bsmartcard_standard_iso, |
|---|
| 62 | bsmartcard_standard_emv2000, |
|---|
| 63 | bsmartcard_standard_irdeto |
|---|
| 64 | } bsmartcard_standard; |
|---|
| 65 | |
|---|
| 66 | /* |
|---|
| 67 | Summary: |
|---|
| 68 | Smartcard settings structure. |
|---|
| 69 | Description: |
|---|
| 70 | Smartcard settings structure, used by bsmartcard_open. |
|---|
| 71 | This allows protocol (T=0, T=1, T=14) and standard (NDS, ISO, EMV2000, IRDETO) to be selected. |
|---|
| 72 | */ |
|---|
| 73 | typedef struct bsmartcard_settings { |
|---|
| 74 | bsmartcard_protocol protocol; |
|---|
| 75 | bsmartcard_standard standard; |
|---|
| 76 | void *callback_context; /* Context pointer, returned in the callback functions */ |
|---|
| 77 | void (*card_insertion)(void *context); /* Called when a card is inserted */ |
|---|
| 78 | void (*card_removal)(void *context); /* Called when a card is removed */ |
|---|
| 79 | } bsmartcard_settings_t; |
|---|
| 80 | |
|---|
| 81 | /* |
|---|
| 82 | Summary: |
|---|
| 83 | Smartcard setting structure initialization. |
|---|
| 84 | Description: |
|---|
| 85 | This function initializes the smartcard settings structure to defaults. |
|---|
| 86 | */ |
|---|
| 87 | void bsmartcard_settings_init( |
|---|
| 88 | bsmartcard_settings_t *settings |
|---|
| 89 | ); |
|---|
| 90 | |
|---|
| 91 | /* |
|---|
| 92 | Summary: |
|---|
| 93 | Open a smart object which corresponds to one smartcard reader. |
|---|
| 94 | Description: |
|---|
| 95 | */ |
|---|
| 96 | bsmartcard_t bsmartcard_open( |
|---|
| 97 | bobject_t smartcard_id, /* smartcard object id */ |
|---|
| 98 | bsmartcard_t *smartcard, |
|---|
| 99 | const bsmartcard_settings_t *settings /* smartcard settings */ |
|---|
| 100 | ); |
|---|
| 101 | |
|---|
| 102 | /* |
|---|
| 103 | Summary: |
|---|
| 104 | Close a smartcard object. |
|---|
| 105 | Description: |
|---|
| 106 | After closing, the bsmartcard_t handle is invalid. |
|---|
| 107 | */ |
|---|
| 108 | void bsmartcard_close( |
|---|
| 109 | bsmartcard_t smartcard /* handle returned by bsmartcard_open */ |
|---|
| 110 | ); |
|---|
| 111 | |
|---|
| 112 | /* |
|---|
| 113 | Summary: |
|---|
| 114 | Read data from the smartcard. |
|---|
| 115 | |
|---|
| 116 | Description: |
|---|
| 117 | If you don't call bsmartcard_set_async, this function will block until it can return |
|---|
| 118 | some data or returns an error. |
|---|
| 119 | |
|---|
| 120 | If you call bsmartcard_set_async, this function will never block and will return |
|---|
| 121 | either some data, no data or an error. |
|---|
| 122 | |
|---|
| 123 | If read fails, you should call bsmartcard_get_status in order to determine |
|---|
| 124 | the state of the smartcard interface. |
|---|
| 125 | */ |
|---|
| 126 | bresult bsmartcard_read( |
|---|
| 127 | bsmartcard_t smartcard, /* handle returned by bsmartcard_open */ |
|---|
| 128 | void *data, /* [out,size_is(length)] memory to read into */ |
|---|
| 129 | size_t length, /* maximum number of bytes to read */ |
|---|
| 130 | size_t *length_read /* [out] amount of data read into memory */ |
|---|
| 131 | ); |
|---|
| 132 | |
|---|
| 133 | /* |
|---|
| 134 | Summary: |
|---|
| 135 | Write data to the smartcard. |
|---|
| 136 | |
|---|
| 137 | Description: |
|---|
| 138 | If you don't call bsmartcard_set_async, this function will block until it can write |
|---|
| 139 | some data or returns an error. |
|---|
| 140 | |
|---|
| 141 | If you call bsmartcard_set_async, this function will never block and will write |
|---|
| 142 | some data or return an error. |
|---|
| 143 | |
|---|
| 144 | If write fails, you should call bsmartcard_get_status in order to determine |
|---|
| 145 | the state of the smartcard interface. |
|---|
| 146 | */ |
|---|
| 147 | bresult bsmartcard_write( |
|---|
| 148 | bsmartcard_t smartcard, /* handle returned by bsmartcard_open */ |
|---|
| 149 | const void *data, /* [size_is(length)] memory to write from */ |
|---|
| 150 | size_t length, /* maximum number of bytes to write */ |
|---|
| 151 | size_t *length_written /* [out] amount of data written */ |
|---|
| 152 | ); |
|---|
| 153 | |
|---|
| 154 | /* TODO: need async notification of status change using bsettop_event */ |
|---|
| 155 | |
|---|
| 156 | /* |
|---|
| 157 | Summary: |
|---|
| 158 | Smartcard error status enum. |
|---|
| 159 | */ |
|---|
| 160 | typedef enum bsmartcard_error { |
|---|
| 161 | bsmartcard_no_error, |
|---|
| 162 | bsmartcard_err_rx_parity, |
|---|
| 163 | bsmartcard_err_tx_parity, |
|---|
| 164 | bsmartcard_err_rx_timeout, |
|---|
| 165 | bsmartcard_err_tx_timeout, |
|---|
| 166 | bsmartcard_err_hardware_failure, |
|---|
| 167 | bsmartcard_err_reset_terminal /* requires a call to bsmartcard_reset() */ |
|---|
| 168 | } bsmartcard_error; |
|---|
| 169 | |
|---|
| 170 | /* |
|---|
| 171 | Summary: |
|---|
| 172 | Smartcard state enum. |
|---|
| 173 | Description: |
|---|
| 174 | This represents the current state of the given slot and card. |
|---|
| 175 | */ |
|---|
| 176 | typedef enum bsmartcard_state { |
|---|
| 177 | bsmartcard_state_unknown = 0, /* Unknown state (perhaps not yet initialized). Persistent. */ |
|---|
| 178 | bsmartcard_state_cold_resetting, /* A cold reset has been requested but is not yet complete. Transient. */ |
|---|
| 179 | bsmartcard_state_warm_resetting, /* A warm reset has been requested but is not yet complete. Transient. */ |
|---|
| 180 | bsmartcard_state_reset_done, /* The slot/card reset has completed. Persistent. */ |
|---|
| 181 | bsmartcard_state_activating, /* The slot/card is currently being activated, but activation is not yet complete. Transient. */ |
|---|
| 182 | bsmartcard_state_receive_decode_atr, /* The ATR is being received or decoded. Transient. */ |
|---|
| 183 | bsmartcard_state_ready, /* The slot/card is initialized and is awaiting sends/receives. Persistent. */ |
|---|
| 184 | bsmartcard_state_transmitting, /* The slot/card is currently transmitting. Transient. */ |
|---|
| 185 | bsmartcard_state_transmitted, /* The slot/card has completed its transmission. Persistent. */ |
|---|
| 186 | bsmartcard_state_receiving, /* The slot/card is currently receiving. Transient. */ |
|---|
| 187 | bsmartcard_state_ignore, /* The slot/card is ignoring events/commands. Persistent. */ |
|---|
| 188 | bsmartcard_state_initialized, /* The slot/card has been initialized, but the ATR has not yet been received. Persistent. */ |
|---|
| 189 | bsmartcard_state_max_state /* A value indicating the total number of possible states. The state returned from bsmartcard_get_status should never exceed this value. */ |
|---|
| 190 | } bsmartcard_state; |
|---|
| 191 | /* |
|---|
| 192 | Summary: |
|---|
| 193 | Status information returned by bsmartcard_get_status. |
|---|
| 194 | */ |
|---|
| 195 | typedef struct bsmartcard_status { |
|---|
| 196 | bool card_present; |
|---|
| 197 | bsmartcard_error err; |
|---|
| 198 | bsmartcard_state state; |
|---|
| 199 | } bsmartcard_status; |
|---|
| 200 | |
|---|
| 201 | /* |
|---|
| 202 | Summary: |
|---|
| 203 | Get the status of the smartcard interface. |
|---|
| 204 | Description: |
|---|
| 205 | This function must be called after read or write fails in order to determine the |
|---|
| 206 | state of the smartcard interface. |
|---|
| 207 | */ |
|---|
| 208 | bresult bsmartcard_get_status( |
|---|
| 209 | bsmartcard_t smartcard, |
|---|
| 210 | bsmartcard_status *status /* [out] Fills in the status information. */ |
|---|
| 211 | ); |
|---|
| 212 | |
|---|
| 213 | /* |
|---|
| 214 | Summary: |
|---|
| 215 | Reset a smartcard. |
|---|
| 216 | Description: |
|---|
| 217 | Reset the smartcard itself. |
|---|
| 218 | */ |
|---|
| 219 | bresult bsmartcard_reset_card( |
|---|
| 220 | bsmartcard_t smartcard, /* handle returned by bsmartcard_open */ |
|---|
| 221 | void *data, /* [out,size_is(length)] pointer to memory that can be read into */ |
|---|
| 222 | size_t length, /* maximum number of bytes pointed to by data */ |
|---|
| 223 | size_t *length_read /* [out] length of data read into the data field. */ |
|---|
| 224 | ); |
|---|
| 225 | |
|---|
| 226 | /* |
|---|
| 227 | Summary: |
|---|
| 228 | Reset the smartcard interface. |
|---|
| 229 | Description: |
|---|
| 230 | Reprogram all the Broadcom smartcard interface, not the card. |
|---|
| 231 | If you want to reset the card, use bsmartcard_reset_card. |
|---|
| 232 | |
|---|
| 233 | The interface must be reset whenever a card is inserted. |
|---|
| 234 | */ |
|---|
| 235 | bresult bsmartcard_reset( |
|---|
| 236 | bsmartcard_t smartcard, /* handle returned by bsmartcard_open */ |
|---|
| 237 | bool warm_reset /* true for a warm reset, false for a cold reset */ |
|---|
| 238 | ); |
|---|
| 239 | |
|---|
| 240 | |
|---|
| 241 | /* |
|---|
| 242 | Summary: |
|---|
| 243 | Detect the card insertion. |
|---|
| 244 | Description: |
|---|
| 245 | The function will be blocked until the card is inserted. |
|---|
| 246 | */ |
|---|
| 247 | bresult bsmartcard_detect_card( /* name changed: was bsmartcard_detectCardPres */ |
|---|
| 248 | bsmartcard_t smartcard |
|---|
| 249 | ); |
|---|
| 250 | |
|---|
| 251 | /* |
|---|
| 252 | Summary: |
|---|
| 253 | Set the interface paramenters after interpreting ATR data. |
|---|
| 254 | Description: |
|---|
| 255 | The function set the interface paramenters after interpreting ATR data. |
|---|
| 256 | */ |
|---|
| 257 | bresult bsmartcard_set_params_from_atr( /* name changed: was bsmartcard_SetParameters */ |
|---|
| 258 | bsmartcard_t smartcard |
|---|
| 259 | ); |
|---|
| 260 | |
|---|
| 261 | |
|---|
| 262 | /* |
|---|
| 263 | Summary: |
|---|
| 264 | Smartcard initialization. |
|---|
| 265 | Description: |
|---|
| 266 | The function initializes the smartcard module. |
|---|
| 267 | */ |
|---|
| 268 | bresult bsmartcard_init(void); |
|---|
| 269 | |
|---|
| 270 | /* |
|---|
| 271 | Summary: |
|---|
| 272 | Smartcard shutdown. |
|---|
| 273 | Description: |
|---|
| 274 | The function shutdowns the smartcard module. |
|---|
| 275 | */ |
|---|
| 276 | |
|---|
| 277 | void bsmartcard_shutdown(void); |
|---|
| 278 | |
|---|
| 279 | |
|---|
| 280 | #ifdef __cplusplus |
|---|
| 281 | } |
|---|
| 282 | #endif |
|---|
| 283 | |
|---|
| 284 | |
|---|
| 285 | #endif /* BSETTOP_SMARTCARD_H__ */ |
|---|