FreeCalypso > hg > fc-tourmaline
comparison src/cs/drivers/drv_app/sim/sim.h @ 190:2e4afc93045d
../drv_app/sim/sim.h: white space fixes
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 30 Jan 2021 06:43:44 +0000 |
parents | b37e6c916df1 |
children |
comparison
equal
deleted
inserted
replaced
189:b37e6c916df1 | 190:2e4afc93045d |
---|---|
20 #endif | 20 #endif |
21 | 21 |
22 #include "nucleus.h" | 22 #include "nucleus.h" |
23 | 23 |
24 /* Flags activation section */ | 24 /* Flags activation section */ |
25 // #define SIM_RETRY /* by default : NOT ACTIVE */ | 25 //#define SIM_RETRY /* by default : NOT ACTIVE */ |
26 //#define SIM_DEBUG_TRACE /* by default : NOT ACTIVE */ | 26 //#define SIM_DEBUG_TRACE /* by default : NOT ACTIVE */ |
27 //#define SIM_UWORD16_MASK 0x00ff //when using SIM entity not maped to length on 16 bits | 27 //#define SIM_UWORD16_MASK 0x00ff //when using SIM entity not maped to length on 16 bits |
28 #define SIM_UWORD16_MASK 0xffff //when using SIM entity maped to length on 16 bits | 28 #define SIM_UWORD16_MASK 0xffff //when using SIM entity maped to length on 16 bits |
29 //#define SIM_APDU_TEST | 29 //#define SIM_APDU_TEST |
30 //#define SIM_SAT_REFRESH_TEST | 30 //#define SIM_SAT_REFRESH_TEST |
31 | 31 |
37 #define SIM_DRX (MEM_SIM + 0x0A) | 37 #define SIM_DRX (MEM_SIM + 0x0A) |
38 #define SIM_DTX (MEM_SIM + 0x0C) | 38 #define SIM_DTX (MEM_SIM + 0x0C) |
39 #define SIM_MASK (MEM_SIM + 0x0E) | 39 #define SIM_MASK (MEM_SIM + 0x0E) |
40 | 40 |
41 | 41 |
42 | |
43 /* | 42 /* |
44 * Bit definitions | 43 * Bit definitions |
45 */ | 44 */ |
46 // control regidter | 45 // control regidter |
47 #define SIM_CMD_CRST 0x0001 | 46 #define SIM_CMD_CRST 0x0001 |
60 #define SIM_CONF1_CHKPAR 0x0001 // enable receipt check parity | 59 #define SIM_CONF1_CHKPAR 0x0001 // enable receipt check parity |
61 #define SIM_CONF1_CONV 0x0002 // coding convention | 60 #define SIM_CONF1_CONV 0x0002 // coding convention |
62 #define SIM_CONF1_TXRX 0x0004 // SIO line direction | 61 #define SIM_CONF1_TXRX 0x0004 // SIO line direction |
63 #define SIM_CONF1_SCLKEN 0x0008 // enable SIM clock | 62 #define SIM_CONF1_SCLKEN 0x0008 // enable SIM clock |
64 #define SIM_CONF1_RSVD 0x0010 // reserved | 63 #define SIM_CONF1_RSVD 0x0010 // reserved |
65 #define SIM_CONF1_SCLKDIV 0x0020 // SIM clock frquency | 64 #define SIM_CONF1_SCLKDIV 0x0020 // SIM clock frquency |
66 #define SIM_CONF1_SCLKLEV 0x0040 // SIM clock idle level | 65 #define SIM_CONF1_SCLKLEV 0x0040 // SIM clock idle level |
67 #define SIM_CONF1_ETU 0x0080 // ETU period | 66 #define SIM_CONF1_ETU 0x0080 // ETU period |
68 #define SIM_CONF1_BYPASS 0x0100 // bypass hardware timers | 67 #define SIM_CONF1_BYPASS 0x0100 // bypass hardware timers |
69 #define SIM_CONF1_SVCCLEV 0x0200 | 68 #define SIM_CONF1_SVCCLEV 0x0200 |
70 #define SIM_CONF1_SRSTLEV 0x0400 | 69 #define SIM_CONF1_SRSTLEV 0x0400 |
71 #define SIM_CONF1_SIOLOW 0x8000 //force SIO to low level | 70 #define SIM_CONF1_SIOLOW 0x8000 //force SIO to low level |
118 | 117 |
119 #define SIM_SLEEP_NONE 0 // No SIM available | 118 #define SIM_SLEEP_NONE 0 // No SIM available |
120 #define SIM_SLEEP_DESACT 1 // The Driver is NOT currently in sleep mode (clock is off) | 119 #define SIM_SLEEP_DESACT 1 // The Driver is NOT currently in sleep mode (clock is off) |
121 #define SIM_SLEEP_ACT 2 // The Driver is currently in sleep mode (clock is on) | 120 #define SIM_SLEEP_ACT 2 // The Driver is currently in sleep mode (clock is on) |
122 #define SIM_SLEEP_NOT_ALLOWED 3 // The Driver cannot stop the clock : | 121 #define SIM_SLEEP_NOT_ALLOWED 3 // The Driver cannot stop the clock : |
123 // The card don't want or the interface is not able | 122 // The card don't want or the interface is not able |
124 // to do it. | 123 // to do it. |
125 #define SIM_SLEEP_WAITING_TIME 500 //represent 2.3s of period before entering in sleep mode | 124 #define SIM_SLEEP_WAITING_TIME 500 //represent 2.3s of period before entering in sleep mode |
126 | 125 |
127 #define SIM_CLK_STOP_MASK 0x0D // Clock Stop mask defined by ETSI 11.11 | 126 #define SIM_CLK_STOP_MASK 0x0D // Clock Stop mask defined by ETSI 11.11 |
128 #define SIM_CLK_STOP_NOT_ALLWD 0x00 // see ETSI 11.11 : Clock Stop never allowed | 127 #define SIM_CLK_STOP_NOT_ALLWD 0x00 // see ETSI 11.11 : Clock Stop never allowed |
129 #define SIM_CLK_STOP_ALLWD 0x01 // see ETSI 11.11 : No prefered level | 128 #define SIM_CLK_STOP_ALLWD 0x01 // see ETSI 11.11 : No prefered level |
130 #define SIM_CLK_STOP_HIGH 0x04 // see ETSI 11.11 : High level only | 129 #define SIM_CLK_STOP_HIGH 0x04 // see ETSI 11.11 : High level only |
131 #define SIM_CLK_STOP_LOW 0x08 // see ETSI 11.11 : Low level only | 130 #define SIM_CLK_STOP_LOW 0x08 // see ETSI 11.11 : Low level only |
132 | 131 |
133 #if(ANLG_FAM == 1) | 132 #if(ANLG_FAM == 1) |
134 //OMEGA specific definitions | 133 //OMEGA specific definitions |
135 #define MODE5V_OMEGA 0x06 // used in SIM_SwitchVolt | 134 #define MODE5V_OMEGA 0x06 // used in SIM_SwitchVolt |
136 #define MODE_INIT_OMEGA_3V 0x05 // used in SIM_StartVolt | 135 #define MODE_INIT_OMEGA_3V 0x05 // used in SIM_StartVolt |
225 #define SIM_INVALIDATE 0x04 | 224 #define SIM_INVALIDATE 0x04 |
226 #define SIM_REHABILITATE 0x44 | 225 #define SIM_REHABILITATE 0x44 |
227 #define SIM_RUN_GSM_ALGO 0x88 | 226 #define SIM_RUN_GSM_ALGO 0x88 |
228 #define SIM_GET_RESPONSE 0xC0 | 227 #define SIM_GET_RESPONSE 0xC0 |
229 #define SIM_TERMINAL_PROFILE 0x10 | 228 #define SIM_TERMINAL_PROFILE 0x10 |
230 #define SIM_FETCH 0x12 | 229 #define SIM_FETCH 0x12 |
231 #define SIM_TERMINAL_RESPONSE 0x14 | 230 #define SIM_TERMINAL_RESPONSE 0x14 |
232 #define SIM_ENVELOPE 0xC2 | 231 #define SIM_ENVELOPE 0xC2 |
233 | |
234 | 232 |
235 | 233 |
236 // SIM file identifiers | 234 // SIM file identifiers |
237 #define MF 0x3F00 | 235 #define MF 0x3F00 |
238 #define EF_ICCID 0x2FE2 | 236 #define EF_ICCID 0x2FE2 |
277 #define RSIMBUFSIZE 270 | 275 #define RSIMBUFSIZE 270 |
278 #define RSIZESW1SW2 2 | 276 #define RSIZESW1SW2 2 |
279 #define XSIMBUFSIZE 270 | 277 #define XSIMBUFSIZE 270 |
280 | 278 |
281 | 279 |
282 | |
283 | |
284 // Structures | 280 // Structures |
285 typedef struct | 281 typedef struct |
286 { | 282 { |
287 volatile unsigned short cmd; | 283 volatile unsigned short cmd; |
288 volatile unsigned short stat; | 284 volatile unsigned short stat; |
307 | 303 |
308 | 304 |
309 typedef struct | 305 typedef struct |
310 { | 306 { |
311 SIM_CONTROLLER *c; | 307 SIM_CONTROLLER *c; |
312 SYS_UWORD8 *xIn; // xmit input pointer | 308 SYS_UWORD8 *xIn; // xmit input pointer |
313 SYS_UWORD8 *xOut; // xmit output pointer | 309 SYS_UWORD8 *xOut; // xmit output pointer |
314 unsigned errorSIM; // code return in case of error detectd | 310 unsigned errorSIM; // code return in case of error detectd |
315 unsigned short conf1; // image of the configuration register - avoids read/mod/write cycles | 311 unsigned short conf1; // image of the configuration register - avoids read/mod/write cycles |
316 volatile unsigned short txParityErr; | 312 volatile unsigned short txParityErr; |
317 unsigned short rxParityErr; // if 0 no parity error on receipt, 1 if... | 313 unsigned short rxParityErr; // if 0 no parity error on receipt, 1 if... |
318 SYS_UWORD8 Freq_Algo; //use to determine which sim clk freq to choose for running GSM algo | 314 SYS_UWORD8 Freq_Algo; //use to determine which sim clk freq to choose for running GSM algo |
319 SYS_UWORD8 PTS_Try; //use to calculate how many PTS try were already done | 315 SYS_UWORD8 PTS_Try; //use to calculate how many PTS try were already done |
320 SYS_UWORD8 FileC; //value of File Characteristic | 316 SYS_UWORD8 FileC; //value of File Characteristic |
321 SYS_UWORD16 etu9600; | 317 SYS_UWORD16 etu9600; |
322 SYS_UWORD16 etu400; | 318 SYS_UWORD16 etu400; |
323 SYS_UWORD16 startclock; //744 clock cycle translated in ETU | 319 SYS_UWORD16 startclock; //744 clock cycle translated in ETU |
324 SYS_UWORD16 stopclock; //1860 clock cycle translated in ETU | 320 SYS_UWORD16 stopclock; //1860 clock cycle translated in ETU |
325 SYS_UWORD8 moderx; //inform that we are in receive mode | 321 SYS_UWORD8 moderx; //inform that we are in receive mode |
326 // 0 : mode of normal reception without procedure | 322 // 0 : mode of normal reception without procedure |
327 // 1 : mode of wait for acknowledge during reception of char | 323 // 1 : mode of wait for acknowledge during reception of char |
328 // 2 : mode of reception of data by bloc | 324 // 2 : mode of reception of data by bloc |
329 // 3 : mode of reception of data char by char (proc char) | 325 // 3 : mode of reception of data char by char (proc char) |
330 // 4 : mode of reception of data char by char (data) | 326 // 4 : mode of reception of data char by char (data) |
331 // 5 : mode of reception of procedure char SW1/SW2 | 327 // 5 : mode of reception of procedure char SW1/SW2 |
332 // 6 : mode of wait for acknowledge char after transmission of char | 328 // 6 : mode of wait for acknowledge char after transmission of char |
333 SYS_UWORD16 expected_data; //number of expected char in receive mode proc char | 329 SYS_UWORD16 expected_data; //number of expected char in receive mode proc char |
334 SYS_UWORD8 ack; //acknowledge char | 330 SYS_UWORD8 ack; //acknowledge char |
335 SYS_UWORD8 null_received; //indicates if a NULL char was received | 331 SYS_UWORD8 null_received; //indicates if a NULL char was received |
336 SYS_UWORD8 hw_mask; //mask used because of pole112 hw prb | 332 SYS_UWORD8 hw_mask; //mask used because of pole112 hw prb |
337 | 333 |
338 SYS_UWORD8 rbuf[RSIMBUFSIZE]; | 334 SYS_UWORD8 rbuf[RSIMBUFSIZE]; |
339 SYS_UWORD8 rx_index; // receive index on rbuf buffer | 335 SYS_UWORD8 rx_index; // receive index on rbuf buffer |
340 | 336 |
341 SYS_UWORD8 xbuf[XSIMBUFSIZE]; | 337 SYS_UWORD8 xbuf[XSIMBUFSIZE]; |
342 SYS_UWORD8 rSW12[RSIZESW1SW2]; //buffer to store SW1 and SW2 | 338 SYS_UWORD8 rSW12[RSIZESW1SW2]; //buffer to store SW1 and SW2 |
343 SYS_UWORD8 SWcount; //static counter | 339 SYS_UWORD8 SWcount; //static counter |
344 void (*InsertFunc)(SIM_CARD *); | 340 void (*InsertFunc)(SIM_CARD *); |
345 void (*RemoveFunc)(void); | 341 void (*RemoveFunc)(void); |
346 SYS_UWORD16 apdu_ans_length; | 342 SYS_UWORD16 apdu_ans_length; |
347 } | 343 } |
348 SIM_PORT; | 344 SIM_PORT; |
349 | |
350 | 345 |
351 | 346 |
352 void SIM_IntHandler(void); | 347 void SIM_IntHandler(void); |
353 #if ((CHIPSET == 4) || (CHIPSET == 5) || (CHIPSET == 6) || (CHIPSET == 7) || (CHIPSET == 8) || (CHIPSET == 9) || (CHIPSET == 10) || (CHIPSET == 11) || (CHIPSET == 12)) | 348 #if ((CHIPSET == 4) || (CHIPSET == 5) || (CHIPSET == 6) || (CHIPSET == 7) || (CHIPSET == 8) || (CHIPSET == 9) || (CHIPSET == 10) || (CHIPSET == 11) || (CHIPSET == 12)) |
354 void SIM_CD_IntHandler(void); | 349 void SIM_CD_IntHandler(void); |
355 #endif | 350 #endif |
356 | |
357 | |
358 | |
359 | 351 |
360 | 352 |
361 /* | 353 /* |
362 * Prototypes | 354 * Prototypes |
363 */ | 355 */ |
398 SYS_UWORD16 SIM_Fetch(SYS_UWORD8 *result, SYS_UWORD16 len, SYS_UWORD16 *rcvSize); | 390 SYS_UWORD16 SIM_Fetch(SYS_UWORD8 *result, SYS_UWORD16 len, SYS_UWORD16 *rcvSize); |
399 SYS_UWORD16 SIM_TerminalResponse(SYS_UWORD8 *result, SYS_UWORD8 *dat, SYS_UWORD16 len, SYS_UWORD16 *rcvSize); | 391 SYS_UWORD16 SIM_TerminalResponse(SYS_UWORD8 *result, SYS_UWORD8 *dat, SYS_UWORD16 len, SYS_UWORD16 *rcvSize); |
400 SYS_UWORD16 SIM_Envelope(SYS_UWORD8 *result, SYS_UWORD8 *dat, SYS_UWORD16 len, SYS_UWORD16 *rcvSize); | 392 SYS_UWORD16 SIM_Envelope(SYS_UWORD8 *result, SYS_UWORD8 *dat, SYS_UWORD16 len, SYS_UWORD16 *rcvSize); |
401 | 393 |
402 // power off | 394 // power off |
403 void SIM_PowerOff(void); | 395 void SIM_PowerOff(void); |
404 | 396 |
405 // WIM | 397 // WIM |
406 SYS_UWORD16 SIM_XchTPDU(SYS_UWORD8 *dat, SYS_UWORD16 trxLen, SYS_UWORD8 *result, | 398 SYS_UWORD16 SIM_XchTPDU(SYS_UWORD8 *dat, SYS_UWORD16 trxLen, SYS_UWORD8 *result, |
407 SYS_UWORD16 rcvLen, SYS_UWORD16 *rcvSize); | 399 SYS_UWORD16 rcvLen, SYS_UWORD16 *rcvSize); |
408 | 400 |
409 void SIM_lock_cr17689(void); | 401 void SIM_lock_cr17689(void); |
410 | |
411 | 402 |
412 | 403 |
413 /* | 404 /* |
414 * Internal Prototypes | 405 * Internal Prototypes |
415 */ | 406 */ |
419 SYS_UWORD16 SIM_Command_Base(SIM_PORT *p, SYS_UWORD16 n, SYS_UWORD8 *dP, SYS_UWORD16 *lP); | 410 SYS_UWORD16 SIM_Command_Base(SIM_PORT *p, SYS_UWORD16 n, SYS_UWORD8 *dP, SYS_UWORD16 *lP); |
420 SYS_UWORD16 SIM_Dummy(void); | 411 SYS_UWORD16 SIM_Dummy(void); |
421 void SIM_InitLog(void); | 412 void SIM_InitLog(void); |
422 | 413 |
423 SYS_UWORD16 SIM_TxParityErrors(); | 414 SYS_UWORD16 SIM_TxParityErrors(); |
424 SYS_UWORD16 SIM_WaitReception(SIM_PORT *p); | 415 SYS_UWORD16 SIM_WaitReception(SIM_PORT *p); |
425 void SIM_Interpret_FileCharacteristics(SIM_PORT *p); | 416 void SIM_Interpret_FileCharacteristics(SIM_PORT *p); |
426 SYS_UWORD16 SIM_PTSprocedure(SIM_CARD *cP, SIM_PORT *p); | 417 SYS_UWORD16 SIM_PTSprocedure(SIM_CARD *cP, SIM_PORT *p); |
427 void SIM_WARMReset (SIM_PORT *p); | 418 void SIM_WARMReset (SIM_PORT *p); |
428 void SIM_SleepMode_In(SYS_UWORD32 param); | 419 void SIM_SleepMode_In(SYS_UWORD32 param); |
429 void SIM_SleepMode_Out(SIM_PORT *p); | 420 void SIM_SleepMode_Out(SIM_PORT *p); |
430 SYS_UWORD8 SIM_GetFileCharacteristics(SIM_PORT *p); | 421 SYS_UWORD8 SIM_GetFileCharacteristics(SIM_PORT *p); |
431 SYS_UWORD16 SIM_ATRdynamictreatement (SIM_PORT *p, SIM_CARD *cP); | 422 SYS_UWORD16 SIM_ATRdynamictreatement (SIM_PORT *p, SIM_CARD *cP); |
432 SYS_UWORD16 SIM_Waitforchars (SIM_PORT *p, SYS_UWORD16 max_wait); | 423 SYS_UWORD16 SIM_Waitforchars (SIM_PORT *p, SYS_UWORD16 max_wait); |
433 void SIM_Calcetu (SIM_PORT *p); | 424 void SIM_Calcetu (SIM_PORT *p); |
434 SYS_UWORD8 SIM_Translate_atr_char (SYS_UWORD8 input, SIM_CARD *cP); | 425 SYS_UWORD8 SIM_Translate_atr_char (SYS_UWORD8 input, SIM_CARD *cP); |
435 | 426 |
436 | 427 |
437 SYS_UWORD8 SIM_StartVolt (SYS_UWORD8 ResetFlag); | 428 SYS_UWORD8 SIM_StartVolt (SYS_UWORD8 ResetFlag); |
438 SYS_UWORD8 SIM_SwitchVolt (SYS_UWORD8 ResetFlag); | 429 SYS_UWORD8 SIM_SwitchVolt (SYS_UWORD8 ResetFlag); |
439 | 430 |
440 SYS_UWORD16 SIM_ManualStart (SIM_PORT *p); | 431 SYS_UWORD16 SIM_ManualStart (SIM_PORT *p); |
441 SYS_UWORD8 SIM_Memcpy(SYS_UWORD8 *Buff_target, SYS_UWORD8 Buff_source[], SYS_UWORD16 len); | 432 SYS_UWORD8 SIM_Memcpy(SYS_UWORD8 *Buff_target, SYS_UWORD8 Buff_source[], SYS_UWORD16 len); |
442 SYS_BOOL SIM_SleepStatus(void); | 433 SYS_BOOL SIM_SleepStatus(void); |
443 SYS_UWORD16 SIM_Reset_Restart_Internal(SIM_CARD *cP, SYS_UWORD8 ResetFlag); | 434 SYS_UWORD16 SIM_Reset_Restart_Internal(SIM_CARD *cP, SYS_UWORD8 ResetFlag); |
444 | 435 |
445 /* | 436 /* |
446 * Global variables | 437 * Global variables |
447 */ | 438 */ |
448 #ifdef SIM_C | 439 #ifdef SIM_C |
454 | 445 |
455 SI_GLOBAL SIM_PORT Sim[1]; | 446 SI_GLOBAL SIM_PORT Sim[1]; |
456 SI_GLOBAL NU_TIMER SIM_timer; | 447 SI_GLOBAL NU_TIMER SIM_timer; |
457 SI_GLOBAL STATUS status_os_sim; | 448 SI_GLOBAL STATUS status_os_sim; |
458 SI_GLOBAL SYS_UWORD8 SIM_sleep_status; | 449 SI_GLOBAL SYS_UWORD8 SIM_sleep_status; |
459 |