source: svn/trunk/newcon3bcm2_21bu/dta/src/settop_api/bsettop_smartcard.h

Last change on this file was 2, checked in by phkim, 11 years ago

1.phkim

  1. revision copy newcon3sk r27
  • Property svn:executable set to *
File size: 8.1 KB
Line 
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
27extern "C"
28{
29#endif
30
31/*=*************************
32Smartcard (bsmartcard_t) supports a read/write interface to the smartcard along with
33reset functions.
34
35Asynchronous I/O is not supported yet.
36****************************/
37
38/*
39Summary:
40        Smartcard handle returned by bsmartcard_open.
41*/
42typedef struct bsmartcard *bsmartcard_t;
43
44/*
45Summary:
46        Smartcard protocol enum definition.
47*/
48typedef enum bsmartcard_protocol {
49        bsmartcard_protocol_unknown,
50        bsmartcard_protocol_t0,
51        bsmartcard_protocol_t1,
52        bsmartcard_protocol_t14
53} bsmartcard_protocol;
54
55/*
56Summary:
57        Smartcard standard enum definition.
58*/
59typedef enum bsmartcard_standard {
60        bsmartcard_standard_nds,
61        bsmartcard_standard_iso,
62        bsmartcard_standard_emv2000,
63        bsmartcard_standard_irdeto
64} bsmartcard_standard;
65
66/*
67Summary:
68        Smartcard settings structure.
69Description:
70        Smartcard settings structure, used by bsmartcard_open. 
71This allows protocol (T=0, T=1, T=14) and standard (NDS, ISO, EMV2000, IRDETO) to be selected.
72*/
73typedef 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/*
82Summary:
83        Smartcard setting structure initialization.
84Description:
85        This function initializes the smartcard settings structure to defaults.
86*/
87void bsmartcard_settings_init(
88        bsmartcard_settings_t *settings
89);
90
91/*
92Summary:
93        Open a smart object which corresponds to one smartcard reader.
94Description:
95*/
96bsmartcard_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/*
103Summary:
104        Close a smartcard object.
105Description:
106        After closing, the bsmartcard_t handle is invalid.
107*/
108void bsmartcard_close(
109        bsmartcard_t smartcard /* handle returned by bsmartcard_open */
110);
111
112/*
113Summary:
114        Read data from the smartcard.
115
116Description:
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*/
126bresult 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/*
134Summary:
135        Write data to the smartcard.
136
137Description:
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*/
147bresult 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/*
157Summary:
158        Smartcard error status enum.
159*/
160typedef 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/*
171Summary:
172        Smartcard state enum.
173Description:
174        This represents the current state of the given slot and card.
175*/
176typedef 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/*
192Summary:
193        Status information returned by bsmartcard_get_status.
194*/
195typedef struct bsmartcard_status {
196        bool card_present;
197        bsmartcard_error err;
198        bsmartcard_state state;
199} bsmartcard_status;
200
201/*
202Summary:
203Get the status of the smartcard interface.
204Description:
205This function must be called after read or write fails in order to determine the
206state of the smartcard interface.
207*/
208bresult bsmartcard_get_status(
209        bsmartcard_t smartcard,
210        bsmartcard_status *status               /* [out] Fills in the status information. */
211);
212
213/*
214Summary:
215        Reset a smartcard.
216Description:
217        Reset the smartcard itself.
218*/
219bresult 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/*
227Summary:
228        Reset the smartcard interface.
229Description:
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*/
235bresult 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/*
242Summary:
243        Detect the card insertion.
244Description:
245        The function will be blocked until the card is inserted.
246*/
247bresult bsmartcard_detect_card( /* name changed: was bsmartcard_detectCardPres */
248                bsmartcard_t smartcard
249);
250
251/*
252Summary:
253        Set the interface paramenters after interpreting ATR data.
254Description:
255        The function set the interface paramenters after interpreting ATR data.
256*/
257bresult bsmartcard_set_params_from_atr( /* name changed: was bsmartcard_SetParameters */
258                bsmartcard_t smartcard
259);
260
261
262/*
263Summary:
264        Smartcard initialization.
265Description:
266        The function initializes the smartcard module.
267*/
268bresult bsmartcard_init(void);
269
270/*
271Summary:
272        Smartcard shutdown.
273Description:
274        The function shutdowns the smartcard module.
275*/
276
277void bsmartcard_shutdown(void);
278
279
280#ifdef __cplusplus
281}
282#endif
283
284
285#endif /* BSETTOP_SMARTCARD_H__ */
Note: See TracBrowser for help on using the repository browser.