diff --git a/Doc/Doxygen/html/_antenna_level_8h_source.html b/Doc/Doxygen/html/_antenna_level_8h_source.html index 84111987..87967761 100644 --- a/Doc/Doxygen/html/_antenna_level_8h_source.html +++ b/Doc/Doxygen/html/_antenna_level_8h_source.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: AntennaLevel.h Source File @@ -11,9 +12,6 @@ - @@ -31,40 +29,19 @@ - + - - + + + +
AntennaLevel.h
-
1 /*
2  * AntennaLevel.h
3  *
4  * Created on: 24.11.2013
5  * Author: skuser
6  */
7 
8 #ifndef ANTENNALEVEL_H_
9 #define ANTENNALEVEL_H_
10 
11 #include "Common.h"
12 
13 #define ANTENNA_LEVEL_R1 47E3
14 #define ANTENNA_LEVEL_R2 1E3
15 #define ANTENNA_LEVEL_VREF 1.0
16 #define ANTENNA_LEVEL_RES 4096
17 #define ANTENNA_LEVEL_OFFSET 190 /* LSB */
18 
19 #define ANTENNA_LEVEL_MILLIVOLT 1E3
20 #define ANTENNA_LEVEL_FACTOR (ANTENNA_LEVEL_VREF * (ANTENNA_LEVEL_R1 + ANTENNA_LEVEL_R2) / (ANTENNA_LEVEL_RES * ANTENNA_LEVEL_R2) )
21 #define ANTENNA_LEVEL_SCALE ((uint32_t) 1<<16)
22 #define ANTENNA_LEVEL_NUMERATOR ((uint32_t) (ANTENNA_LEVEL_MILLIVOLT * ANTENNA_LEVEL_FACTOR * ANTENNA_LEVEL_SCALE + .5))
23 #define ANTENNA_LEVEL_DENOMINATOR (ANTENNA_LEVEL_SCALE)
24 
25 #define ANTENNA_LEVEL_LOG_RDRDETECT_INTERVAL (15)
26 extern uint8_t AntennaLevelLogReaderDetectCount;
27 
28 #define FIELD_MIN_RSSI 500
29 
30 static inline
31 void AntennaLevelInit(void) {
32  ADCA.CTRLA = ADC_ENABLE_bm;
33  ADCA.CTRLB = ADC_RESOLUTION_12BIT_gc;
34  ADCA.REFCTRL = ADC_REFSEL_INT1V_gc | ADC_BANDGAP_bm;
35  ADCA.PRESCALER = ADC_PRESCALER_DIV32_gc;
36  ADCA.CH0.CTRL = ADC_CH_INPUTMODE_SINGLEENDED_gc;
37  ADCA.CH0.MUXCTRL = ADC_CH_MUXPOS_PIN1_gc;
38 
39 }
40 
41 static inline
42 uint16_t AntennaLevelGet(void) {
43  ADCA.CH0.CTRL |= ADC_CH_START_bm;
44  while (!(ADCA.CH0.INTFLAGS & ADC_CH_CHIF_bm));
45 
46  ADCA.CH0.INTFLAGS = ADC_CH_CHIF_bm;
47 
48  int16_t Result = ADCA.CH0RES - ANTENNA_LEVEL_OFFSET;
49  if (Result < 0) Result = 0;
50 
51  return (uint16_t)(((uint32_t) Result * ANTENNA_LEVEL_NUMERATOR) / ANTENNA_LEVEL_DENOMINATOR);
52 }
53 
54 void AntennaLevelTick(void);
55 void AntennaLevelResetMaxRssi(void);
56 
57 #endif /* ANTENNALEVEL_H_ */
+
1 /*
2  * AntennaLevel.h
3  *
4  * Created on: 24.11.2013
5  * Author: skuser
6  */
7 
8 #ifndef ANTENNALEVEL_H_
9 #define ANTENNALEVEL_H_
10 
11 #include "Common.h"
12 
13 #define ANTENNA_LEVEL_R1 47E3
14 #define ANTENNA_LEVEL_R2 1E3
15 #define ANTENNA_LEVEL_VREF 1.0
16 #define ANTENNA_LEVEL_RES 4096
17 #define ANTENNA_LEVEL_OFFSET 190 /* LSB */
18 
19 #define ANTENNA_LEVEL_MILLIVOLT 1E3
20 #define ANTENNA_LEVEL_FACTOR (ANTENNA_LEVEL_VREF * (ANTENNA_LEVEL_R1 + ANTENNA_LEVEL_R2) / (ANTENNA_LEVEL_RES * ANTENNA_LEVEL_R2) )
21 #define ANTENNA_LEVEL_SCALE ((uint32_t) 1<<16)
22 #define ANTENNA_LEVEL_NUMERATOR ((uint32_t) (ANTENNA_LEVEL_MILLIVOLT * ANTENNA_LEVEL_FACTOR * ANTENNA_LEVEL_SCALE + .5))
23 #define ANTENNA_LEVEL_DENOMINATOR (ANTENNA_LEVEL_SCALE)
24 
25 #define ANTENNA_LEVEL_LOG_RDRDETECT_INTERVAL (15)
26 extern uint8_t AntennaLevelLogReaderDetectCount;
27 
28 #define FIELD_MIN_RSSI 500
29 
30 static inline
31 void AntennaLevelInit(void) {
32  ADCA.CAL = (PRODSIGNATURES_ADCACAL1 << 8) | PRODSIGNATURES_ADCACAL0; /* Load calibration data, source: https://www.avrfreaks.net/comment/2080211#comment-2080211 */
33  ADCA.CTRLA = ADC_ENABLE_bm;
34  ADCA.CTRLB = ADC_RESOLUTION_12BIT_gc;
35  ADCA.REFCTRL = ADC_REFSEL_INT1V_gc | ADC_BANDGAP_bm;
36  ADCA.PRESCALER = ADC_PRESCALER_DIV32_gc;
37  ADCA.CH0.CTRL = ADC_CH_INPUTMODE_SINGLEENDED_gc;
38  ADCA.CH0.MUXCTRL = ADC_CH_MUXPOS_PIN1_gc;
39 
40 }
41 
42 static inline
43 uint16_t AntennaLevelGet(void) {
44  ADCA.CH0.CTRL |= ADC_CH_START_bm;
45  while (!(ADCA.CH0.INTFLAGS & ADC_CH_CHIF_bm));
46 
47  ADCA.CH0.INTFLAGS = ADC_CH_CHIF_bm;
48 
49  int16_t Result = ADCA.CH0RES - ANTENNA_LEVEL_OFFSET;
50  if (Result < 0) Result = 0;
51 
52  return (uint16_t)(((uint32_t) Result * ANTENNA_LEVEL_NUMERATOR) / ANTENNA_LEVEL_DENOMINATOR);
53 }
54 
55 void AntennaLevelTick(void);
56 void AntennaLevelResetMaxRssi(void);
57 
58 #endif /* ANTENNALEVEL_H_ */
diff --git a/Doc/Doxygen/html/_application_8h_source.html b/Doc/Doxygen/html/_application_8h_source.html index 2da03942..85765947 100644 --- a/Doc/Doxygen/html/_application_8h_source.html +++ b/Doc/Doxygen/html/_application_8h_source.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: Application.h Source File @@ -11,9 +12,6 @@ - @@ -31,40 +29,19 @@ - + - - + + + +
Application.h
-
1 /*
2  * Application.h
3  *
4  * Created on: 18.02.2013
5  * Author: skuser
6  */
7 
8 #ifndef APPLICATION_H_
9 #define APPLICATION_H_
10 
11 #include "../Common.h"
12 #include "../Configuration.h"
13 #include "../Log.h"
14 
15 /* Applications */
16 #include "MifareUltralight.h"
17 #include "MifareClassic.h"
18 #include "Reader14443A.h"
19 #include "Vicinity.h"
20 #include "Sl2s2002.h"
21 #include "TITagitstandard.h"
22 #include "Sniff14443A.h"
23 #include "NTAG215.h"
24 #include "EM4233.h"
25 
26 /* Function wrappers */
27 INLINE void ApplicationInit(void) {
28  ActiveConfiguration.ApplicationInitFunc();
29 }
30 
31 INLINE void ApplicationTask(void) {
32  ActiveConfiguration.ApplicationTaskFunc();
33 }
34 
35 INLINE void ApplicationTick(void) {
36  ActiveConfiguration.ApplicationTickFunc();
37 }
38 
39 INLINE uint16_t ApplicationProcess(uint8_t *ByteBuffer, uint16_t ByteCount) {
40  return ActiveConfiguration.ApplicationProcessFunc(ByteBuffer, ByteCount);
41 }
42 
43 INLINE void ApplicationReset(void) {
44  ActiveConfiguration.ApplicationResetFunc();
45  //LogEntry(LOG_INFO_RESET_APP, NULL, 0);
46 }
47 
48 INLINE void ApplicationGetUid(ConfigurationUidType Uid) {
49  ActiveConfiguration.ApplicationGetUidFunc(Uid);
50 }
51 
52 INLINE void ApplicationSetUid(ConfigurationUidType Uid) {
53  ActiveConfiguration.ApplicationSetUidFunc(Uid);
54  LogEntry(LOG_INFO_UID_SET, Uid, ActiveConfiguration.UidSize);
55 }
56 
57 #endif /* APPLICATION_H_ */
void(* ApplicationSetUidFunc)(ConfigurationUidType Uid)
Definition: Configuration.h:139
-
uint16_t(* ApplicationProcessFunc)(uint8_t *ByteBuffer, uint16_t BitCount)
Definition: Configuration.h:129
-
void(* ApplicationResetFunc)(void)
Definition: Configuration.h:113
+
1 /*
2  * Application.h
3  *
4  * Created on: 18.02.2013
5  * Author: skuser
6  */
7 
8 #ifndef APPLICATION_H_
9 #define APPLICATION_H_
10 
11 #include "../Common.h"
12 #include "../Configuration.h"
13 #include "../Log.h"
14 
15 /* Applications */
16 #include "MifareUltralight.h"
17 #include "MifareClassic.h"
18 #include "Reader14443A.h"
19 #include "Vicinity.h"
20 #include "Sl2s2002.h"
21 #include "TITagitstandard.h"
22 #include "TITagitplus.h"
23 #include "Sniff14443A.h"
24 #include "NTAG215.h"
25 #include "EM4233.h"
26 #include "Sniff15693.h"
27 
28 /* Function wrappers */
29 INLINE void ApplicationInit(void) {
30  ActiveConfiguration.ApplicationInitFunc();
31 }
32 
33 INLINE void ApplicationTask(void) {
34  ActiveConfiguration.ApplicationTaskFunc();
35 }
36 
37 INLINE void ApplicationTick(void) {
38  ActiveConfiguration.ApplicationTickFunc();
39 }
40 
41 INLINE uint16_t ApplicationProcess(uint8_t *ByteBuffer, uint16_t ByteCount) {
42  return ActiveConfiguration.ApplicationProcessFunc(ByteBuffer, ByteCount);
43 }
44 
45 INLINE void ApplicationReset(void) {
46  ActiveConfiguration.ApplicationResetFunc();
47  //LogEntry(LOG_INFO_RESET_APP, NULL, 0);
48 }
49 
50 INLINE void ApplicationGetUid(ConfigurationUidType Uid) {
51  ActiveConfiguration.ApplicationGetUidFunc(Uid);
52 }
53 
54 INLINE void ApplicationSetUid(ConfigurationUidType Uid) {
55  ActiveConfiguration.ApplicationSetUidFunc(Uid);
56  LogEntry(LOG_INFO_UID_SET, Uid, ActiveConfiguration.UidSize);
57 }
58 
59 #endif /* APPLICATION_H_ */
void(* ApplicationSetUidFunc)(ConfigurationUidType Uid)
Definition: Configuration.h:142
+
uint16_t(* ApplicationProcessFunc)(uint8_t *ByteBuffer, uint16_t BitCount)
Definition: Configuration.h:132
+
void(* ApplicationResetFunc)(void)
Definition: Configuration.h:116
UID change.
Definition: Log.h:21
-
void(* ApplicationGetUidFunc)(ConfigurationUidType Uid)
Definition: Configuration.h:134
-
void(* ApplicationTickFunc)(void)
Definition: Configuration.h:117
-
void(* ApplicationTaskFunc)(void)
Definition: Configuration.h:115
-
void(* ApplicationInitFunc)(void)
Definition: Configuration.h:111
-
uint8_t UidSize
Definition: Configuration.h:156
+
void(* ApplicationGetUidFunc)(ConfigurationUidType Uid)
Definition: Configuration.h:137
+
void(* ApplicationTickFunc)(void)
Definition: Configuration.h:120
+
void(* ApplicationTaskFunc)(void)
Definition: Configuration.h:118
+
void(* ApplicationInitFunc)(void)
Definition: Configuration.h:114
+
uint8_t UidSize
Definition: Configuration.h:159
diff --git a/Doc/Doxygen/html/_battery_8h_source.html b/Doc/Doxygen/html/_battery_8h_source.html index c106e056..a199d43b 100644 --- a/Doc/Doxygen/html/_battery_8h_source.html +++ b/Doc/Doxygen/html/_battery_8h_source.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: Battery.h Source File @@ -11,9 +12,6 @@ - @@ -31,40 +29,19 @@
- + - - + + + +
1 /*
2  * Battery.h
3  *
4  * Created on: 20.08.2014
5  * Author: sk
6  */
7 
8 #ifndef BATTERY_H_
9 #define BATTERY_H_
10 
11 #include "Common.h"
12 
13 #define BATTERY_PORT PORTD
14 #define BATTERY_STAT_PIN PIN0_bm
15 #define BATTERY_STAT_PINCTRL PIN0CTRL
16 #define BATTERY_PORT_MASK (BATTERY_STAT_PIN)
17 
18 INLINE void BatteryInit(void) {
19  BATTERY_PORT.DIRCLR = BATTERY_PORT_MASK;
20  BATTERY_PORT.BATTERY_STAT_PINCTRL = PORT_OPC_PULLUP_gc;
21 }
22 
23 INLINE bool BatteryIsCharging(void) {
24  if (!(BATTERY_PORT.IN & BATTERY_STAT_PIN)) {
25  return true;
26  } else {
27  return false;
28  }
29 }
30 
31 #endif /* BATTERY_H_ */
diff --git a/Doc/Doxygen/html/_button_8h_source.html b/Doc/Doxygen/html/_button_8h_source.html index b8982b3d..d6649ef0 100644 --- a/Doc/Doxygen/html/_button_8h_source.html +++ b/Doc/Doxygen/html/_button_8h_source.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: Button.h Source File @@ -11,9 +12,6 @@ - @@ -31,40 +29,19 @@ - + - - + + + +
1 /*
2  * Button.h
3  *
4  * Created on: 13.05.2013
5  * Author: skuser
6  */
7 
8 #ifndef BUTTON_H_
9 #define BUTTON_H_
10 
11 #include "Common.h"
12 
13 typedef enum {
14  BUTTON_R_PRESS_SHORT = 0,
15  BUTTON_R_PRESS_LONG,
16  BUTTON_L_PRESS_SHORT,
17  BUTTON_L_PRESS_LONG,
18 
19  /* Must be last element */
20  BUTTON_TYPE_COUNT
21 } ButtonTypeEnum;
22 
23 typedef enum {
24  BUTTON_ACTION_NONE,
25  BUTTON_ACTION_UID_RANDOM,
26  BUTTON_ACTION_UID_LEFT_INCREMENT,
27  BUTTON_ACTION_UID_RIGHT_INCREMENT,
28  BUTTON_ACTION_UID_LEFT_DECREMENT,
29  BUTTON_ACTION_UID_RIGHT_DECREMENT,
30  BUTTON_ACTION_CYCLE_SETTINGS,
31  BUTTON_ACTION_STORE_MEM,
32  BUTTON_ACTION_RECALL_MEM,
33  BUTTON_ACTION_TOGGLE_FIELD,
34  BUTTON_ACTION_STORE_LOG,
35  BUTTON_ACTION_CLONE,
36  BUTTON_ACTION_CLONE_MFU,
37 
38  /* This has to be last element */
39  BUTTON_ACTION_COUNT
40 } ButtonActionEnum;
41 
42 void ButtonInit(void);
43 void ButtonTick(void);
44 
45 void ButtonGetActionList(char *List, uint16_t BufferSize);
46 void ButtonSetActionById(ButtonTypeEnum Type, ButtonActionEnum Action);
47 void ButtonGetActionByName(ButtonTypeEnum Type, char *Action, uint16_t BufferSize);
48 bool ButtonSetActionByName(ButtonTypeEnum Type, const char *Action);
49 
50 #endif /* BUTTON_H_ */
diff --git a/Doc/Doxygen/html/_buttons_8txt.html b/Doc/Doxygen/html/_buttons_8txt.html index 4d00880b..6f444fa2 100644 --- a/Doc/Doxygen/html/_buttons_8txt.html +++ b/Doc/Doxygen/html/_buttons_8txt.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: Buttons.txt File Reference @@ -11,9 +12,6 @@ - @@ -31,40 +29,19 @@ - + - - + + + +
diff --git a/Doc/Doxygen/html/_chameleon-_mini_8h_source.html b/Doc/Doxygen/html/_chameleon-_mini_8h_source.html index 2876457a..d646513a 100644 --- a/Doc/Doxygen/html/_chameleon-_mini_8h_source.html +++ b/Doc/Doxygen/html/_chameleon-_mini_8h_source.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: Chameleon-Mini.h Source File @@ -11,9 +12,6 @@ - @@ -31,40 +29,19 @@
- + - - + + + +
diff --git a/Doc/Doxygen/html/_chameleon_terminal_8h_source.html b/Doc/Doxygen/html/_chameleon_terminal_8h_source.html index 38df57ef..f085b493 100644 --- a/Doc/Doxygen/html/_chameleon_terminal_8h_source.html +++ b/Doc/Doxygen/html/_chameleon_terminal_8h_source.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: ChameleonTerminal.h Source File @@ -11,9 +12,6 @@ - @@ -31,40 +29,19 @@ - + - - + + + +
ChameleonTerminal.h
-
1 /* ChameleonTerminal.h */
2 
3 #ifndef __TESTS_CHAMELEON_TERMINAL_H__
4 #define __TESTS_CHAMELEON_TERMINAL_H__
5 
6 #include "../Terminal/Commands.h"
7 #include "../Terminal/CommandLine.h"
8 #include "../Terminal/Terminal.h"
9 
10 typedef bool (*ChameleonTestType)(char*, uint16_t);
11 
12 #define COMMAND_RUNTESTS "RUNTESTS"
13 CommandStatusIdType CommandRunTests(char *OutParam);
14 
15 #endif
+
1 /* ChameleonTerminal.h */
2 
3 #ifndef __TESTS_CHAMELEON_TERMINAL_H__
4 #define __TESTS_CHAMELEON_TERMINAL_H__
5 
6 #include "../Terminal/Commands.h"
7 #include "../Terminal/CommandLine.h"
8 #include "../Terminal/Terminal.h"
9 
10 typedef bool (*ChameleonTestType)(char *, uint16_t);
11 
12 #define COMMAND_RUNTESTS "RUNTESTS"
13 CommandStatusIdType CommandRunTests(char *OutParam);
14 
15 #endif
diff --git a/Doc/Doxygen/html/_codec_8h_source.html b/Doc/Doxygen/html/_codec_8h_source.html index e1fda906..546d908e 100644 --- a/Doc/Doxygen/html/_codec_8h_source.html +++ b/Doc/Doxygen/html/_codec_8h_source.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: Codec.h Source File @@ -11,9 +12,6 @@ - @@ -31,40 +29,19 @@ - + - - + + + +
Codec.h
-
1 /*
2  * CODEC.h
3  *
4  * Created on: 18.02.2013
5  * Author: skuser
6  */
7 
8 #ifndef CODEC_H_
9 #define CODEC_H_
10 
11 /* Peripheral definitions */
12 #define CODEC_DEMOD_POWER_PORT PORTB
13 #define CODEC_DEMOD_POWER_MASK PIN0_bm
14 #define CODEC_DEMOD_IN_PORT PORTB
15 #define CODEC_DEMOD_IN_MASK (CODEC_DEMOD_IN_MASK0 | CODEC_DEMOD_IN_MASK1)
16 #define CODEC_DEMOD_IN_MASK0 PIN1_bm
17 #define CODEC_DEMOD_IN_MASK1 PIN2_bm
18 #define CODEC_DEMOD_IN_PINCTRL0 PIN1CTRL
19 #define CODEC_DEMOD_IN_PINCTRL1 PIN2CTRL
20 #define CODEC_DEMOD_IN_EVMUX0 EVSYS_CHMUX_PORTB_PIN1_gc
21 #define CODEC_DEMOD_IN_EVMUX1 EVSYS_CHMUX_PORTB_PIN2_gc
22 #define CODEC_DEMOD_IN_INT0_VECT PORTB_INT0_vect
23 #define CODEC_DEMOD_IN_INT1_VECT PORTB_INT1_vect
24 #define CODEC_LOADMOD_PORT PORTC
25 #define CODEC_LOADMOD_MASK PIN6_bm
26 #define CODEC_CARRIER_IN_PORT PORTC
27 #define CODEC_CARRIER_IN_MASK PIN2_bm
28 #define CODEC_CARRIER_IN_PINCTRL PIN2CTRL
29 #define CODEC_CARRIER_IN_EVMUX EVSYS_CHMUX_PORTC_PIN2_gc
30 #define CODEC_CARRIER_IN_DIV 2 /* external clock division factor */
31 #define CODEC_SUBCARRIER_PORT PORTC
32 #define CODEC_SUBCARRIER_MASK_PSK PIN4_bm
33 #define CODEC_SUBCARRIER_MASK_OOK PIN5_bm
34 #define CODEC_SUBCARRIER_MASK (CODEC_SUBCARRIER_MASK_PSK | CODEC_SUBCARRIER_MASK_OOK)
35 #define CODEC_SUBCARRIER_TIMER TCC1
36 #define CODEC_SUBCARRIER_CC_PSK CCA
37 #define CODEC_SUBCARRIER_CC_OOK CCB
38 #define CODEC_SUBCARRIER_CCEN_PSK TC1_CCAEN_bm
39 #define CODEC_SUBCARRIER_CCEN_OOK TC1_CCBEN_bm
40 #define CODEC_TIMER_SAMPLING TCD0
41 #define CODEC_TIMER_SAMPLING_CCA_VECT TCD0_CCA_vect
42 #define CODEC_TIMER_SAMPLING_CCB_VECT TCD0_CCB_vect
43 #define CODEC_TIMER_SAMPLING_CCC_VECT TCD0_CCC_vect
44 #define CODEC_TIMER_SAMPLING_CCD_VECT TCD0_CCD_vect
45 #define CODEC_TIMER_LOADMOD TCE0
46 #define CODEC_TIMER_LOADMOD_OVF_VECT TCE0_OVF_vect
47 #define CODEC_TIMER_LOADMOD_CCA_VECT TCE0_CCA_vect
48 #define CODEC_TIMER_LOADMOD_CCB_VECT TCE0_CCB_vect
49 #define CODEC_TIMER_LOADMOD_CCC_VECT TCE0_CCC_vect
50 #define CODEC_TIMER_MODSTART_EVSEL TC_EVSEL_CH0_gc
51 #define CODEC_TIMER_MODEND_EVSEL TC_EVSEL_CH1_gc
52 #define CODEC_TIMER_CARRIER_CLKSEL TC_CLKSEL_EVCH6_gc
53 #define CODEC_READER_TIMER TCC0
54 #define CODEC_READER_PORT PORTC
55 #define CODEC_READER_MASK_LEFT PIN0_bm
56 #define CODEC_READER_MASK_RIGHT PIN1_bm
57 #define CODEC_READER_MASK (CODEC_READER_MASK_LEFT | CODEC_READER_MASK_RIGHT)
58 #define CODEC_READER_PINCTRL_LEFT PIN0CTRL
59 #define CODEC_READER_PINCTRL_RIGHT PIN1CTRL
60 #define CODEC_AC_DEMOD_SETTINGS AC_HSMODE_bm | AC_HYSMODE_NO_gc
61 #define CODEC_MAXIMUM_THRESHOLD 0xFFF // the maximum voltage can be calculated with ch0data * Vref / 0xFFF
62 #define CODEC_THRESHOLD_CALIBRATE_MIN 128
63 #define CODEC_THRESHOLD_CALIBRATE_MID 768
64 #define CODEC_THRESHOLD_CALIBRATE_MAX 2048
65 #define CODEC_THRESHOLD_CALIBRATE_STEPS 16
66 #define CODEC_TIMER_TIMESTAMPS TCD1
67 #define CODEC_TIMER_TIMESTAMPS_CCA_VECT TCD1_CCA_vect
68 #define CODEC_TIMER_TIMESTAMPS_CCB_VECT TCD1_CCB_vect
69 
70 #ifndef __ASSEMBLER__
71 
72 #include <avr/io.h>
73 #include <stdint.h>
74 #include <stdbool.h>
75 #include "../Common.h"
76 #include "../Configuration.h"
77 #include "../Settings.h"
78 
79 #include "ISO14443-2A.h"
80 #include "Reader14443-2A.h"
81 #include "SniffISO14443-2A.h"
82 #include "ISO15693.h"
83 
84 /* Timing definitions for ISO14443A */
85 #define ISO14443A_SUBCARRIER_DIVIDER 16
86 #define ISO14443A_BIT_GRID_CYCLES 128
87 #define ISO14443A_BIT_RATE_CYCLES 128
88 #define ISO14443A_FRAME_DELAY_PREV1 1236
89 #define ISO14443A_FRAME_DELAY_PREV0 1172
90 #define ISO14443A_RX_PENDING_TIMEOUT 4 // ms
91 
92 #define CODEC_BUFFER_SIZE 256
93 
94 #define CODEC_CARRIER_FREQ 13560000
95 
96 #define Codec8Reg0 GPIOR0
97 #define Codec8Reg1 GPIOR1
98 #define Codec8Reg2 GPIOR2
99 #define Codec8Reg3 GPIOR3
100 #define CodecCount16Register1 (*((volatile uint16_t*) &GPIOR4)) /* GPIOR4 & GPIOR5 */
101 #define CodecCount16Register2 (*((volatile uint16_t*) &GPIOR6)) /* GPIOR6 & GPIOR7 */
102 #define CodecPtrRegister1 (*((volatile uint8_t**) &GPIOR8))
103 #define CodecPtrRegister2 (*((volatile uint8_t**) &GPIORA))
104 #define CodecPtrRegister3 (*((volatile uint8_t**) &GPIORC))
105 
106 
107 extern uint16_t Reader_FWT;
108 
109 #define FWI2FWT(x) ((uint32_t)(256 * 16 * ((uint32_t)1 << (x))) / (CODEC_CARRIER_FREQ / 1000) + 1)
110 
111 typedef enum {
112  CODEC_SUBCARRIERMOD_OFF,
113  CODEC_SUBCARRIERMOD_OOK
114 } SubcarrierModType;
115 
116 extern uint8_t CodecBuffer[CODEC_BUFFER_SIZE];
117 extern uint8_t CodecBuffer2[CODEC_BUFFER_SIZE];
118 
119 /* Shared ISR pointers and handlers */
120 extern void (* volatile isr_func_TCD0_CCC_vect)(void);
121 void isr_Reader14443_2A_TCD0_CCC_vect(void);
122 void isr_ISO15693_CODEC_TIMER_SAMPLING_CCC_VECT(void);
123 extern void (* volatile isr_func_CODEC_DEMOD_IN_INT0_VECT)(void);
124 void isr_ISO14443_2A_TCD0_CCC_vect(void);
125 void isr_ISO15693_CODEC_DEMOD_IN_INT0_VECT(void);
126 extern void (* volatile isr_func_CODEC_TIMER_LOADMOD_CCB_VECT)(void);
127 void isr_ISO15693_CODEC_TIMER_LOADMOD_CCB_VECT(void);
128 void isr_SniffISO14443_2A_CODEC_TIMER_LOADMOD_CCB_VECT(void);
129 
130 INLINE void CodecInit(void) {
131  ActiveConfiguration.CodecInitFunc();
132 }
133 
134 INLINE void CodecDeInit(void) {
135  ActiveConfiguration.CodecDeInitFunc();
136 }
137 
138 INLINE void CodecTask(void) {
139  ActiveConfiguration.CodecTaskFunc();
140 }
141 
142 /* Helper Functions for Codec implementations */
143 INLINE void CodecInitCommon(void) {
144  /* Configure CARRIER input pin and route it to EVSYS.
145  * Multiply by 2 again by using both edges when externally
146  * dividing by 2 */
147 #if CODEC_CARRIER_IN_DIV == 2
148  CODEC_CARRIER_IN_PORT.CODEC_CARRIER_IN_PINCTRL = PORT_ISC_BOTHEDGES_gc;
149 #else
150 #error Option not supported
151 #endif
152  CODEC_CARRIER_IN_PORT.DIRCLR = CODEC_CARRIER_IN_MASK;
153  EVSYS.CH6MUX = CODEC_CARRIER_IN_EVMUX;
154 
155  /* Configure two DEMOD pins for input.
156  * Configure event channel 0 for rising edge (begin of modulation pause)
157  * Configure event channel 1 for falling edge (end of modulation pause) */
158  CODEC_DEMOD_POWER_PORT.OUTCLR = CODEC_DEMOD_POWER_MASK;
159  CODEC_DEMOD_POWER_PORT.DIRSET = CODEC_DEMOD_POWER_MASK;
160  CODEC_DEMOD_IN_PORT.DIRCLR = CODEC_DEMOD_IN_MASK;
161  CODEC_DEMOD_IN_PORT.CODEC_DEMOD_IN_PINCTRL0 = PORT_ISC_RISING_gc;
162  CODEC_DEMOD_IN_PORT.CODEC_DEMOD_IN_PINCTRL1 = PORT_ISC_FALLING_gc;
163  CODEC_DEMOD_IN_PORT.INT0MASK = 0;
164  CODEC_DEMOD_IN_PORT.INT1MASK = 0;
165  CODEC_DEMOD_IN_PORT.INTCTRL = PORT_INT0LVL_HI_gc | PORT_INT1LVL_HI_gc;
166  EVSYS.CH0MUX = CODEC_DEMOD_IN_EVMUX0;
167  EVSYS.CH1MUX = CODEC_DEMOD_IN_EVMUX1;
168 
169  EVSYS.CH2MUX = CODEC_DEMOD_IN_EVMUX0;
170 
171 
172  /* Configure loadmod pin configuration and use a virtual port configuration
173  * for single instruction cycle access */
174  CODEC_LOADMOD_PORT.DIRSET = CODEC_LOADMOD_MASK;
175  CODEC_LOADMOD_PORT.OUTCLR = CODEC_LOADMOD_MASK;
176  PORTCFG.VPCTRLA &= ~PORTCFG_VP0MAP_gm;
177  PORTCFG.VPCTRLA |= PORTCFG_VP02MAP_PORTC_gc;
178 
179  /* Configure subcarrier pins for output */
180  CODEC_SUBCARRIER_PORT.DIRSET = CODEC_SUBCARRIER_MASK;
181  CODEC_SUBCARRIER_PORT.OUTCLR = CODEC_SUBCARRIER_MASK;
182 
183  /* Configure pins for reader field with the LEFT output being inverted
184  * and all bridge outputs static high */
185  CODEC_READER_PORT.CODEC_READER_PINCTRL_LEFT = PORT_INVEN_bm;
186  CODEC_READER_PORT.OUTCLR = CODEC_READER_MASK_LEFT;
187  CODEC_READER_PORT.OUTSET = CODEC_READER_MASK_RIGHT;
188  CODEC_READER_PORT.DIRSET = CODEC_READER_MASK;
189 
190  /* Configure timer for generating reader field and configure AWEX for outputting pattern
191  * with disabled outputs. */
192  CODEC_READER_TIMER.CTRLB = TC0_CCAEN_bm | TC_WGMODE_SINGLESLOPE_gc;
193  CODEC_READER_TIMER.PER = F_CPU / CODEC_CARRIER_FREQ - 1;
194  CODEC_READER_TIMER.CCA = F_CPU / CODEC_CARRIER_FREQ / 2 ;
195 
196  AWEXC.OUTOVEN = 0x00;
197  AWEXC.CTRL = AWEX_CWCM_bm | AWEX_DTICCAEN_bm | AWEX_DTICCBEN_bm;
198 
199  /* Configure DAC for the reference voltage */
200  DACB.EVCTRL = 0;
201  DACB.CTRLB = DAC_CHSEL_SINGLE_gc;
202  DACB.CTRLC = DAC_REFSEL_AVCC_gc;
203  DACB.CTRLA = DAC_IDOEN_bm | DAC_ENABLE_bm;
204  DACB.CH0DATA = GlobalSettings.ActiveSettingPtr->ReaderThreshold; // real threshold voltage can be calculated with ch0data * Vref / 0xFFF
205 
206  /* Configure Analog Comparator 0 to detect changes in demodulated reader field */
207  ACA.AC0MUXCTRL = AC_MUXPOS_DAC_gc | AC_MUXNEG_PIN7_gc;
208  ACA.AC0CTRL = CODEC_AC_DEMOD_SETTINGS;
209 
210  /* Configure Analog Comparator 1 to detect SOC */
211  ACA.AC1MUXCTRL = AC_MUXPOS_DAC_gc | AC_MUXNEG_PIN7_gc;
212  ACA.AC1CTRL = CODEC_AC_DEMOD_SETTINGS;
213 }
214 
215 INLINE void CodecSetSubcarrier(SubcarrierModType ModType, uint16_t Divider) {
216  if (ModType == CODEC_SUBCARRIERMOD_OFF) {
217  CODEC_SUBCARRIER_TIMER.CTRLA = TC_CLKSEL_OFF_gc;
218  CODEC_SUBCARRIER_TIMER.CTRLB = 0;
219  } else if (ModType == CODEC_SUBCARRIERMOD_OOK) {
220  /* Configure subcarrier generation with 50% DC output using OOK */
221  CODEC_SUBCARRIER_TIMER.CNT = 0;
222  CODEC_SUBCARRIER_TIMER.PER = Divider - 1;
223  CODEC_SUBCARRIER_TIMER.CODEC_SUBCARRIER_CC_OOK = Divider / 2;
224  CODEC_SUBCARRIER_TIMER.CTRLB = CODEC_SUBCARRIER_CCEN_OOK | TC_WGMODE_SINGLESLOPE_gc;
225  }
226 }
227 
228 INLINE void CodecChangeDivider(uint16_t Divider) {
229  CODEC_SUBCARRIER_TIMER.PER = Divider - 1;
230 }
231 
232 INLINE void CodecStartSubcarrier(void) {
233  CODEC_SUBCARRIER_TIMER.CTRLA = CODEC_TIMER_CARRIER_CLKSEL;
234 }
235 
236 INLINE void CodecSetDemodPower(bool bOnOff) {
237  if (bOnOff) {
238  CODEC_DEMOD_POWER_PORT.OUTSET = CODEC_DEMOD_POWER_MASK;
239  } else {
240  CODEC_DEMOD_POWER_PORT.OUTCLR = CODEC_DEMOD_POWER_MASK;
241  }
242 }
243 
244 INLINE bool CodecGetLoadmodState(void) {
245  if (ACA.STATUS & AC_AC0STATE_bm) {
246  return true;
247  } else {
248  return false;
249  }
250 }
251 
252 INLINE void CodecSetLoadmodState(bool bOnOff) {
253  if (bOnOff) {
254  VPORT0.OUT |= CODEC_LOADMOD_MASK;
255  } else {
256  VPORT0.OUT &= ~CODEC_LOADMOD_MASK;
257  }
258 }
259 
260 // Turn on and off the codec Reader field
261 INLINE void CodecSetReaderField(bool bOnOff) { // this is the function for turning on/off the reader field dumbly; before using this function, please consider to use CodecReaderField{Start,Stop}
262 
263  if (bOnOff) {
264  /* Start timer for field generation and unmask outputs */
265  CODEC_READER_TIMER.CTRLA = TC_CLKSEL_DIV1_gc;
266  AWEXC.OUTOVEN = CODEC_READER_MASK;
267  } else {
268  /* Disable outputs of AWEX and stop field generation */
269  AWEXC.OUTOVEN = 0x00;
270  CODEC_READER_TIMER.CTRLA = TC_CLKSEL_OFF_gc;
271  }
272 }
273 
274 // Get the status of the reader field
275 INLINE bool CodecGetReaderField(void) {
276  return (CODEC_READER_TIMER.CTRLA == TC_CLKSEL_DIV1_gc) && (AWEXC.OUTOVEN == CODEC_READER_MASK);
277 }
278 
279 void CodecReaderFieldStart(void);
280 void CodecReaderFieldStop(void);
281 bool CodecIsReaderFieldReady(void);
282 
283 void CodecReaderFieldRestart(uint16_t delay);
284 #define FIELD_RESTART() CodecReaderFieldRestart(100)
285 bool CodecIsReaderToBeRestarted(void);
286 
287 void CodecThresholdSet(uint16_t th);
288 uint16_t CodecThresholdIncrement(void);
289 void CodecThresholdReset(void);
290 
291 #endif /* __ASSEMBLER__ */
292 
293 #endif /* CODEC_H_ */
void(* CodecInitFunc)(void)
Definition: Configuration.h:93
-
void(* CodecTaskFunc)(void)
Definition: Configuration.h:99
-
void(* CodecDeInitFunc)(void)
Definition: Configuration.h:95
+
1 /*
2  * CODEC.h
3  *
4  * Created on: 18.02.2013
5  * Author: skuser
6  */
7 
8 #ifndef CODEC_H_
9 #define CODEC_H_
10 
11 /* Peripheral definitions */
12 #define CODEC_DEMOD_POWER_PORT PORTB
13 #define CODEC_DEMOD_POWER_MASK PIN0_bm
14 #define CODEC_DEMOD_IN_PORT PORTB
15 #define CODEC_DEMOD_IN_MASK (CODEC_DEMOD_IN_MASK0 | CODEC_DEMOD_IN_MASK1)
16 #define CODEC_DEMOD_IN_MASK0 PIN1_bm
17 #define CODEC_DEMOD_IN_MASK1 PIN2_bm
18 #define CODEC_DEMOD_IN_PINCTRL0 PIN1CTRL
19 #define CODEC_DEMOD_IN_PINCTRL1 PIN2CTRL
20 #define CODEC_DEMOD_IN_EVMUX0 EVSYS_CHMUX_PORTB_PIN1_gc
21 #define CODEC_DEMOD_IN_EVMUX1 EVSYS_CHMUX_PORTB_PIN2_gc
22 #define CODEC_DEMOD_IN_INT0_VECT PORTB_INT0_vect
23 #define CODEC_DEMOD_IN_INT1_VECT PORTB_INT1_vect
24 #define CODEC_LOADMOD_PORT PORTC
25 #define CODEC_LOADMOD_MASK PIN6_bm
26 #define CODEC_CARRIER_IN_PORT PORTC
27 #define CODEC_CARRIER_IN_MASK PIN2_bm
28 #define CODEC_CARRIER_IN_PINCTRL PIN2CTRL
29 #define CODEC_CARRIER_IN_EVMUX EVSYS_CHMUX_PORTC_PIN2_gc
30 #define CODEC_CARRIER_IN_DIV 2 /* external clock division factor */
31 #define CODEC_SUBCARRIER_PORT PORTC
32 #define CODEC_SUBCARRIER_MASK_PSK PIN4_bm
33 #define CODEC_SUBCARRIER_MASK_OOK PIN5_bm
34 #define CODEC_SUBCARRIER_MASK (CODEC_SUBCARRIER_MASK_PSK | CODEC_SUBCARRIER_MASK_OOK)
35 #define CODEC_SUBCARRIER_TIMER TCC1
36 #define CODEC_SUBCARRIER_CC_PSK CCA
37 #define CODEC_SUBCARRIER_CC_OOK CCB
38 #define CODEC_SUBCARRIER_CCEN_PSK TC1_CCAEN_bm
39 #define CODEC_SUBCARRIER_CCEN_OOK TC1_CCBEN_bm
40 #define CODEC_TIMER_SAMPLING TCD0
41 #define CODEC_TIMER_SAMPLING_OVF_VECT TCD0_OVF_vect
42 #define CODEC_TIMER_SAMPLING_CCA_VECT TCD0_CCA_vect
43 #define CODEC_TIMER_SAMPLING_CCB_VECT TCD0_CCB_vect
44 #define CODEC_TIMER_SAMPLING_CCC_VECT TCD0_CCC_vect
45 #define CODEC_TIMER_SAMPLING_CCD_VECT TCD0_CCD_vect
46 #define CODEC_TIMER_LOADMOD TCE0
47 #define CODEC_TIMER_LOADMOD_OVF_VECT TCE0_OVF_vect
48 #define CODEC_TIMER_LOADMOD_CCA_VECT TCE0_CCA_vect
49 #define CODEC_TIMER_LOADMOD_CCB_VECT TCE0_CCB_vect
50 #define CODEC_TIMER_LOADMOD_CCC_VECT TCE0_CCC_vect
51 #define CODEC_TIMER_MODSTART_EVSEL TC_EVSEL_CH0_gc
52 #define CODEC_TIMER_MODEND_EVSEL TC_EVSEL_CH1_gc
53 #define CODEC_TIMER_CARRIER_CLKSEL TC_CLKSEL_EVCH6_gc
54 #define CODEC_READER_TIMER TCC0
55 #define CODEC_READER_PORT PORTC
56 #define CODEC_READER_MASK_LEFT PIN0_bm
57 #define CODEC_READER_MASK_RIGHT PIN1_bm
58 #define CODEC_READER_MASK (CODEC_READER_MASK_LEFT | CODEC_READER_MASK_RIGHT)
59 #define CODEC_READER_PINCTRL_LEFT PIN0CTRL
60 #define CODEC_READER_PINCTRL_RIGHT PIN1CTRL
61 #define CODEC_AC_DEMOD_SETTINGS AC_HSMODE_bm | AC_HYSMODE_NO_gc
62 #define CODEC_MAXIMUM_THRESHOLD 0xFFF // the maximum voltage can be calculated with ch0data * Vref / 0xFFF
63 #define CODEC_THRESHOLD_CALIBRATE_MIN 128
64 #define CODEC_THRESHOLD_CALIBRATE_MID 768
65 #define CODEC_THRESHOLD_CALIBRATE_MAX 2048
66 #define CODEC_THRESHOLD_CALIBRATE_STEPS 16
67 #define CODEC_TIMER_TIMESTAMPS TCD1
68 #define CODEC_TIMER_TIMESTAMPS_OVF_VECT TCD1_OVF_vect
69 #define CODEC_TIMER_TIMESTAMPS_CCA_VECT TCD1_CCA_vect
70 #define CODEC_TIMER_TIMESTAMPS_CCB_VECT TCD1_CCB_vect
71 
72 #ifndef __ASSEMBLER__
73 
74 #include <avr/io.h>
75 #include <stdint.h>
76 #include <stdbool.h>
77 #include "../Common.h"
78 #include "../Configuration.h"
79 #include "../Settings.h"
80 
81 #include "ISO14443-2A.h"
82 #include "Reader14443-2A.h"
83 #include "SniffISO14443-2A.h"
84 #include "ISO15693.h"
85 #include "SniffISO15693.h"
86 
87 /* Timing definitions for ISO14443A */
88 #define ISO14443A_SUBCARRIER_DIVIDER 16
89 #define ISO14443A_BIT_GRID_CYCLES 128
90 #define ISO14443A_BIT_RATE_CYCLES 128
91 #define ISO14443A_FRAME_DELAY_PREV1 1236
92 #define ISO14443A_FRAME_DELAY_PREV0 1172
93 #define ISO14443A_RX_PENDING_TIMEOUT 4 // ms
94 
95 #define CODEC_BUFFER_SIZE 256
96 
97 #define CODEC_CARRIER_FREQ 13560000
98 
99 #define Codec8Reg0 GPIOR0
100 #define Codec8Reg1 GPIOR1
101 #define Codec8Reg2 GPIOR2
102 #define Codec8Reg3 GPIOR3
103 #define CodecCount16Register1 (*((volatile uint16_t*) &GPIOR4)) /* GPIOR4 & GPIOR5 */
104 #define CodecCount16Register2 (*((volatile uint16_t*) &GPIOR6)) /* GPIOR6 & GPIOR7 */
105 #define CodecPtrRegister1 (*((volatile uint8_t**) &GPIOR8))
106 #define CodecPtrRegister2 (*((volatile uint8_t**) &GPIORA))
107 #define CodecPtrRegister3 (*((volatile uint8_t**) &GPIORC))
108 
109 
110 extern uint16_t Reader_FWT;
111 
112 #define FWI2FWT(x) ((uint32_t)(256 * 16 * ((uint32_t)1 << (x))) / (CODEC_CARRIER_FREQ / 1000) + 1)
113 
114 typedef enum {
115  CODEC_SUBCARRIERMOD_OFF,
116  CODEC_SUBCARRIERMOD_OOK
117 } SubcarrierModType;
118 
119 extern uint8_t CodecBuffer[CODEC_BUFFER_SIZE];
120 extern uint8_t CodecBuffer2[CODEC_BUFFER_SIZE];
121 
122 extern enum RCTraffic {TRAFFIC_READER, TRAFFIC_CARD} SniffTrafficSource;
123 
124 /* Shared ISR pointers and handlers */
125 extern void (* volatile isr_func_TCD0_CCC_vect)(void);
126 void isr_Reader14443_2A_TCD0_CCC_vect(void);
127 void isr_ISO15693_CODEC_TIMER_SAMPLING_CCC_VECT(void);
128 extern void (* volatile isr_func_CODEC_DEMOD_IN_INT0_VECT)(void);
129 void isr_ISO14443_2A_TCD0_CCC_vect(void);
130 void isr_ISO15693_CODEC_DEMOD_IN_INT0_VECT(void);
131 extern void (* volatile isr_func_CODEC_TIMER_LOADMOD_OVF_VECT)(void);
132 void isr_ISO14443_2A_CODEC_TIMER_LOADMOD_OVF_VECT(void);
133 void isr_SNIFF_ISO15693_CODEC_TIMER_LOADMOD_OVF_VECT(void);
134 extern void (* volatile isr_func_CODEC_TIMER_LOADMOD_CCA_VECT)(void);
135 void isr_Reader14443_2A_CODEC_TIMER_LOADMOD_CCA_VECT(void);
136 void isr_SNIFF_ISO15693_CODEC_TIMER_LOADMOD_CCA_VECT(void);
137 extern void (* volatile isr_func_CODEC_TIMER_LOADMOD_CCB_VECT)(void);
138 void isr_ISO15693_CODEC_TIMER_LOADMOD_CCB_VECT(void);
139 void isr_SniffISO14443_2A_CODEC_TIMER_LOADMOD_CCB_VECT(void);
140 void isr_SNIFF_ISO15693_CODEC_TIMER_LOADMOD_CCA_VECT(void);
141 extern void (* volatile isr_func_CODEC_TIMER_TIMESTAMPS_CCA_VECT)(void);
142 void isr_Reader14443_2A_CODEC_TIMER_TIMESTAMPS_CCA_VECT(void);
143 void isr_SNIFF_ISO15693_CODEC_TIMER_TIMESTAMPS_CCA_VECT(void);
144 extern void (* volatile isr_func_ACA_AC0_vect)(void);
145 void isr_SniffISO14443_2A_ACA_AC0_VECT(void);
146 void isr_SNIFF_ISO15693_ACA_AC0_VECT(void);
147 
148 INLINE void CodecInit(void) {
149  ActiveConfiguration.CodecInitFunc();
150 }
151 
152 INLINE void CodecDeInit(void) {
153  ActiveConfiguration.CodecDeInitFunc();
154 }
155 
156 INLINE void CodecTask(void) {
157  ActiveConfiguration.CodecTaskFunc();
158 }
159 
160 /* Helper Functions for Codec implementations */
161 INLINE void CodecInitCommon(void) {
162  /* Configure CARRIER input pin and route it to EVSYS.
163  * Multiply by 2 again by using both edges when externally
164  * dividing by 2 */
165 #if CODEC_CARRIER_IN_DIV == 2
166  CODEC_CARRIER_IN_PORT.CODEC_CARRIER_IN_PINCTRL = PORT_ISC_BOTHEDGES_gc;
167 #else
168 #error Option not supported
169 #endif
170  CODEC_CARRIER_IN_PORT.DIRCLR = CODEC_CARRIER_IN_MASK;
171  EVSYS.CH6MUX = CODEC_CARRIER_IN_EVMUX;
172 
173  /* Configure two DEMOD pins for input.
174  * Configure event channel 0 for rising edge (begin of modulation pause)
175  * Configure event channel 1 for falling edge (end of modulation pause) */
176  CODEC_DEMOD_POWER_PORT.OUTCLR = CODEC_DEMOD_POWER_MASK;
177  CODEC_DEMOD_POWER_PORT.DIRSET = CODEC_DEMOD_POWER_MASK;
178  CODEC_DEMOD_IN_PORT.DIRCLR = CODEC_DEMOD_IN_MASK;
179  CODEC_DEMOD_IN_PORT.CODEC_DEMOD_IN_PINCTRL0 = PORT_ISC_RISING_gc;
180  CODEC_DEMOD_IN_PORT.CODEC_DEMOD_IN_PINCTRL1 = PORT_ISC_FALLING_gc;
181  CODEC_DEMOD_IN_PORT.INT0MASK = 0;
182  CODEC_DEMOD_IN_PORT.INT1MASK = 0;
183  CODEC_DEMOD_IN_PORT.INTCTRL = PORT_INT0LVL_HI_gc | PORT_INT1LVL_HI_gc;
184  EVSYS.CH0MUX = CODEC_DEMOD_IN_EVMUX0;
185  EVSYS.CH1MUX = CODEC_DEMOD_IN_EVMUX1;
186 
187  /* Configure loadmod pin configuration and use a virtual port configuration
188  * for single instruction cycle access */
189  CODEC_LOADMOD_PORT.DIRSET = CODEC_LOADMOD_MASK;
190  CODEC_LOADMOD_PORT.OUTCLR = CODEC_LOADMOD_MASK;
191  PORTCFG.VPCTRLA &= ~PORTCFG_VP0MAP_gm;
192  PORTCFG.VPCTRLA |= PORTCFG_VP02MAP_PORTC_gc;
193 
194  /* Configure subcarrier pins for output */
195  CODEC_SUBCARRIER_PORT.DIRSET = CODEC_SUBCARRIER_MASK;
196  CODEC_SUBCARRIER_PORT.OUTCLR = CODEC_SUBCARRIER_MASK;
197 
198  /* Configure pins for reader field with the LEFT output being inverted
199  * and all bridge outputs static high */
200  CODEC_READER_PORT.CODEC_READER_PINCTRL_LEFT = PORT_INVEN_bm;
201  CODEC_READER_PORT.OUTCLR = CODEC_READER_MASK_LEFT;
202  CODEC_READER_PORT.OUTSET = CODEC_READER_MASK_RIGHT;
203  CODEC_READER_PORT.DIRSET = CODEC_READER_MASK;
204 
205  /* Configure timer for generating reader field and configure AWEX for outputting pattern
206  * with disabled outputs. */
207  CODEC_READER_TIMER.CTRLB = TC0_CCAEN_bm | TC_WGMODE_SINGLESLOPE_gc;
208  CODEC_READER_TIMER.PER = F_CPU / CODEC_CARRIER_FREQ - 1;
209  CODEC_READER_TIMER.CCA = F_CPU / CODEC_CARRIER_FREQ / 2 ;
210 
211  AWEXC.OUTOVEN = 0x00;
212  AWEXC.CTRL = AWEX_CWCM_bm | AWEX_DTICCAEN_bm | AWEX_DTICCBEN_bm;
213 
214  /* Configure DAC for the reference voltage */
215  DACB.EVCTRL = 0;
216  DACB.CTRLB = DAC_CHSEL_SINGLE_gc;
217  DACB.CTRLC = DAC_REFSEL_AVCC_gc;
218  DACB.CTRLA = DAC_IDOEN_bm | DAC_ENABLE_bm;
219  DACB.CH0DATA = GlobalSettings.ActiveSettingPtr->ReaderThreshold; // real threshold voltage can be calculated with ch0data * Vref / 0xFFF
220 
221  /* Configure Analog Comparator 0 to detect changes in demodulated reader field */
222  ACA.AC0MUXCTRL = AC_MUXPOS_DAC_gc | AC_MUXNEG_PIN7_gc;
223  ACA.AC0CTRL = CODEC_AC_DEMOD_SETTINGS;
224 
225  /* Configure Analog Comparator 1 to detect SOC */
226  ACA.AC1MUXCTRL = AC_MUXPOS_DAC_gc | AC_MUXNEG_PIN7_gc;
227  ACA.AC1CTRL = CODEC_AC_DEMOD_SETTINGS;
228 }
229 
230 INLINE void CodecSetSubcarrier(SubcarrierModType ModType, uint16_t Divider) {
231  if (ModType == CODEC_SUBCARRIERMOD_OFF) {
232  CODEC_SUBCARRIER_TIMER.CTRLA = TC_CLKSEL_OFF_gc;
233  CODEC_SUBCARRIER_TIMER.CTRLB = 0;
234  } else if (ModType == CODEC_SUBCARRIERMOD_OOK) {
235  /* Configure subcarrier generation with 50% DC output using OOK */
236  CODEC_SUBCARRIER_TIMER.CNT = 0;
237  CODEC_SUBCARRIER_TIMER.PER = Divider - 1;
238  CODEC_SUBCARRIER_TIMER.CODEC_SUBCARRIER_CC_OOK = Divider / 2;
239  CODEC_SUBCARRIER_TIMER.CTRLB = CODEC_SUBCARRIER_CCEN_OOK | TC_WGMODE_SINGLESLOPE_gc;
240  }
241 }
242 
243 INLINE void CodecChangeDivider(uint16_t Divider) {
244  CODEC_SUBCARRIER_TIMER.PER = Divider - 1;
245 }
246 
247 INLINE void CodecStartSubcarrier(void) {
248  CODEC_SUBCARRIER_TIMER.CTRLA = CODEC_TIMER_CARRIER_CLKSEL;
249 }
250 
251 INLINE void CodecSetDemodPower(bool bOnOff) {
252  if (bOnOff) {
253  CODEC_DEMOD_POWER_PORT.OUTSET = CODEC_DEMOD_POWER_MASK;
254  } else {
255  CODEC_DEMOD_POWER_PORT.OUTCLR = CODEC_DEMOD_POWER_MASK;
256  }
257 }
258 
259 INLINE bool CodecGetLoadmodState(void) {
260  if (ACA.STATUS & AC_AC0STATE_bm) {
261  return true;
262  } else {
263  return false;
264  }
265 }
266 
267 INLINE void CodecSetLoadmodState(bool bOnOff) {
268  if (bOnOff) {
269  VPORT0.OUT |= CODEC_LOADMOD_MASK;
270  } else {
271  VPORT0.OUT &= ~CODEC_LOADMOD_MASK;
272  }
273 }
274 
275 // Turn on and off the codec Reader field
276 INLINE void CodecSetReaderField(bool bOnOff) { // this is the function for turning on/off the reader field dumbly; before using this function, please consider to use CodecReaderField{Start,Stop}
277 
278  if (bOnOff) {
279  /* Start timer for field generation and unmask outputs */
280  CODEC_READER_TIMER.CTRLA = TC_CLKSEL_DIV1_gc;
281  AWEXC.OUTOVEN = CODEC_READER_MASK;
282  } else {
283  /* Disable outputs of AWEX and stop field generation */
284  AWEXC.OUTOVEN = 0x00;
285  CODEC_READER_TIMER.CTRLA = TC_CLKSEL_OFF_gc;
286  }
287 }
288 
289 // Get the status of the reader field
290 INLINE bool CodecGetReaderField(void) {
291  return (CODEC_READER_TIMER.CTRLA == TC_CLKSEL_DIV1_gc) && (AWEXC.OUTOVEN == CODEC_READER_MASK);
292 }
293 
294 void CodecReaderFieldStart(void);
295 void CodecReaderFieldStop(void);
296 bool CodecIsReaderFieldReady(void);
297 
298 void CodecReaderFieldRestart(uint16_t delay);
299 #define FIELD_RESTART() CodecReaderFieldRestart(100)
300 bool CodecIsReaderToBeRestarted(void);
301 
302 void CodecThresholdSet(uint16_t th);
303 uint16_t CodecThresholdIncrement(void);
304 void CodecThresholdReset(void);
305 
306 #endif /* __ASSEMBLER__ */
307 
308 #endif /* CODEC_H_ */
void(* CodecInitFunc)(void)
Definition: Configuration.h:96
+
void(* CodecTaskFunc)(void)
Definition: Configuration.h:102
+
void(* CodecDeInitFunc)(void)
Definition: Configuration.h:98
diff --git a/Doc/Doxygen/html/_command_line_8h_source.html b/Doc/Doxygen/html/_command_line_8h_source.html index 5f41304a..88505b2d 100644 --- a/Doc/Doxygen/html/_command_line_8h_source.html +++ b/Doc/Doxygen/html/_command_line_8h_source.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: CommandLine.h Source File @@ -11,9 +12,6 @@ - @@ -31,40 +29,19 @@
- + - - + + + +
1 /*
2  * CommandLine.h
3  *
4  * Created on: 04.05.2013
5  * Author: skuser
6  */
7 
8 #ifndef COMMANDLINE_H_
9 #define COMMANDLINE_H_
10 
11 #include "Terminal.h"
12 #include "Commands.h"
13 
14 void CommandLineInit(void);
15 bool CommandLineProcessByte(uint8_t Byte);
16 void CommandLineTick(void);
17 
18 void CommandExecute(const char *command);
19 void CommandLineAppendData(void const *const Buffer, uint16_t Bytes);
20 
21 /* Functions for timeout commands */
22 void CommandLinePendingTaskFinished(CommandStatusIdType ReturnStatusID, char const *const OutMessage); // must be called, when the intended task is finished
23 extern void (*CommandLinePendingTaskTimeout)(void); // gets called on timeout to end the pending task
24 void CommandLinePendingTaskBreak(void); // this manually triggers a timeout
25 
26 #endif /* COMMANDLINE_H_ */
diff --git a/Doc/Doxygen/html/_command_line_8txt.html b/Doc/Doxygen/html/_command_line_8txt.html index 3d3b8736..2eed2715 100644 --- a/Doc/Doxygen/html/_command_line_8txt.html +++ b/Doc/Doxygen/html/_command_line_8txt.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: CommandLine.txt File Reference @@ -11,9 +12,6 @@ - @@ -31,40 +29,19 @@ - + - - + + + +
diff --git a/Doc/Doxygen/html/_commands_8h_source.html b/Doc/Doxygen/html/_commands_8h_source.html index 18bd8ae2..d907a137 100644 --- a/Doc/Doxygen/html/_commands_8h_source.html +++ b/Doc/Doxygen/html/_commands_8h_source.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: Commands.h Source File @@ -11,9 +12,6 @@ - @@ -31,40 +29,19 @@
- + - - + + + +
Commands.h
-
1 
2 
3 #ifndef COMMANDS_H_
4 #define COMMANDS_H_
5 
6 #include "../Common.h"
7 
8 #define MAX_COMMAND_LENGTH 16
9 #define MAX_STATUS_LENGTH 32
10 
11 
12 #define COMMAND_INFO_OK_ID 100
13 #define COMMAND_INFO_OK "OK"
14 #define COMMAND_INFO_OK_WITH_TEXT_ID 101
15 #define COMMAND_INFO_OK_WITH_TEXT "OK WITH TEXT"
16 #define COMMAND_INFO_XMODEM_WAIT_ID 110
17 #define COMMAND_INFO_XMODEM_WAIT "WAITING FOR XMODEM"
18 #define COMMAND_INFO_FALSE_ID 120
19 #define COMMAND_INFO_FALSE "FALSE"
20 #define COMMAND_INFO_TRUE_ID 121
21 #define COMMAND_INFO_TRUE "TRUE"
22 #define COMMAND_ERR_UNKNOWN_CMD_ID 200
23 #define COMMAND_ERR_UNKNOWN_CMD "UNKNOWN COMMAND"
24 #define COMMAND_ERR_INVALID_USAGE_ID 201
25 #define COMMAND_ERR_INVALID_USAGE "INVALID COMMAND USAGE"
26 #define COMMAND_ERR_INVALID_PARAM_ID 202
27 #define COMMAND_ERR_INVALID_PARAM "INVALID PARAMETER"
28 #define COMMAND_ERR_TIMEOUT_ID 203
29 #define COMMAND_ERR_TIMEOUT "TIMEOUT"
30 #define TIMEOUT_COMMAND 255 // this is just for the CommandLine module to know that this is a timeout command
31 
32 
33 #define COMMAND_CHAR_TRUE '1'
34 #define COMMAND_CHAR_FALSE '0'
35 #define COMMAND_CHAR_SUGGEST '?' /* <CMD>=? for help */
36 
37 #define COMMAND_UID_BUFSIZE 32
38 
39 #define COMMAND_IS_SUGGEST_STRING(x) ( ((x)[0] == COMMAND_CHAR_SUGGEST) && ((x)[1] == '\0') )
40 
41 typedef uint8_t CommandStatusIdType;
42 typedef const char CommandStatusMessageType[MAX_STATUS_LENGTH];
43 
44 typedef CommandStatusIdType(*CommandExecFuncType)(char *OutMessage);
45 typedef CommandStatusIdType(*CommandExecParamFuncType)(char *OutMessage, const char *InParams);
46 typedef CommandStatusIdType(*CommandSetFuncType)(char *OutMessage, const char *InParam);
47 typedef CommandStatusIdType(*CommandGetFuncType)(char *OutParam);
48 
49 typedef struct {
50  char Command[MAX_COMMAND_LENGTH];
51  CommandExecFuncType ExecFunc;
52  CommandExecParamFuncType ExecParamFunc;
53  CommandSetFuncType SetFunc;
54  CommandGetFuncType GetFunc;
55 } CommandEntryType;
56 
57 #define COMMAND_VERSION "VERSION"
58 CommandStatusIdType CommandGetVersion(char *OutParam);
59 
60 #define COMMAND_CONFIG "CONFIG"
61 CommandStatusIdType CommandGetConfig(char *OutParam);
62 CommandStatusIdType CommandSetConfig(char *OutMessage, const char *InParam);
63 
64 #define COMMAND_UID "UID"
65 #define COMMAND_UID_RANDOM "RANDOM"
66 CommandStatusIdType CommandGetUid(char *OutParam);
67 CommandStatusIdType CommandSetUid(char *OutMessage, const char *InParam);
68 
69 #define COMMAND_READONLY "READONLY"
70 CommandStatusIdType CommandGetReadOnly(char *OutParam);
71 CommandStatusIdType CommandSetReadOnly(char *OutMessage, const char *InParam);
72 
73 #define COMMAND_UPLOAD "UPLOAD"
74 CommandStatusIdType CommandExecUpload(char *OutMessage);
75 
76 #define COMMAND_DOWNLOAD "DOWNLOAD"
77 CommandStatusIdType CommandExecDownload(char *OutMessage);
78 
79 #define COMMAND_RESET "RESET"
80 CommandStatusIdType CommandExecReset(char *OutMessage);
81 
82 #define COMMAND_UPGRADE "UPGRADE"
83 CommandStatusIdType CommandExecUpgrade(char *OutMessage);
84 
85 #define COMMAND_MEMSIZE "MEMSIZE"
86 CommandStatusIdType CommandGetMemSize(char *OutParam);
87 
88 #define COMMAND_UIDSIZE "UIDSIZE"
89 CommandStatusIdType CommandGetUidSize(char *OutParam);
90 
91 #define COMMAND_RBUTTON "RBUTTON"
92 CommandStatusIdType CommandGetRButton(char *OutParam);
93 CommandStatusIdType CommandSetRButton(char *OutMessage, const char *InParam);
94 
95 #define COMMAND_RBUTTON_LONG "RBUTTON_LONG"
96 CommandStatusIdType CommandGetRButtonLong(char *OutParam);
97 CommandStatusIdType CommandSetRButtonLong(char *OutMessage, const char *InParam);
98 
99 #define COMMAND_LBUTTON "LBUTTON"
100 CommandStatusIdType CommandGetLButton(char *OutParam);
101 CommandStatusIdType CommandSetLButton(char *OutMessage, const char *InParam);
102 
103 #define COMMAND_LBUTTON_LONG "LBUTTON_LONG"
104 CommandStatusIdType CommandGetLButtonLong(char *OutParam);
105 CommandStatusIdType CommandSetLButtonLong(char *OutMessage, const char *InParam);
106 
107 
108 #define COMMAND_LEDGREEN "LEDGREEN"
109 CommandStatusIdType CommandGetLedGreen(char *OutParam);
110 CommandStatusIdType CommandSetLedGreen(char *OutMessage, const char *InParam);
111 
112 #define COMMAND_LEDRED "LEDRED"
113 CommandStatusIdType CommandGetLedRed(char *OutParam);
114 CommandStatusIdType CommandSetLedRed(char *OutMessage, const char *InParam);
115 
116 #define COMMAND_PIN "PIN"
117 CommandStatusIdType CommandGetPin(char *OutParam);
118 CommandStatusIdType CommandSetPin(char *OutMessage, const char *InParam);
119 
120 #define COMMAND_LOGMODE "LOGMODE"
121 CommandStatusIdType CommandGetLogMode(char *OutParam);
122 CommandStatusIdType CommandSetLogMode(char *OutMessage, const char *InParam);
123 
124 #define COMMAND_LOGMEM "LOGMEM"
125 CommandStatusIdType CommandGetLogMem(char *OutParam);
126 
127 #define COMMAND_LOGDOWNLOAD "LOGDOWNLOAD"
128 CommandStatusIdType CommandExecLogDownload(char *OutMessage);
129 
130 #define COMMAND_STORELOG "LOGSTORE"
131 CommandStatusIdType CommandExecStoreLog(char *OutMessage);
132 
133 #define COMMAND_LOGCLEAR "LOGCLEAR"
134 CommandStatusIdType CommandExecLogClear(char *OutMessage);
135 
136 #define COMMAND_SETTING "SETTING"
137 CommandStatusIdType CommandGetSetting(char *OutParam);
138 CommandStatusIdType CommandSetSetting(char *OutMessage, const char *InParam);
139 
140 #define COMMAND_CLEAR "CLEAR"
141 CommandStatusIdType CommandExecClear(char *OutMessage);
142 
143 #define COMMAND_STORE "STORE"
144 CommandStatusIdType CommandExecStore(char *OutMessage);
145 
146 #define COMMAND_RECALL "RECALL"
147 CommandStatusIdType CommandExecRecall(char *OutMessage);
148 
149 #define COMMAND_CHARGING "CHARGING"
150 CommandStatusIdType CommandGetCharging(char *OutParam);
151 
152 #define COMMAND_HELP "HELP"
153 CommandStatusIdType CommandExecHelp(char *OutMessage);
154 
155 #define COMMAND_RSSI "RSSI"
156 CommandStatusIdType CommandGetRssi(char *OutParam);
157 
158 #define COMMAND_SYSTICK "SYSTICK"
159 CommandStatusIdType CommandGetSysTick(char *OutParam);
160 
161 #define COMMAND_SEND_RAW "SEND_RAW"
162 CommandStatusIdType CommandExecParamSendRaw(char *OutMessage, const char *InParams);
163 
164 #define COMMAND_SEND "SEND"
165 CommandStatusIdType CommandExecParamSend(char *OutMessage, const char *InParams);
166 
167 #define COMMAND_GETUID "GETUID"
168 CommandStatusIdType CommandExecGetUid(char *OutMessage);
169 
170 #define COMMAND_DUMP_MFU "DUMP_MFU"
171 CommandStatusIdType CommandExecDumpMFU(char *OutMessage);
172 
173 #define COMMAND_CLONE_MFU "CLONE_MFU"
174 CommandStatusIdType CommandExecCloneMFU(char *OutMessage);
175 
176 #define COMMAND_IDENTIFY_CARD "IDENTIFY"
177 CommandStatusIdType CommandExecIdentifyCard(char *OutMessage);
178 
179 #define COMMAND_TIMEOUT "TIMEOUT"
180 CommandStatusIdType CommandGetTimeout(char *OutMessage);
181 CommandStatusIdType CommandSetTimeout(char *OutMessage, const char *InParam);
182 
183 #define COMMAND_THRESHOLD "THRESHOLD"
184 CommandStatusIdType CommandGetThreshold(char *OutParam);
185 CommandStatusIdType CommandSetThreshold(char *OutMessage, const char *InParam);
186 
187 #define COMMAND_AUTOCALIBRATE "AUTOCALIBRATE"
188 CommandStatusIdType CommandExecAutocalibrate(char *OutMessage);
189 
190 #define COMMAND_FIELD "FIELD"
191 CommandStatusIdType CommandSetField(char *OutMessage, const char *InParam);
192 CommandStatusIdType CommandGetField(char *OutMessage);
193 
194 #define COMMAND_CLONE "CLONE"
195 CommandStatusIdType CommandExecClone(char *OutMessage);
196 
197 #ifdef ENABLE_RUNTESTS_TERMINAL_COMMAND
198  #include "../Tests/ChameleonTerminal.h"
199 #endif
200 
201 #if defined(CONFIG_MF_DESFIRE_SUPPORT) && !defined(DISABLE_DESFIRE_TERMINAL_COMMANDS)
202  #include "../Application/DESFire/DESFireChameleonTerminal.h"
203 #endif
204 
205 #define COMMAND_LIST_END ""
206 /* Defines the end of command list. This is no actual command */
207 
208 #endif /* COMMANDS_H_ */
+
1 
2 
3 #ifndef COMMANDS_H_
4 #define COMMANDS_H_
5 
6 #include "../Common.h"
7 
8 #define MAX_COMMAND_LENGTH 16
9 #define MAX_STATUS_LENGTH 32
10 
11 
12 #define COMMAND_INFO_OK_ID 100
13 #define COMMAND_INFO_OK "OK"
14 #define COMMAND_INFO_OK_WITH_TEXT_ID 101
15 #define COMMAND_INFO_OK_WITH_TEXT "OK WITH TEXT"
16 #define COMMAND_INFO_XMODEM_WAIT_ID 110
17 #define COMMAND_INFO_XMODEM_WAIT "WAITING FOR XMODEM"
18 #define COMMAND_INFO_FALSE_ID 120
19 #define COMMAND_INFO_FALSE "FALSE"
20 #define COMMAND_INFO_TRUE_ID 121
21 #define COMMAND_INFO_TRUE "TRUE"
22 #define COMMAND_ERR_UNKNOWN_CMD_ID 200
23 #define COMMAND_ERR_UNKNOWN_CMD "UNKNOWN COMMAND"
24 #define COMMAND_ERR_INVALID_USAGE_ID 201
25 #define COMMAND_ERR_INVALID_USAGE "INVALID COMMAND USAGE"
26 #define COMMAND_ERR_INVALID_PARAM_ID 202
27 #define COMMAND_ERR_INVALID_PARAM "INVALID PARAMETER"
28 #define COMMAND_ERR_TIMEOUT_ID 203
29 #define COMMAND_ERR_TIMEOUT "TIMEOUT"
30 #define TIMEOUT_COMMAND 255 // this is just for the CommandLine module to know that this is a timeout command
31 
32 
33 #define COMMAND_CHAR_TRUE '1'
34 #define COMMAND_CHAR_FALSE '0'
35 #define COMMAND_CHAR_SUGGEST '?' /* <CMD>=? for help */
36 
37 #define COMMAND_UID_BUFSIZE 32
38 
39 #define COMMAND_IS_SUGGEST_STRING(x) ( ((x)[0] == COMMAND_CHAR_SUGGEST) && ((x)[1] == '\0') )
40 
41 typedef uint8_t CommandStatusIdType;
42 typedef const char CommandStatusMessageType[MAX_STATUS_LENGTH];
43 
44 typedef CommandStatusIdType(*CommandExecFuncType)(char *OutMessage);
45 typedef CommandStatusIdType(*CommandExecParamFuncType)(char *OutMessage, const char *InParams);
46 typedef CommandStatusIdType(*CommandSetFuncType)(char *OutMessage, const char *InParam);
47 typedef CommandStatusIdType(*CommandGetFuncType)(char *OutParam);
48 
49 typedef struct {
50  char Command[MAX_COMMAND_LENGTH];
51  CommandExecFuncType ExecFunc;
52  CommandExecParamFuncType ExecParamFunc;
53  CommandSetFuncType SetFunc;
54  CommandGetFuncType GetFunc;
55 } CommandEntryType;
56 
57 #define COMMAND_VERSION "VERSION"
58 CommandStatusIdType CommandGetVersion(char *OutParam);
59 
60 #define COMMAND_CONFIG "CONFIG"
61 CommandStatusIdType CommandGetConfig(char *OutParam);
62 CommandStatusIdType CommandSetConfig(char *OutMessage, const char *InParam);
63 
64 #define COMMAND_UID "UID"
65 #define COMMAND_UID_RANDOM "RANDOM"
66 CommandStatusIdType CommandGetUid(char *OutParam);
67 CommandStatusIdType CommandSetUid(char *OutMessage, const char *InParam);
68 
69 #define COMMAND_READONLY "READONLY"
70 CommandStatusIdType CommandGetReadOnly(char *OutParam);
71 CommandStatusIdType CommandSetReadOnly(char *OutMessage, const char *InParam);
72 
73 #define COMMAND_UPLOAD "UPLOAD"
74 CommandStatusIdType CommandExecUpload(char *OutMessage);
75 
76 #define COMMAND_DOWNLOAD "DOWNLOAD"
77 CommandStatusIdType CommandExecDownload(char *OutMessage);
78 
79 #define COMMAND_RESET "RESET"
80 CommandStatusIdType CommandExecReset(char *OutMessage);
81 
82 #define COMMAND_UPGRADE "UPGRADE"
83 CommandStatusIdType CommandExecUpgrade(char *OutMessage);
84 
85 #define COMMAND_MEMSIZE "MEMSIZE"
86 CommandStatusIdType CommandGetMemSize(char *OutParam);
87 
88 #define COMMAND_UIDSIZE "UIDSIZE"
89 CommandStatusIdType CommandGetUidSize(char *OutParam);
90 
91 #define COMMAND_RBUTTON "RBUTTON"
92 CommandStatusIdType CommandGetRButton(char *OutParam);
93 CommandStatusIdType CommandSetRButton(char *OutMessage, const char *InParam);
94 
95 #define COMMAND_RBUTTON_LONG "RBUTTON_LONG"
96 CommandStatusIdType CommandGetRButtonLong(char *OutParam);
97 CommandStatusIdType CommandSetRButtonLong(char *OutMessage, const char *InParam);
98 
99 #define COMMAND_LBUTTON "LBUTTON"
100 CommandStatusIdType CommandGetLButton(char *OutParam);
101 CommandStatusIdType CommandSetLButton(char *OutMessage, const char *InParam);
102 
103 #define COMMAND_LBUTTON_LONG "LBUTTON_LONG"
104 CommandStatusIdType CommandGetLButtonLong(char *OutParam);
105 CommandStatusIdType CommandSetLButtonLong(char *OutMessage, const char *InParam);
106 
107 
108 #define COMMAND_LEDGREEN "LEDGREEN"
109 CommandStatusIdType CommandGetLedGreen(char *OutParam);
110 CommandStatusIdType CommandSetLedGreen(char *OutMessage, const char *InParam);
111 
112 #define COMMAND_LEDRED "LEDRED"
113 CommandStatusIdType CommandGetLedRed(char *OutParam);
114 CommandStatusIdType CommandSetLedRed(char *OutMessage, const char *InParam);
115 
116 #define COMMAND_PIN "PIN"
117 CommandStatusIdType CommandGetPin(char *OutParam);
118 CommandStatusIdType CommandSetPin(char *OutMessage, const char *InParam);
119 
120 #define COMMAND_LOGMODE "LOGMODE"
121 CommandStatusIdType CommandGetLogMode(char *OutParam);
122 CommandStatusIdType CommandSetLogMode(char *OutMessage, const char *InParam);
123 
124 #define COMMAND_LOGMEM "LOGMEM"
125 CommandStatusIdType CommandGetLogMem(char *OutParam);
126 
127 #define COMMAND_LOGDOWNLOAD "LOGDOWNLOAD"
128 CommandStatusIdType CommandExecLogDownload(char *OutMessage);
129 
130 #define COMMAND_STORELOG "LOGSTORE"
131 CommandStatusIdType CommandExecStoreLog(char *OutMessage);
132 
133 #define COMMAND_LOGCLEAR "LOGCLEAR"
134 CommandStatusIdType CommandExecLogClear(char *OutMessage);
135 
136 #define COMMAND_SETTING "SETTING"
137 CommandStatusIdType CommandGetSetting(char *OutParam);
138 CommandStatusIdType CommandSetSetting(char *OutMessage, const char *InParam);
139 
140 #define COMMAND_CLEAR "CLEAR"
141 CommandStatusIdType CommandExecClear(char *OutMessage);
142 
143 #define COMMAND_STORE "STORE"
144 CommandStatusIdType CommandExecStore(char *OutMessage);
145 
146 #define COMMAND_RECALL "RECALL"
147 CommandStatusIdType CommandExecRecall(char *OutMessage);
148 
149 #define COMMAND_CHARGING "CHARGING"
150 CommandStatusIdType CommandGetCharging(char *OutParam);
151 
152 #define COMMAND_HELP "HELP"
153 CommandStatusIdType CommandExecHelp(char *OutMessage);
154 
155 #define COMMAND_RSSI "RSSI"
156 CommandStatusIdType CommandGetRssi(char *OutParam);
157 
158 #define COMMAND_SYSTICK "SYSTICK"
159 CommandStatusIdType CommandGetSysTick(char *OutParam);
160 
161 #define COMMAND_SEND_RAW "SEND_RAW"
162 CommandStatusIdType CommandExecParamSendRaw(char *OutMessage, const char *InParams);
163 
164 #define COMMAND_SEND "SEND"
165 CommandStatusIdType CommandExecParamSend(char *OutMessage, const char *InParams);
166 
167 #define COMMAND_GETUID "GETUID"
168 CommandStatusIdType CommandExecGetUid(char *OutMessage);
169 
170 #define COMMAND_DUMP_MFU "DUMP_MFU"
171 CommandStatusIdType CommandExecDumpMFU(char *OutMessage);
172 
173 #define COMMAND_CLONE_MFU "CLONE_MFU"
174 CommandStatusIdType CommandExecCloneMFU(char *OutMessage);
175 
176 #define COMMAND_IDENTIFY_CARD "IDENTIFY"
177 CommandStatusIdType CommandExecIdentifyCard(char *OutMessage);
178 
179 #define COMMAND_TIMEOUT "TIMEOUT"
180 CommandStatusIdType CommandGetTimeout(char *OutMessage);
181 CommandStatusIdType CommandSetTimeout(char *OutMessage, const char *InParam);
182 
183 #define COMMAND_THRESHOLD "THRESHOLD"
184 CommandStatusIdType CommandGetThreshold(char *OutParam);
185 CommandStatusIdType CommandSetThreshold(char *OutMessage, const char *InParam);
186 
187 #define COMMAND_AUTOCALIBRATE "AUTOCALIBRATE"
188 CommandStatusIdType CommandExecAutocalibrate(char *OutMessage);
189 
190 #define COMMAND_FIELD "FIELD"
191 CommandStatusIdType CommandSetField(char *OutMessage, const char *InParam);
192 CommandStatusIdType CommandGetField(char *OutMessage);
193 
194 #define COMMAND_CLONE "CLONE"
195 CommandStatusIdType CommandExecClone(char *OutMessage);
196 
197 #ifdef CONFIG_ISO15693_SNIFF_SUPPORT
198 #define COMMAND_AUTOTHRESHOLD "AUTOTHRESHOLD"
199 CommandStatusIdType CommandGetAutoThreshold(char *OutParam);
200 CommandStatusIdType CommandSetAutoThreshold(char *OutMessage, const char *InParam);
201 #endif /*#ifdef CONFIG_ISO15693_SNIFF_SUPPORT*/
202 
203 #ifdef ENABLE_RUNTESTS_TERMINAL_COMMAND
204 #include "../Tests/ChameleonTerminal.h"
205 #endif
206 
207 #if defined(CONFIG_MF_DESFIRE_SUPPORT) && !defined(DISABLE_DESFIRE_TERMINAL_COMMANDS)
208 #include "../Application/DESFire/DESFireChameleonTerminal.h"
209 #endif
210 
211 #define COMMAND_LIST_END ""
212 /* Defines the end of command list. This is no actual command */
213 
214 #endif /* COMMANDS_H_ */
diff --git a/Doc/Doxygen/html/_common_8h_source.html b/Doc/Doxygen/html/_common_8h_source.html index 074801f3..8e302510 100644 --- a/Doc/Doxygen/html/_common_8h_source.html +++ b/Doc/Doxygen/html/_common_8h_source.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: Common.h Source File @@ -11,9 +12,6 @@ - @@ -31,40 +29,19 @@ - + - - + + + +
Common.h
-
1 /*
2  * Common.h
3  *
4  * Created on: 20.03.2013
5  * Author: skuser
6  */
7 
8 #ifndef COMMON_H_
9 #define COMMON_H_
10 
11 #include <stdio.h>
12 #include <stdbool.h>
13 #include <util/parity.h>
14 #include <util/delay.h>
15 #include <avr/pgmspace.h>
16 #include <avr/io.h>
17 
18 #define ODD_PARITY(Value) OddParityBit(Value)//(parity_even_bit(Value) ? 0 : 1)
19 
20 #define ISR_SHARED \
21  void __attribute__((signal)) // This function type has to be used for all the interrupt handlers that have to be changed at runtime
22 
23 #define INLINE \
24  static inline __attribute__((always_inline))
25 
26 #ifndef STRINGIFY
27 #define STRINGIFY(x) #x
28 #endif
29 
30 #define ARRAY_COUNT(x) \
31  (sizeof(x) / sizeof(x[0]))
32 
33 #define NIBBLE_TO_HEXCHAR(x) ( (x) < 0x0A ? (x) + '0' : (x) + 'A' - 0x0A )
34 #define HEXCHAR_TO_NIBBLE(x) ( (x) < 'A' ? (x) - '0' : (x) - 'A' + 0x0A )
35 #define VALID_HEXCHAR(x) ( ( (x) >= '0' && (x) <= '9' ) || ( (x) >= 'A' && (x) <= 'F' ) )
36 #define MIN(x,y) ( (x) < (y) ? (x) : (y) )
37 #define MAX(x,y) ( (x) > (y) ? (x) : (y) )
38 #define SYSTICK_DIFF(since) ((uint16_t) (SystemGetSysTick() - since))
39 #define SYSTICK_DIFF_100MS(since) (SYSTICK_DIFF(since) / 100)
40 
41 #define BITS_PER_BYTE 8
42 
43 uint16_t BufferToHexString(char *HexOut, uint16_t MaxChars, const void *Buffer, uint16_t ByteCount);
44 uint16_t HexStringToBuffer(void *Buffer, uint16_t MaxBytes, const char *HexIn);
45 
46 INLINE uint8_t BitReverseByte(uint8_t Byte) {
47  extern const uint8_t PROGMEM BitReverseByteTable[];
48 
49  return pgm_read_byte(&BitReverseByteTable[Byte]);
50 }
51 
52 INLINE uint8_t OddParityBit(uint8_t Byte) {
53  extern const uint8_t PROGMEM OddParityByteTable[];
54 
55  return pgm_read_byte(&OddParityByteTable[Byte]);
56 }
57 
58 INLINE uint8_t StringLength(const char *Str, uint8_t MaxLen) {
59  uint8_t StrLen = 0;
60 
61  while (MaxLen > 0) {
62  if (*Str++ == '\0')
63  break;
64 
65  MaxLen--;
66  StrLen++;
67  }
68 
69  return StrLen;
70 }
71 
72 #endif /* COMMON_H_ */
+
1 /*
2  * Common.h
3  *
4  * Created on: 20.03.2013
5  * Author: skuser
6  */
7 
8 #ifndef COMMON_H_
9 #define COMMON_H_
10 
11 #include <stdio.h>
12 #include <stdbool.h>
13 #include <util/parity.h>
14 #include <util/delay.h>
15 #include <avr/pgmspace.h>
16 #include <avr/io.h>
17 
18 #define ODD_PARITY(Value) OddParityBit(Value)//(parity_even_bit(Value) ? 0 : 1)
19 
20 #define ISR_SHARED \
21  void __attribute__((signal)) // This function type has to be used for all the interrupt handlers that have to be changed at runtime
22 
23 #define INLINE \
24  static inline __attribute__((always_inline))
25 
26 #ifndef STRINGIFY
27 #define STRINGIFY(x) #x
28 #endif
29 
30 #define ARRAY_COUNT(x) \
31  (sizeof(x) / sizeof(x[0]))
32 
33 #define NIBBLE_TO_HEXCHAR(x) ( (x) < 0x0A ? (x) + '0' : (x) + 'A' - 0x0A )
34 #define HEXCHAR_TO_NIBBLE(x) ( (x) < 'A' ? (x) - '0' : (x) - 'A' + 0x0A )
35 #define VALID_HEXCHAR(x) ( ( (x) >= '0' && (x) <= '9' ) || ( (x) >= 'A' && (x) <= 'F' ) )
36 #define MIN(x,y) ( (x) < (y) ? (x) : (y) )
37 #define MAX(x,y) ( (x) > (y) ? (x) : (y) )
38 #define SYSTICK_DIFF(since) ((uint16_t) (SystemGetSysTick() - since))
39 #define SYSTICK_DIFF_100MS(since) (SYSTICK_DIFF(since) / 100)
40 
41 #define BITS_PER_BYTE 8
42 #define ARCH_BIG_ENDIAN
43 
44 uint16_t BufferToHexString(char *HexOut, uint16_t MaxChars, const void *Buffer, uint16_t ByteCount);
45 uint16_t HexStringToBuffer(void *Buffer, uint16_t MaxBytes, const char *HexIn);
46 
47 INLINE uint8_t BitReverseByte(uint8_t Byte) {
48  extern const uint8_t PROGMEM BitReverseByteTable[];
49 
50  return pgm_read_byte(&BitReverseByteTable[Byte]);
51 }
52 
53 INLINE uint8_t OddParityBit(uint8_t Byte) {
54  extern const uint8_t PROGMEM OddParityByteTable[];
55 
56  return pgm_read_byte(&OddParityByteTable[Byte]);
57 }
58 
59 INLINE uint8_t StringLength(const char *Str, uint8_t MaxLen) {
60  uint8_t StrLen = 0;
61 
62  while (MaxLen > 0) {
63  if (*Str++ == '\0')
64  break;
65 
66  MaxLen--;
67  StrLen++;
68  }
69 
70  return StrLen;
71 }
72 
73 #endif /* COMMON_H_ */
diff --git a/Doc/Doxygen/html/_configuration_8h.html b/Doc/Doxygen/html/_configuration_8h.html index 68b7cf92..11fe29bb 100644 --- a/Doc/Doxygen/html/_configuration_8h.html +++ b/Doc/Doxygen/html/_configuration_8h.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: Configuration.h File Reference @@ -11,9 +12,6 @@ - @@ -31,40 +29,19 @@ - + - - + + + +
 

Macro Definition Documentation

- + +

◆ TAG_FAMILY_NONE

+
@@ -125,9 +104,9 @@

Macro Definition Documentation

diff --git a/Doc/Doxygen/html/_configuration_8h_source.html b/Doc/Doxygen/html/_configuration_8h_source.html index d2cabc08..b3745943 100644 --- a/Doc/Doxygen/html/_configuration_8h_source.html +++ b/Doc/Doxygen/html/_configuration_8h_source.html @@ -3,7 +3,8 @@ - + +Chameleon-Mini: Configuration.h Source File @@ -11,9 +12,6 @@ - @@ -31,40 +29,19 @@
- + - - + + + +
Configuration.h
-Go to the documentation of this file.
1 /*
2  * Standards.h
3  *
4  * Created on: 15.02.2013
5  * Author: skuser
6  */
8 #ifndef STANDARDS_H_
9 #define STANDARDS_H_
10 
11 #include <stdint.h>
12 #include <stdbool.h>
13 
14 #include "Map.h"
15 
16 #define CONFIGURATION_NAME_LENGTH_MAX 32
17 #define CONFIGURATION_UID_SIZE_MAX 16
18 
19 typedef uint8_t ConfigurationUidType[CONFIGURATION_UID_SIZE_MAX];
20 
21 typedef enum {
22  /* This HAS to be the first element */
23  CONFIG_NONE = 0,
24 
25 #ifdef CONFIG_MF_ULTRALIGHT_SUPPORT
26  CONFIG_MF_ULTRALIGHT,
27  CONFIG_MF_ULTRALIGHT_C,
28  CONFIG_MF_ULTRALIGHT_EV1_80B,
29  CONFIG_MF_ULTRALIGHT_EV1_164B,
30 #endif
31 #ifdef CONFIG_MF_CLASSIC_MINI_4B_SUPPORT
32  CONFIG_MF_CLASSIC_MINI_4B,
33 #endif
34 #ifdef CONFIG_MF_CLASSIC_1K_SUPPORT
35  CONFIG_MF_CLASSIC_1K,
36 #endif
37 #ifdef CONFIG_MF_CLASSIC_1K_7B_SUPPORT
38  CONFIG_MF_CLASSIC_1K_7B,
39 #endif
40 #ifdef CONFIG_MF_CLASSIC_4K_SUPPORT
41  CONFIG_MF_CLASSIC_4K,
42 #endif
43 #ifdef CONFIG_MF_CLASSIC_4K_7B_SUPPORT
44  CONFIG_MF_CLASSIC_4K_7B,
45 #endif
46 #ifdef CONFIG_ISO14443A_SNIFF_SUPPORT
47  CONFIG_ISO14443A_SNIFF,
48 #endif
49 #ifdef CONFIG_ISO14443A_READER_SUPPORT
50  CONFIG_ISO14443A_READER,
51 #endif
52 #ifdef CONFIG_NTAG215_SUPPORT
53  CONFIG_NTAG215,
54 #endif
55 #ifdef CONFIG_VICINITY_SUPPORT
56  CONFIG_VICINITY,
57 #endif
58 #ifdef CONFIG_ISO15693_SNIFF_SUPPORT
59  CONFIG_ISO15693_SNIFF,
60 #endif
61 #ifdef CONFIG_SL2S2002_SUPPORT
62  CONFIG_SL2S2002,
63 #endif
64 #ifdef CONFIG_TITAGITSTANDARD_SUPPORT
65  CONFIG_TITAGITSTANDARD,
66 #endif
67 #ifdef CONFIG_EM4233_SUPPORT
68  CONFIG_EM4233,
69 #endif
70 #ifdef CONFIG_MF_DESFIRE_SUPPORT
71  CONFIG_MF_DESFIRE,
72 #endif
73  /* This HAS to be the last element */
74  CONFIG_COUNT
75 } ConfigurationEnum;
76 
78 #define TAG_FAMILY_NONE 0
79 #define TAG_FAMILY_ISO14443A 1
80 #define TAG_FAMILY_ISO14443B 2
81 #define TAG_FAMILY_ISO15693 5
82 
83 
85 typedef struct {
93  void (*CodecInitFunc)(void);
95  void (*CodecDeInitFunc)(void);
99  void (*CodecTaskFunc)(void);
111  void (*ApplicationInitFunc)(void);
113  void (*ApplicationResetFunc)(void);
115  void (*ApplicationTaskFunc)(void);
117  void (*ApplicationTickFunc)(void);
129  uint16_t (*ApplicationProcessFunc)(uint8_t *ByteBuffer, uint16_t BitCount);
134  void (*ApplicationGetUidFunc)(ConfigurationUidType Uid);
139  void (*ApplicationSetUidFunc)(ConfigurationUidType Uid);
150  uint16_t MemorySize;
156  uint8_t UidSize;
160  bool ReadOnly;
164  uint8_t TagFamily;
165 
167 
168 extern ConfigurationType ActiveConfiguration;
169 
170 void ConfigurationInit(void);
171 void ConfigurationSetById(ConfigurationEnum Configuration);
172 MapIdType ConfigurationCheckByName(const char *Configuration);
173 void ConfigurationGetByName(char *Configuration, uint16_t BufferSize);
174 bool ConfigurationSetByName(const char *Configuration);
175 void ConfigurationGetList(char *ConfigurationList, uint16_t BufferSize);
176 
177 #endif /* STANDARDS_H_ */
uint8_t TagFamily
Definition: Configuration.h:164
-
uint16_t MemorySize
Definition: Configuration.h:150
-
Definition: Configuration.h:85
-
bool ReadOnly
Definition: Configuration.h:160
-
uint8_t UidSize
Definition: Configuration.h:156
+Go to the documentation of this file.
1 /*
2  * Standards.h
3  *
4  * Created on: 15.02.2013
5  * Author: skuser
6  */
8 #ifndef STANDARDS_H_
9 #define STANDARDS_H_
10 
11 #include <stdint.h>
12 #include <stdbool.h>
13 
14 #include "Map.h"
15 
16 #define CONFIGURATION_NAME_LENGTH_MAX 32
17 #define CONFIGURATION_UID_SIZE_MAX 16
18 
19 typedef uint8_t ConfigurationUidType[CONFIGURATION_UID_SIZE_MAX];
20 
21 typedef enum {
22  /* This HAS to be the first element */
23  CONFIG_NONE = 0,
24 
25 #ifdef CONFIG_MF_ULTRALIGHT_SUPPORT
26  CONFIG_MF_ULTRALIGHT,
27  CONFIG_MF_ULTRALIGHT_C,
28  CONFIG_MF_ULTRALIGHT_EV1_80B,
29  CONFIG_MF_ULTRALIGHT_EV1_164B,
30 #endif
31 #ifdef CONFIG_MF_CLASSIC_MINI_4B_SUPPORT
32  CONFIG_MF_CLASSIC_MINI_4B,
33 #endif
34 #ifdef CONFIG_MF_CLASSIC_1K_SUPPORT
35  CONFIG_MF_CLASSIC_1K,
36 #endif
37 #ifdef CONFIG_MF_CLASSIC_1K_7B_SUPPORT
38  CONFIG_MF_CLASSIC_1K_7B,
39 #endif
40 #ifdef CONFIG_MF_CLASSIC_4K_SUPPORT
41  CONFIG_MF_CLASSIC_4K,
42 #endif
43 #ifdef CONFIG_MF_CLASSIC_4K_7B_SUPPORT
44  CONFIG_MF_CLASSIC_4K_7B,
45 #endif
46 #ifdef CONFIG_ISO14443A_SNIFF_SUPPORT
47  CONFIG_ISO14443A_SNIFF,
48 #endif
49 #ifdef CONFIG_ISO14443A_READER_SUPPORT
50  CONFIG_ISO14443A_READER,
51 #endif
52 #ifdef CONFIG_NTAG215_SUPPORT
53  CONFIG_NTAG215,
54 #endif
55 #ifdef CONFIG_VICINITY_SUPPORT
56  CONFIG_VICINITY,
57 #endif
58 #ifdef CONFIG_ISO15693_SNIFF_SUPPORT
59  CONFIG_ISO15693_SNIFF,
60 #endif
61 #ifdef CONFIG_SL2S2002_SUPPORT
62  CONFIG_SL2S2002,
63 #endif
64 #ifdef CONFIG_TITAGITSTANDARD_SUPPORT
65  CONFIG_TITAGITSTANDARD,
66 #endif
67 #ifdef CONFIG_TITAGITPLUS_SUPPORT
68  CONFIG_TITAGITPLUS,
69 #endif
70 #ifdef CONFIG_EM4233_SUPPORT
71  CONFIG_EM4233,
72 #endif
73 #ifdef CONFIG_MF_DESFIRE_SUPPORT
74  CONFIG_MF_DESFIRE,
75 #endif
76  /* This HAS to be the last element */
77  CONFIG_COUNT
78 } ConfigurationEnum;
79 
81 #define TAG_FAMILY_NONE 0
82 #define TAG_FAMILY_ISO14443A 1
83 #define TAG_FAMILY_ISO14443B 2
84 #define TAG_FAMILY_ISO15693 5
85 
86 
88 typedef struct {
96  void (*CodecInitFunc)(void);
98  void (*CodecDeInitFunc)(void);
102  void (*CodecTaskFunc)(void);
114  void (*ApplicationInitFunc)(void);
116  void (*ApplicationResetFunc)(void);
118  void (*ApplicationTaskFunc)(void);
120  void (*ApplicationTickFunc)(void);
132  uint16_t (*ApplicationProcessFunc)(uint8_t *ByteBuffer, uint16_t BitCount);
137  void (*ApplicationGetUidFunc)(ConfigurationUidType Uid);
142  void (*ApplicationSetUidFunc)(ConfigurationUidType Uid);
153  uint16_t MemorySize;
159  uint8_t UidSize;
163  bool ReadOnly;
167  uint8_t TagFamily;
168 
170 
171 extern ConfigurationType ActiveConfiguration;
172 
173 void ConfigurationInit(void);
174 void ConfigurationSetById(ConfigurationEnum Configuration);
175 MapIdType ConfigurationCheckByName(const char *Configuration);
176 void ConfigurationGetByName(char *Configuration, uint16_t BufferSize);
177 bool ConfigurationSetByName(const char *Configuration);
178 void ConfigurationGetList(char *ConfigurationList, uint16_t BufferSize);
179 
180 #endif /* STANDARDS_H_ */
uint8_t TagFamily
Definition: Configuration.h:167
+
uint16_t MemorySize
Definition: Configuration.h:153
+
Definition: Configuration.h:88
+
bool ReadOnly
Definition: Configuration.h:163
+
uint8_t UidSize
Definition: Configuration.h:159
diff --git a/Doc/Doxygen/html/_configurations_8txt.html b/Doc/Doxygen/html/_configurations_8txt.html index a1efd1d3..c4b5f05e 100644 --- a/Doc/Doxygen/html/_configurations_8txt.html +++ b/Doc/Doxygen/html/_configurations_8txt.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: Configurations.txt File Reference @@ -11,9 +12,6 @@ - @@ -31,40 +29,19 @@
- + - - + + + +
diff --git a/Doc/Doxygen/html/_crypto1_8h_source.html b/Doc/Doxygen/html/_crypto1_8h_source.html index 39140379..7548cdf2 100644 --- a/Doc/Doxygen/html/_crypto1_8h_source.html +++ b/Doc/Doxygen/html/_crypto1_8h_source.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: Crypto1.h Source File @@ -11,9 +12,6 @@ - @@ -31,40 +29,19 @@
- + - - + + + +
1 #ifndef CRYPTO1_H
2 #define CRYPTO1_H
3 
4 #include <stdint.h>
5 #include <stdbool.h>
6 
7 void Crypto1GetState(uint8_t *pEven, uint8_t *pOdd);
8 
9 /* Gets the current keystream-bit, without shifting the internal LFSR */
10 uint8_t Crypto1FilterOutput(void);
11 
12 /* Set up Crypto1 cipher using the given Key, Uid and CardNonce. Also encrypts
13  * the CardNonce in-place while in non-linear mode. */
14 void Crypto1Setup(uint8_t Key[6], uint8_t Uid[4], uint8_t CardNonce[4]);
15 /* Same for nested auth. CardNonce[4]..[7] will contain the parity bits after return */
16 void Crypto1SetupNested(uint8_t Key[6], uint8_t Uid[4], uint8_t CardNonce[8], bool Decrypt);
17 
18 /* Load the decrypted ReaderNonce into the Crypto1 state LFSR */
19 void Crypto1Auth(uint8_t EncryptedReaderNonce[4]);
20 
21 /* Generate 8 Bits of key stream */
22 uint8_t Crypto1Byte(void);
23 
24 /* Encrypt/Decrypt array */
25 void Crypto1ByteArray(uint8_t *Buffer, uint8_t Count);
26 void Crypto1ByteArrayWithParity(uint8_t *Buffer, uint8_t Count);
27 
28 /* Generate 4 Bits of key stream */
29 uint8_t Crypto1Nibble(void);
30 
31 /* Execute 'ClockCount' cycles on the PRNG state 'State' */
32 void Crypto1PRNG(uint8_t State[4], uint8_t ClockCount);
33 
34 /* Encrypts buffer with consideration of parity bits */
35 void Crypto1EncryptWithParity(uint8_t *Buffer, uint8_t BitCount);
36 
37 /* Encrypts buffer with LFSR feedback within reader nonce and considers parity bits */
38 void Crypto1ReaderAuthWithParity(uint8_t PlainReaderAnswerWithParityBits[9]);
39 
40 #endif //CRYPTO1_H
diff --git a/Doc/Doxygen/html/_crypto_a_e_s128_8h_source.html b/Doc/Doxygen/html/_crypto_a_e_s128_8h_source.html index e791b69b..17a2f7f0 100644 --- a/Doc/Doxygen/html/_crypto_a_e_s128_8h_source.html +++ b/Doc/Doxygen/html/_crypto_a_e_s128_8h_source.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: CryptoAES128.h Source File @@ -11,9 +12,6 @@ - @@ -31,40 +29,19 @@ - + - - + + + +
CryptoAES128.h
-
1 /* CryptoAES128.h : Adds support for XMega HW accelerated 128-bit AES encryption
2  * in ECB and CBC modes.
3  * Based in part on the the source code for Microchip's ASF library
4  * available at https://github.com/avrxml/asf (see license below).
5  * Author: Maxie D. Schmidt (@maxieds)
6  */
7 
8 /*****************************************************************************
9  * Copyright (c) 2014-2018 Microchip Technology Inc. and its subsidiaries.
10  *
11  * Subject to your compliance with these terms, you may use Microchip
12  * software and any derivatives exclusively with Microchip products.
13  * It is your responsibility to comply with third party license terms applicable
14  * to your use of third party software (including open source software) that
15  * may accompany Microchip software.
16  *
17  * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
18  * WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
19  * INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
20  * AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
21  * LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
22  * LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
23  * SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
24  * POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
25  * ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
26  * RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
27  * THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
28  *****************************************************************************/
29 
30 #ifndef __CRYPTO_AES128_HW_H__
31 #define __CRYPTO_AES128_HW_H__
32 
33 #include <avr/io.h>
34 
35 /* AES Processing mode */
36 #define CRYPTO_AES_PMODE_DECIPHER 0 // decipher
37 #define CRYPTO_AES_PMODE_ENCIPHER 1 // cipher
38 
39 /* AES Start mode */
40 #define CRYPTO_AES_START_MODE_MANUAL 0 // Manual mode
41 #define CRYPTO_AES_START_MODE_AUTO 1 // Auto mode
42 #define CRYPTO_AES_START_MODE_DMA 2 // DMA mode
43 
44 /* AES Cryptographic key size */
45 #define CRYPTO_AES_KEY_SIZE_128 0 // 128-bit
46 #define CRYPTO_AES_KEY_SIZE_192 1 // 192-bit
47 #define CRYPTO_AES_KEY_SIZE_256 2 // 256-bit
48 
49 /* AES Operation cipher mode */
50 #define CRYPTO_AES_ECB_MODE 0 // Electronic Code Book mode
51 #define CRYPTO_AES_CBC_MODE 1 // Cipher Block Chaining mode
52 #define CRYPTO_AES_OFB_MODE 2 // Output FeedBack mode
53 #define CRYPTO_AES_CFB_MODE 3 // Cipher FeedBack mode
54 #define CRYPTO_AES_CTR_MODE 4 // Counter mode
55 
56 /* AES URAD Type */
57 #define CRYPTO_AES_URAT_INPUTWRITE_DMA 0 // Input Data Register written during the data processing in DMA mode
58 #define CRYPTO_AES_URAT_OUTPUTREAD_PROCESS 1 // Output Data Register read during the data processing
59 #define CRYPTO_AES_URAT_MRWRITE_PROCESS 2 // Mode Register written during the data processing
60 #define CRYPTO_AES_URAT_OUTPUTREAD_SUBKEY 3 // Output Data Register read during the sub-keys generation
61 #define CRYPTO_AES_URAT_MRWRITE_SUBKEY 4 // Mode Register written during the sub-keys generation
62 #define CRYPTO_AES_URAT_READ_WRITEONLY 5 // Write-only register read access
63 
64 /* Define types for the AES-128 specific implementation: */
65 #define CRYPTO_AES_KEY_SIZE 16
66 typedef uint8_t CryptoAESKey_t[CRYPTO_AES_KEY_SIZE];
67 
68 #define CRYPTO_AES_BLOCK_SIZE 16
69 typedef uint8_t CryptoAESBlock_t[CRYPTO_AES_BLOCK_SIZE];
70 
71 #define CryptoAESBytesToBlocks(byteCount) \
72  ((byteCount + CRYPTO_AES_BLOCK_SIZE - 1) / CRYPTO_AES_BLOCK_SIZE)
73 
74 typedef enum aes_dec {
75  AES_ENCRYPT,
76  AES_DECRYPT = AES_DECRYPT_bm,
77 } CryptoAESDec_t;
78 
79 /* AES Auto Start Trigger settings */
80 typedef enum aes_auto {
81  AES_MANUAL, // manual start mode.
82  AES_AUTO = AES_AUTO_bm, // auto start mode.
83 } CryptoAESAuto_t;
84 
85 /* AES State XOR Load Enable settings */
86 typedef enum aes_xor {
87  AES_XOR_OFF, // state direct load.
88  AES_XOR_ON = AES_XOR_bm, // state XOR load.
89 } CryptoAESXor_t;
90 
91 /* AES Interrupt Enable / Level settings */
92 typedef enum aes_intlvl {
93  AES_INTLVL_OFF = AES_INTLVL_OFF_gc, // Interrupt Disabled
94  AES_INTLVL_LO = AES_INTLVL_LO_gc, // Low Level
95  AES_INTLVL_MED = AES_INTLVL_MED_gc, // Medium Level
96  AES_INTLVL_HI = AES_INTLVL_HI_gc, // High Level
97 } CryptoAESIntlvl_t;
98 
99 /* AES interrupt callback function pointer. */
100 typedef void (*aes_callback_t)(void);
101 
102 typedef struct {
103  CryptoAESDec_t ProcessingMode;
104  uint8_t ProcessingDelay; // [0,15]
105  CryptoAESAuto_t StartMode;
106  unsigned char OpMode; // 0 = ECB, 1 = CBC, 2 = OFB, 3 = CFB, 4 = CTR
107  CryptoAESXor_t XorMode;
108 } CryptoAESConfig_t;
109 
110 typedef struct {
111  unsigned char datrdy; // ENABLE/DISABLE; Data ready interrupt
112  unsigned char urad; // ENABLE/DISABLE; Unspecified Register Access Detection
113 } CryptoAES_ISRConfig_t;
114 
115 /* AES encryption complete. */
116 #define AES_ENCRYPTION_COMPLETE (1UL << 0)
117 
118 /* AES GF multiplication complete. */
119 #define AES_GF_MULTI_COMPLETE (1UL << 1)
120 
121 void aes_start(void);
122 void aes_software_reset(void);
123 bool aes_is_busy(void);
124 bool aes_is_error(void);
125 void aes_clear_interrupt_flag(void);
126 void aes_clear_error_flag(void);
127 void aes_configure(CryptoAESDec_t op_mode, CryptoAESAuto_t auto_start, CryptoAESXor_t xor_mode);
128 void aes_configure_encrypt(CryptoAESAuto_t auto_start, CryptoAESXor_t xor_mode);
129 void aes_configure_decrypt(CryptoAESAuto_t auto_start, CryptoAESXor_t xor_mode);
130 void aes_set_key(uint8_t *key_in);
131 void aes_get_key(uint8_t *key_out);
132 void aes_write_inputdata(uint8_t *data_in);
133 void aes_read_outputdata(uint8_t *data_out);
134 void aes_isr_configure(CryptoAESIntlvl_t intlvl);
135 void aes_set_callback(const aes_callback_t callback);
136 
137 void CryptoAESGetConfigDefaults(CryptoAESConfig_t *ctx);
138 void CryptoAESInitContext(CryptoAESConfig_t *ctx);
139 uint16_t CryptoAESGetPaddedBufferSize(uint16_t bufSize);
140 
141 void CryptoAESEncryptBlock(uint8_t *Plaintext, uint8_t *Ciphertext, const uint8_t *Key, bool);
142 void CryptoAESDecryptBlock(uint8_t *Plaintext, uint8_t *Ciphertext, const uint8_t *Key);
143 uint8_t CryptoAESEncryptBuffer(uint16_t Count, uint8_t *Plaintext, uint8_t *Ciphertext,
144  const uint8_t *IV, const uint8_t *Key);
145 uint8_t CryptoAESDecryptBuffer(uint16_t Count, uint8_t *Plaintext, uint8_t *Ciphertext,
146  const uint8_t *IV, const uint8_t *Key);
147 
148 typedef uint8_t (*CryptoAESFuncType)(uint8_t*, uint8_t*, uint8_t*);
149 typedef struct {
150  CryptoAESFuncType cryptFunc;
151  uint16_t blockSize;
152 } CryptoAES_CBCSpec_t;
153 
154 void CryptoAES_CBCSend(uint16_t Count, void* Plaintext, void* Ciphertext,
155  uint8_t *IV, uint8_t *Key,
156  CryptoAES_CBCSpec_t CryptoSpec);
157 void CryptoAES_CBCRecv(uint16_t Count, void* Plaintext, void* Ciphertext,
158  uint8_t *IV, uint8_t *Key,
159  CryptoAES_CBCSpec_t CryptoSpec);
160 
161 void CryptoAESEncrypt_CBCSend(uint16_t Count, uint8_t *PlainText, uint8_t *CipherText,
162  uint8_t *Key, uint8_t *IV);
163 void CryptoAESDecrypt_CBCSend(uint16_t Count, uint8_t *PlainText, uint8_t *CipherText,
164  uint8_t *Key, uint8_t *IV);
165 void CryptoAESEncrypt_CBCReceive(uint16_t Count, uint8_t *PlainText, uint8_t *CipherText,
166  uint8_t *Key, uint8_t *IV);
167 void CryptoAESDecrypt_CBCReceive(uint16_t Count, uint8_t *PlainText, uint8_t *CipherText,
168  uint8_t *Key, uint8_t *IV);
169 
170 /* Crypto utility functions: */
171 #define CRYPTO_BYTES_TO_BLOCKS(numBytes, blockSize) \
172  ( ((numBytes) + (blockSize) - 1) / (blockSize) )
173 
174 #define CryptoMemoryXOR(inputBuf, destBuf, bufSize) ({ \
175  uint8_t *in = (uint8_t *) inputBuf; \
176  uint8_t *out = (uint8_t *) destBuf; \
177  uint16_t count = (uint16_t) bufSize; \
178  while(count-- > 0) { \
179  *(out++) ^= *(in++); \
180  } \
181  })
182 
183 #endif
+
1 /* CryptoAES128.h : Adds support for XMega HW accelerated 128-bit AES encryption
2  * in ECB and CBC modes.
3  * Based in part on the the source code for Microchip's ASF library
4  * available at https://github.com/avrxml/asf (see license below).
5  * Author: Maxie D. Schmidt (@maxieds)
6  */
7 
8 /*****************************************************************************
9  * Copyright (c) 2014-2018 Microchip Technology Inc. and its subsidiaries.
10  *
11  * Subject to your compliance with these terms, you may use Microchip
12  * software and any derivatives exclusively with Microchip products.
13  * It is your responsibility to comply with third party license terms applicable
14  * to your use of third party software (including open source software) that
15  * may accompany Microchip software.
16  *
17  * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
18  * WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
19  * INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
20  * AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
21  * LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
22  * LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
23  * SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
24  * POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
25  * ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
26  * RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
27  * THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
28  *****************************************************************************/
29 
30 #ifndef __CRYPTO_AES128_HW_H__
31 #define __CRYPTO_AES128_HW_H__
32 
33 #include <avr/io.h>
34 
35 /* AES Processing mode */
36 #define CRYPTO_AES_PMODE_DECIPHER 0 // decipher
37 #define CRYPTO_AES_PMODE_ENCIPHER 1 // cipher
38 
39 /* AES Start mode */
40 #define CRYPTO_AES_START_MODE_MANUAL 0 // Manual mode
41 #define CRYPTO_AES_START_MODE_AUTO 1 // Auto mode
42 #define CRYPTO_AES_START_MODE_DMA 2 // DMA mode
43 
44 /* AES Cryptographic key size */
45 #define CRYPTO_AES_KEY_SIZE_128 0 // 128-bit
46 #define CRYPTO_AES_KEY_SIZE_192 1 // 192-bit
47 #define CRYPTO_AES_KEY_SIZE_256 2 // 256-bit
48 
49 /* AES Operation cipher mode */
50 #define CRYPTO_AES_ECB_MODE 0 // Electronic Code Book mode
51 #define CRYPTO_AES_CBC_MODE 1 // Cipher Block Chaining mode
52 #define CRYPTO_AES_OFB_MODE 2 // Output FeedBack mode
53 #define CRYPTO_AES_CFB_MODE 3 // Cipher FeedBack mode
54 #define CRYPTO_AES_CTR_MODE 4 // Counter mode
55 
56 /* AES URAD Type */
57 #define CRYPTO_AES_URAT_INPUTWRITE_DMA 0 // Input Data Register written during the data processing in DMA mode
58 #define CRYPTO_AES_URAT_OUTPUTREAD_PROCESS 1 // Output Data Register read during the data processing
59 #define CRYPTO_AES_URAT_MRWRITE_PROCESS 2 // Mode Register written during the data processing
60 #define CRYPTO_AES_URAT_OUTPUTREAD_SUBKEY 3 // Output Data Register read during the sub-keys generation
61 #define CRYPTO_AES_URAT_MRWRITE_SUBKEY 4 // Mode Register written during the sub-keys generation
62 #define CRYPTO_AES_URAT_READ_WRITEONLY 5 // Write-only register read access
63 
64 /* Define types for the AES-128 specific implementation: */
65 #define CRYPTO_AES_KEY_SIZE 16
66 typedef uint8_t CryptoAESKey_t[CRYPTO_AES_KEY_SIZE];
67 
68 #define CRYPTO_AES_BLOCK_SIZE 16
69 typedef uint8_t CryptoAESBlock_t[CRYPTO_AES_BLOCK_SIZE];
70 
71 #define CryptoAESBytesToBlocks(byteCount) \
72  ((byteCount + CRYPTO_AES_BLOCK_SIZE - 1) / CRYPTO_AES_BLOCK_SIZE)
73 
74 typedef enum aes_dec {
75  AES_ENCRYPT,
76  AES_DECRYPT = AES_DECRYPT_bm,
77 } CryptoAESDec_t;
78 
79 /* AES Auto Start Trigger settings */
80 typedef enum aes_auto {
81  AES_MANUAL, // manual start mode.
82  AES_AUTO = AES_AUTO_bm, // auto start mode.
83 } CryptoAESAuto_t;
84 
85 /* AES State XOR Load Enable settings */
86 typedef enum aes_xor {
87  AES_XOR_OFF, // state direct load.
88  AES_XOR_ON = AES_XOR_bm, // state XOR load.
89 } CryptoAESXor_t;
90 
91 /* AES Interrupt Enable / Level settings */
92 typedef enum aes_intlvl {
93  AES_INTLVL_OFF = AES_INTLVL_OFF_gc, // Interrupt Disabled
94  AES_INTLVL_LO = AES_INTLVL_LO_gc, // Low Level
95  AES_INTLVL_MED = AES_INTLVL_MED_gc, // Medium Level
96  AES_INTLVL_HI = AES_INTLVL_HI_gc, // High Level
97 } CryptoAESIntlvl_t;
98 
99 /* AES interrupt callback function pointer. */
100 typedef void (*aes_callback_t)(void);
101 
102 typedef struct {
103  CryptoAESDec_t ProcessingMode;
104  uint8_t ProcessingDelay; // [0,15]
105  CryptoAESAuto_t StartMode;
106  unsigned char OpMode; // 0 = ECB, 1 = CBC, 2 = OFB, 3 = CFB, 4 = CTR
107  CryptoAESXor_t XorMode;
108 } CryptoAESConfig_t;
109 
110 typedef struct {
111  unsigned char datrdy; // ENABLE/DISABLE; Data ready interrupt
112  unsigned char urad; // ENABLE/DISABLE; Unspecified Register Access Detection
113 } CryptoAES_ISRConfig_t;
114 
115 /* AES encryption complete. */
116 #define AES_ENCRYPTION_COMPLETE (1UL << 0)
117 
118 /* AES GF multiplication complete. */
119 #define AES_GF_MULTI_COMPLETE (1UL << 1)
120 
121 void aes_start(void);
122 void aes_software_reset(void);
123 bool aes_is_busy(void);
124 bool aes_is_error(void);
125 void aes_clear_interrupt_flag(void);
126 void aes_clear_error_flag(void);
127 void aes_configure(CryptoAESDec_t op_mode, CryptoAESAuto_t auto_start, CryptoAESXor_t xor_mode);
128 void aes_configure_encrypt(CryptoAESAuto_t auto_start, CryptoAESXor_t xor_mode);
129 void aes_configure_decrypt(CryptoAESAuto_t auto_start, CryptoAESXor_t xor_mode);
130 void aes_set_key(uint8_t *key_in);
131 void aes_get_key(uint8_t *key_out);
132 void aes_write_inputdata(uint8_t *data_in);
133 void aes_read_outputdata(uint8_t *data_out);
134 void aes_isr_configure(CryptoAESIntlvl_t intlvl);
135 void aes_set_callback(const aes_callback_t callback);
136 
137 void CryptoAESGetConfigDefaults(CryptoAESConfig_t *ctx);
138 void CryptoAESInitContext(CryptoAESConfig_t *ctx);
139 uint16_t CryptoAESGetPaddedBufferSize(uint16_t bufSize);
140 
141 void CryptoAESEncryptBlock(uint8_t *Plaintext, uint8_t *Ciphertext, const uint8_t *Key, bool);
142 void CryptoAESDecryptBlock(uint8_t *Plaintext, uint8_t *Ciphertext, const uint8_t *Key);
143 uint8_t CryptoAESEncryptBuffer(uint16_t Count, uint8_t *Plaintext, uint8_t *Ciphertext,
144  const uint8_t *IV, const uint8_t *Key);
145 uint8_t CryptoAESDecryptBuffer(uint16_t Count, uint8_t *Plaintext, uint8_t *Ciphertext,
146  const uint8_t *IV, const uint8_t *Key);
147 
148 typedef uint8_t (*CryptoAESFuncType)(uint8_t *, uint8_t *, uint8_t *);
149 typedef struct {
150  CryptoAESFuncType cryptFunc;
151  uint16_t blockSize;
152 } CryptoAES_CBCSpec_t;
153 
154 void CryptoAES_CBCSend(uint16_t Count, void *Plaintext, void *Ciphertext,
155  uint8_t *IV, uint8_t *Key,
156  CryptoAES_CBCSpec_t CryptoSpec);
157 void CryptoAES_CBCRecv(uint16_t Count, void *Plaintext, void *Ciphertext,
158  uint8_t *IV, uint8_t *Key,
159  CryptoAES_CBCSpec_t CryptoSpec);
160 
161 void CryptoAESEncrypt_CBCSend(uint16_t Count, uint8_t *PlainText, uint8_t *CipherText,
162  uint8_t *Key, uint8_t *IV);
163 void CryptoAESDecrypt_CBCSend(uint16_t Count, uint8_t *PlainText, uint8_t *CipherText,
164  uint8_t *Key, uint8_t *IV);
165 void CryptoAESEncrypt_CBCReceive(uint16_t Count, uint8_t *PlainText, uint8_t *CipherText,
166  uint8_t *Key, uint8_t *IV);
167 void CryptoAESDecrypt_CBCReceive(uint16_t Count, uint8_t *PlainText, uint8_t *CipherText,
168  uint8_t *Key, uint8_t *IV);
169 
170 /* Crypto utility functions: */
171 #define CRYPTO_BYTES_TO_BLOCKS(numBytes, blockSize) \
172  ( ((numBytes) + (blockSize) - 1) / (blockSize) )
173 
174 #define CryptoMemoryXOR(inputBuf, destBuf, bufSize) ({ \
175  uint8_t *in = (uint8_t *) inputBuf; \
176  uint8_t *out = (uint8_t *) destBuf; \
177  uint16_t count = (uint16_t) bufSize; \
178  while(count-- > 0) { \
179  *(out++) ^= *(in++); \
180  } \
181  })
182 
183 #endif
diff --git a/Doc/Doxygen/html/_crypto_t_d_e_a_8h_source.html b/Doc/Doxygen/html/_crypto_t_d_e_a_8h_source.html index 7835677e..4a4b8a95 100644 --- a/Doc/Doxygen/html/_crypto_t_d_e_a_8h_source.html +++ b/Doc/Doxygen/html/_crypto_t_d_e_a_8h_source.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: CryptoTDEA.h Source File @@ -11,9 +12,6 @@ - @@ -31,40 +29,19 @@ - + - - + + + +
CryptoTDEA.h
-
1 /*
2  * CryptoDES.h
3  *
4  * Created on: 18.10.2016
5  * Author: dev_zzo
6  */
7 
8 #ifndef CRYPTODES_H_
9 #define CRYPTODES_H_
10 
11 #include <stdint.h>
12 #include "../Common.h"
13 
14 /* Notes on cryptography in DESFire cards
15 
16 The EV0 was the first chip in the DESFire series. It makes use of the TDEA
17 encryption to secure the comms. It also employs CBC to make things more secure.
18 
19 CBC is used in two "modes": "send mode" and "receive mode".
20 - Sending data uses the same structure as conventional encryption with CBC
21  (XOR with the IV then apply block cipher)
22 - Receiving data uses the same structure as conventional decryption with CBC
23  (apply block cipher then XOR with the IV)
24 
25 Both operations employ TDEA encryption on the PICC's side and decryption on
26 PCD's side.
27 
28 */
29 
30 /* Key sizes, in bytes */
31 #define CRYPTO_DES_KEY_SIZE 8 /* Bytes */
32 #define CRYPTO_2KTDEA_KEY_SIZE (CRYPTO_DES_KEY_SIZE * 2)
33 #define CRYPTO_3KTDEA_KEY_SIZE (CRYPTO_DES_KEY_SIZE * 3)
34 
35 typedef uint8_t Crypto2KTDEAKeyType[CRYPTO_2KTDEA_KEY_SIZE];
36 typedef uint8_t Crypto3KTDEAKeyType[CRYPTO_3KTDEA_KEY_SIZE];
37 
38 #define CRYPTO_DES_BLOCK_SIZE 8 /* Bytes */
39 #define CRYPTO_2KTDEA_BLOCK_SIZE (CRYPTO_DES_BLOCK_SIZE)
40 #define CRYPTO_3KTDEA_BLOCK_SIZE (CRYPTO_DES_BLOCK_SIZE)
41 
42 /* Prototype the CBC function pointer in case anyone needs it */
43 typedef void (*CryptoTDEACBCFuncType)(uint16_t Count, const void *Plaintext, void *Ciphertext, void *IV, const uint8_t *Keys);
44 typedef void (*CryptoTDEAFuncType)(const void *PlainText, void *Ciphertext, const uint8_t *Keys);
45 
46 void CryptoEncryptDEA(void *Plaintext, void *Ciphertext, const uint8_t *Keys);
47 void CryptoDecryptDEA(void *Plaintext, void *Ciphertext, const uint8_t *Keys);
48 void EncryptDESBuffer(uint16_t Count, const void* Plaintext, void* Ciphertext, const uint8_t* Keys);
49 void DecryptDESBuffer(uint16_t Count, void* Plaintext, const void* Ciphertext, const uint8_t* Keys);
50 
57 void CryptoEncrypt2KTDEA(const void *Plaintext, void *Ciphertext, const uint8_t *Keys);
58 void CryptoDecrypt2KTDEA(const void *Plaintext, void *Ciphertext, const uint8_t *Keys);
59 
60 void CryptoEncrypt3KTDEA(void* Plaintext, void* Ciphertext, const uint8_t* Keys);
61 void CryptoDecrypt3KTDEA(void* Plaintext, void* Ciphertext, const uint8_t* Keys);
62 
63 void Encrypt3DESBuffer(uint16_t Count, const void* Plaintext, void* Ciphertext, const uint8_t* Keys);
64 void Decrypt3DESBuffer(uint16_t Count, void* Plaintext, const void* Ciphertext, const uint8_t* Keys);
65 
66 
75 void CryptoEncrypt2KTDEA_CBCSend(uint16_t Count, const void *Input, void *Output, void *IV, const uint8_t *Keys);
76 void CryptoDecrypt2KTDEA_CBCSend(uint16_t Count, const void *Input, void *Output, void *IV, const uint8_t *Keys);
77 
86 void CryptoEncrypt2KTDEA_CBCReceive(uint16_t Count, const void *Input, void *Output, void *IV, const uint8_t *Keys);
87 void CryptoDecrypt2KTDEA_CBCReceive(uint16_t Count, const void *Input, void *Output, void *IV, const uint8_t *Keys);
88 
89 
98 void CryptoEncrypt3KTDEA_CBCSend(uint16_t Count, const void *Plaintext, void *Ciphertext, void *IV, const uint8_t *Keys);
99 void CryptoDecrypt3KTDEA_CBCReceive(uint16_t Count, const void *Plaintext, void *Ciphertext, void *IV, const uint8_t *Keys);
100 
101 /* Spec for more generic send/recv encrypt/decrypt schemes: */
102 typedef struct {
103  CryptoTDEAFuncType cryptFunc;
104  uint16_t blockSize;
105 } CryptoTDEA_CBCSpec;
106 
107 void CryptoTDEA_CBCSend(uint16_t Count, void* Plaintext, void* Ciphertext,
108  void *IV, const uint8_t* Keys, CryptoTDEA_CBCSpec CryptoSpec);
109 void CryptoTDEA_CBCRecv(uint16_t Count, void* Plaintext, void* Ciphertext,
110  void *IV, const uint8_t* Keys, CryptoTDEA_CBCSpec CryptoSpec);
111 
112 uint8_t TransferEncryptTDEASend(uint8_t *Buffer, uint8_t Count);
113 uint8_t TransferEncryptTDEAReceive(uint8_t *Buffer, uint8_t Count);
114 
121 INLINE void CryptoPaddingTDEA(uint8_t *Buffer, uint8_t BytesInBuffer, bool FirstPaddingBitSet) {
122  uint8_t PaddingByte = FirstPaddingBitSet << 7;
123  uint8_t i;
124 
125  for (i = BytesInBuffer; i < CRYPTO_DES_BLOCK_SIZE; ++i) {
126  Buffer[i] = PaddingByte;
127  PaddingByte = 0x00;
128  }
129 }
130 
131 #endif /* CRYPTODES_H_ */
+
1 /*
2  * CryptoDES.h
3  *
4  * Created on: 18.10.2016
5  * Author: dev_zzo
6  */
7 
8 #ifndef CRYPTODES_H_
9 #define CRYPTODES_H_
10 
11 #include <stdint.h>
12 #include "../Common.h"
13 
14 /* Notes on cryptography in DESFire cards
15 
16 The EV0 was the first chip in the DESFire series. It makes use of the TDEA
17 encryption to secure the comms. It also employs CBC to make things more secure.
18 
19 CBC is used in two "modes": "send mode" and "receive mode".
20 - Sending data uses the same structure as conventional encryption with CBC
21  (XOR with the IV then apply block cipher)
22 - Receiving data uses the same structure as conventional decryption with CBC
23  (apply block cipher then XOR with the IV)
24 
25 Both operations employ TDEA encryption on the PICC's side and decryption on
26 PCD's side.
27 
28 */
29 
30 /* Key sizes, in bytes */
31 #define CRYPTO_DES_KEY_SIZE 8 /* Bytes */
32 #define CRYPTO_2KTDEA_KEY_SIZE (CRYPTO_DES_KEY_SIZE * 2)
33 #define CRYPTO_3KTDEA_KEY_SIZE (CRYPTO_DES_KEY_SIZE * 3)
34 
35 typedef uint8_t Crypto2KTDEAKeyType[CRYPTO_2KTDEA_KEY_SIZE];
36 typedef uint8_t Crypto3KTDEAKeyType[CRYPTO_3KTDEA_KEY_SIZE];
37 
38 #define CRYPTO_DES_BLOCK_SIZE 8 /* Bytes */
39 #define CRYPTO_2KTDEA_BLOCK_SIZE (CRYPTO_DES_BLOCK_SIZE)
40 #define CRYPTO_3KTDEA_BLOCK_SIZE (CRYPTO_DES_BLOCK_SIZE)
41 
42 /* Prototype the CBC function pointer in case anyone needs it */
43 typedef void (*CryptoTDEACBCFuncType)(uint16_t Count, const void *Plaintext, void *Ciphertext, void *IV, const uint8_t *Keys);
44 typedef void (*CryptoTDEAFuncType)(const void *PlainText, void *Ciphertext, const uint8_t *Keys);
45 
46 void CryptoEncryptDEA(void *Plaintext, void *Ciphertext, const uint8_t *Keys);
47 void CryptoDecryptDEA(void *Plaintext, void *Ciphertext, const uint8_t *Keys);
48 void EncryptDESBuffer(uint16_t Count, const void *Plaintext, void *Ciphertext, const uint8_t *Keys);
49 void DecryptDESBuffer(uint16_t Count, void *Plaintext, const void *Ciphertext, const uint8_t *Keys);
50 
57 void CryptoEncrypt2KTDEA(const void *Plaintext, void *Ciphertext, const uint8_t *Keys);
58 void CryptoDecrypt2KTDEA(const void *Plaintext, void *Ciphertext, const uint8_t *Keys);
59 
60 void CryptoEncrypt3KTDEA(void *Plaintext, void *Ciphertext, const uint8_t *Keys);
61 void CryptoDecrypt3KTDEA(void *Plaintext, void *Ciphertext, const uint8_t *Keys);
62 
63 void Encrypt3DESBuffer(uint16_t Count, const void *Plaintext, void *Ciphertext, const uint8_t *Keys);
64 void Decrypt3DESBuffer(uint16_t Count, void *Plaintext, const void *Ciphertext, const uint8_t *Keys);
65 
66 
75 void CryptoEncrypt2KTDEA_CBCSend(uint16_t Count, const void *Input, void *Output, void *IV, const uint8_t *Keys);
76 void CryptoDecrypt2KTDEA_CBCSend(uint16_t Count, const void *Input, void *Output, void *IV, const uint8_t *Keys);
77 
86 void CryptoEncrypt2KTDEA_CBCReceive(uint16_t Count, const void *Input, void *Output, void *IV, const uint8_t *Keys);
87 void CryptoDecrypt2KTDEA_CBCReceive(uint16_t Count, const void *Input, void *Output, void *IV, const uint8_t *Keys);
88 
89 
98 void CryptoEncrypt3KTDEA_CBCSend(uint16_t Count, const void *Plaintext, void *Ciphertext, void *IV, const uint8_t *Keys);
99 void CryptoDecrypt3KTDEA_CBCReceive(uint16_t Count, const void *Plaintext, void *Ciphertext, void *IV, const uint8_t *Keys);
100 
101 /* Spec for more generic send/recv encrypt/decrypt schemes: */
102 typedef struct {
103  CryptoTDEAFuncType cryptFunc;
104  uint16_t blockSize;
105 } CryptoTDEA_CBCSpec;
106 
107 void CryptoTDEA_CBCSend(uint16_t Count, void *Plaintext, void *Ciphertext,
108  void *IV, const uint8_t *Keys, CryptoTDEA_CBCSpec CryptoSpec);
109 void CryptoTDEA_CBCRecv(uint16_t Count, void *Plaintext, void *Ciphertext,
110  void *IV, const uint8_t *Keys, CryptoTDEA_CBCSpec CryptoSpec);
111 
112 uint8_t TransferEncryptTDEASend(uint8_t *Buffer, uint8_t Count);
113 uint8_t TransferEncryptTDEAReceive(uint8_t *Buffer, uint8_t Count);
114 
121 INLINE void CryptoPaddingTDEA(uint8_t *Buffer, uint8_t BytesInBuffer, bool FirstPaddingBitSet) {
122  uint8_t PaddingByte = FirstPaddingBitSet << 7;
123  uint8_t i;
124 
125  for (i = BytesInBuffer; i < CRYPTO_DES_BLOCK_SIZE; ++i) {
126  Buffer[i] = PaddingByte;
127  PaddingByte = 0x00;
128  }
129 }
130 
131 #endif /* CRYPTODES_H_ */
diff --git a/Doc/Doxygen/html/_crypto_tests_8h_source.html b/Doc/Doxygen/html/_crypto_tests_8h_source.html index f4e420ff..48676907 100644 --- a/Doc/Doxygen/html/_crypto_tests_8h_source.html +++ b/Doc/Doxygen/html/_crypto_tests_8h_source.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: CryptoTests.h Source File @@ -11,9 +12,6 @@ - @@ -31,40 +29,19 @@ - + - - + + + +
CryptoTests.h
-
1 /* CryptoTests.h */
2 
3 #ifdef ENABLE_CRYPTO_TESTS
4 
5 #ifndef __CRYPTO_TESTS_H__
6 #define __CRYPTO_TESTS_H__
7 
8 #include "../Common.h"
9 #include "../Terminal/Terminal.h"
10 #include "../Application/CryptoTDEA.h"
11 #include "../Application/CryptoAES128.h"
12 
13 #include <stdlib.h>
14 #include <string.h>
15 #include <inttypes.h>
16 #include <stdbool.h>
17 
18 /* DES crypto test cases: */
19 
20 /* Test 2KTDEA encryption, ECB mode: */
21 bool CryptoTDEATestCase1(char *OutParam, uint16_t MaxOutputLength);
22 
23 /* Test 2KTDEA encryption, CBC receive mode: */
24 bool CryptoTDEATestCase2(char *OutParam, uint16_t MaxOutputLength);
25 
26 /* AES-128 crypto test cases: */
27 
28 /* Test AES-128 encrypt/decrypt for a single block (ECB mode): */
29 bool CryptoAESTestCase1(char *OutParam, uint16_t MaxOutputLength);
30 
31 /* Test AES-128 encrypt/decrypt for a single-block buffer (CBC mode, with an IV) -- Version 1:
32  * Adapted from: https://github.com/eewiki/asf/blob/master/xmega/drivers/aes/example2/aes_example2.c
33  */
34 bool CryptoAESTestCase2(char *OutParam, uint16_t MaxOutputLength);
35 
36 #endif /* __CRYPTO_TESTS_H__ */
37 
38 #endif /* ENABLE_CRYPTO_TESTS */
+
1 /* CryptoTests.h */
2 
3 #ifdef ENABLE_CRYPTO_TESTS
4 
5 #ifndef __CRYPTO_TESTS_H__
6 #define __CRYPTO_TESTS_H__
7 
8 #include "../Common.h"
9 #include "../Terminal/Terminal.h"
10 #include "../Application/CryptoTDEA.h"
11 #include "../Application/CryptoAES128.h"
12 
13 #include <stdlib.h>
14 #include <string.h>
15 #include <inttypes.h>
16 #include <stdbool.h>
17 
18 /* DES crypto test cases: */
19 
20 /* Test 2KTDEA encryption, ECB mode: */
21 bool CryptoTDEATestCase1(char *OutParam, uint16_t MaxOutputLength);
22 
23 /* Test 2KTDEA encryption, CBC receive mode: */
24 bool CryptoTDEATestCase2(char *OutParam, uint16_t MaxOutputLength);
25 
26 /* AES-128 crypto test cases: */
27 
28 /* Test AES-128 encrypt/decrypt for a single block (ECB mode): */
29 bool CryptoAESTestCase1(char *OutParam, uint16_t MaxOutputLength);
30 
31 /* Test AES-128 encrypt/decrypt for a single-block buffer (CBC mode, with an IV) -- Version 1:
32  * Adapted from: https://github.com/eewiki/asf/blob/master/xmega/drivers/aes/example2/aes_example2.c
33  */
34 bool CryptoAESTestCase2(char *OutParam, uint16_t MaxOutputLength);
35 
36 #endif /* __CRYPTO_TESTS_H__ */
37 
38 #endif /* ENABLE_CRYPTO_TESTS */
diff --git a/Doc/Doxygen/html/_d_e_s_fire_application_directory_8h_source.html b/Doc/Doxygen/html/_d_e_s_fire_application_directory_8h_source.html index d64db97c..2f5bb549 100644 --- a/Doc/Doxygen/html/_d_e_s_fire_application_directory_8h_source.html +++ b/Doc/Doxygen/html/_d_e_s_fire_application_directory_8h_source.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: DESFireApplicationDirectory.h Source File @@ -11,9 +12,6 @@ - @@ -31,40 +29,19 @@ - + - - + + + +
DESFireApplicationDirectory.h
-
1 /*
2 The DESFire stack portion of this firmware source
3 is free software written by Maxie Dion Schmidt (@maxieds):
4 You can redistribute it and/or modify
5 it under the terms of this license.
6 
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 
11 The complete source distribution of
12 this firmware is available at the following link:
13 https://github.com/maxieds/ChameleonMiniFirmwareDESFireStack.
14 
15 Based in part on the original DESFire code created by
16 @dev-zzo (GitHub handle) [Dmitry Janushkevich] available at
17 https://github.com/dev-zzo/ChameleonMini/tree/desfire.
18 
19 This notice must be retained at the top of all source files where indicated.
20 */
21 
22 /*
23  * DESFireApplicationDirectory.h :
24  * Maxie D. Schmidt (github.com/maxieds)
25  */
26 
27 #ifndef __DESFIRE_DFAPPDIR_H__
28 #define __DESFIRE_DFAPPDIR_H__
29 
30 #include "DESFireFirmwareSettings.h"
31 #include "DESFirePICCHeaderLayout.h"
32 #include "DESFireInstructions.h"
33 #include "DESFireFile.h"
34 
35 #define DESFIRE_MAX_FILES_EV0 16
36 #define DESFIRE_MAX_FILES_EV1 32
37 
38 #if defined(DESFIRE_MEMORY_LIMITED_TESTING) && !defined(DESFIRE_CUSTOM_MAX_APPS)
39  #define DESFIRE_MAX_APPS (6)
40 #elif defined(DESFIRE_CUSTOM_MAX_APPS)
41  #define DESFIRE_MAX_APPS (DESFIRE_CUSTOM_MAX_APPS)
42 #else
43  #define DESFIRE_MAX_APPS (28)
44 #endif
45 
46 #define DESFIRE_MAX_SLOTS (DESFIRE_MAX_APPS + 1)
47 
48 #if defined(DESFIRE_MEMORY_LIMITED_TESTING) && !defined(DESFIRE_CUSTOM_MAX_FILES)
49  #define DESFIRE_MAX_FILES (6)
50 #elif defined(DESFIRE_CUSTOM_MAX_FILES)
51  #define DESFIRE_MAX_FILES (DESFIRE_CUSTOM_MAX_FILES)
52 #else
53  #define DESFIRE_MAX_FILES (DESFIRE_MAX_FILES_EV1)
54 #endif
55 
56 #if defined(DESFIRE_MEMORY_LIMITED_TESTING) && !defined(DESFIRE_CUSTOM_MAX_KEYS)
57  #define DESFIRE_MAX_KEYS (4)
58 #elif defined(DESFIRE_CUSTOM_MAX_KEYS)
59  #define DESFIRE_MAX_KEYS (DESFIRE_CUSTOM_MAX_KEYS)
60 #else
61  #define DESFIRE_MAX_KEYS (14)
62 #endif
63 
64 #ifdef DESFIRE_USE_FACTORY_SIZES
65  #undef DESFIRE_CUSTOM_MAX_APPS
66  #define DESFIRE_CUSTOM_MAX_APPS (28)
67  #undef DESFIRE_CUSTOM_MAX_KEYS
68  #define DESFIRE_CUSTOM_MAX_KEYS (14)
69  #undef DESFIRE_CUSTOM_MAX_FILES
70  #define DESFIRE_CUSTOM_MAX_FILES (DESFIRE_MAX_FILES_EV1)
71 #elif defined(DESFIRE_MAXIMIZE_SIZES_FOR_STORAGE)
72  #undef DESFIRE_CUSTOM_MAX_APPS
73  #define DESFIRE_CUSTOM_MAX_APPS (DESFIRE_EEPROM_BLOCK_SIZE - 1)
74  #undef DESFIRE_CUSTOM_MAX_KEYS
75  #define DESFIRE_CUSTOM_MAX_KEYS (DESFIRE_EEPROM_BLOCK_SIZE)
76  #undef DESFIRE_CUSTOM_MAX_FILES
77  #define DESFIRE_CUSTOM_MAX_FILES (DESFIRE_EEPROM_BLOCK_SIZE)
78 #endif
79 
80 /* Mifare DESFire EV1 Application crypto operations */
81 #define APPLICATION_CRYPTO_DES 0x00
82 #define APPLICATION_CRYPTO_3K3DES 0x40
83 #define APPLICATION_CRYPTO_AES 0x80
84 
85 /* Define application directory identifiers: */
86 #define MAX_AID_SIZE (12)
87 #define DESFIRE_AID_SIZE (3)
88 
89 typedef BYTE DESFireAidType[DESFIRE_AID_SIZE];
90 
91 /*
92  * Defines the application directory contents.
93  * The application directory maps AIDs to application slots:
94  * the AID's index in `AppIds` is the slot number.
95  *
96  * This is the "global" structure that gets stored in the header
97  * data for the directory. To see the actual byte-for-byte storage
98  * of the accounting data for each instantiated AID slot, refer to the
99  * `DesfireApplicationDataType` structure from above.
100  */
101 typedef struct DESFIRE_FIRMWARE_PACKING {
102  BYTE FirstFreeSlot;
103  DESFireAidType AppIds[DESFIRE_MAX_SLOTS] DESFIRE_FIRMWARE_ARRAY_ALIGNAT;
104  SIZET AppCacheStructBlockOffset[DESFIRE_MAX_SLOTS];
105 } DESFireAppDirType;
106 
107 #define DESFIRE_APP_DIR_BLOCKS DESFIRE_BYTES_TO_BLOCKS(sizeof(DESFireAppDirType))
108 
109 /* Global card structure support routines */
110 void SynchronizeAppDir(void);
111 void SynchronizePICCInfo(void);
112 
113 /* PICC / Application master key settings */
114 /* Mifare DESFire master key settings
115  bit 7 - 4: Always 0.
116  bit 3: PICC master key settings frozen = 0 (WARNING - this is irreversible);
117  PICC master key settings changeable when authenticated with PICC master key = 1
118  bit 2: PICC master key authentication required for creating or deleting applications = 0;
119  Authentication not required = 1
120  bit 1: PICC master key authentication required for listing of applications or
121  reading key settings = 0;
122  Free listing of applications and reading key settings = 1
123  bit 0: PICC master key frozen (reversible with configuration change or when formatting card) = 0;
124  PICC master key changeable = 1
125 */
126 #define DESFIRE_ALLOW_MASTER_KEY_CHANGE (0x01) //(1 << 0)
127 #define DESFIRE_FREE_DIRECTORY_LIST (0x02) //(1 << 1)
128 #define DESFIRE_FREE_CREATE_DELETE (0x04) //(1 << 2)
129 #define DESFIRE_ALLOW_CONFIG_CHANGE (0x08) //(1 << 3)
130 #define DESFIRE_USE_TARGET_KEY 0xE
131 #define DESFIRE_ALL_KEYS_FROZEN 0xF
132 
133 /* PICC master key (PMK) settings for application creation / deletion
134  * (see page 34 of the datasheet)
135  */
136 BYTE PMKConfigurationChangeable(void);
137 BYTE PMKRequiredForAppCreateDelete(void);
138 BYTE PMKFreeDirectoryListing(void);
139 BYTE PMKAllowChangingKey(void);
140 
141 /* Application master key (AMK)
142  * (see page 35 of the datasheet)
143  */
144 BYTE AMKConfigurationChangeable(void);
145 BYTE AMKRequiredForFileCreateDelete(void);
146 BYTE AMKFreeDirectoryListing(void);
147 BYTE AMKAllowChangingKey(void);
148 BYTE AMKRequiredToChangeKeys(void);
149 BYTE AMKGetRequiredKeyToChangeKeys(void);
150 BYTE AMKRequireCurrentKeyToChangeKey(void);
151 BYTE AMKAllKeysFrozen(void);
152 
153 /* Application data management */
154 SIZET GetAppProperty(DesfireCardLayout propId, BYTE AppSlot);
155 void SetAppProperty(DesfireCardLayout propId, BYTE AppSlot, SIZET Value);
156 
157 /* Application key management */
158 bool KeyIdValid(uint8_t AppSlot, uint8_t KeyId);
159 BYTE ReadMaxKeyCount(uint8_t AppSlot);
160 BYTE ReadKeyCount(uint8_t AppSlot);
161 void WriteKeyCount(uint8_t AppSlot, BYTE KeyCount);
162 BYTE ReadKeySettings(uint8_t AppSlot, uint8_t KeyId);
163 void WriteKeySettings(uint8_t AppSlot, uint8_t KeyId, BYTE Value);
164 BYTE ReadKeyVersion(uint8_t AppSlot, uint8_t KeyId);
165 void WriteKeyVersion(uint8_t AppSlot, uint8_t KeyId, BYTE Value);
166 BYTE ReadKeyCryptoType(uint8_t AppSlot, uint8_t KeyId);
167 void WriteKeyCryptoType(uint8_t AppSlot, uint8_t KeyId, BYTE Value);
168 SIZET ReadKeyStorageAddress(uint8_t AppSlot);
169 void WriteKeyStorageAddress(uint8_t AppSlot, SIZET Value);
170 void ReadAppKey(uint8_t AppSlot, uint8_t KeyId, uint8_t *Key, SIZET KeySize);
171 void WriteAppKey(uint8_t AppSlot, uint8_t KeyId, const uint8_t *Key, SIZET KeySize);
172 
173 /* Application file management */
174 BYTE ReadFileCount(uint8_t AppSlot);
175 void WriteFileCount(uint8_t AppSlot, BYTE FileCount);
176 BYTE LookupFileNumberIndex(uint8_t AppSlot, BYTE FileNumber);
177 BYTE LookupFileNumberByIndex(uint8_t AppSlot, BYTE FileIndex);
178 BYTE LookupNextFreeFileSlot(uint8_t AppSlot);
179 void WriteFileNumberAtIndex(uint8_t AppSlot, uint8_t FileIndex, BYTE FileNumber);
180 SIZET ReadFileDataStructAddress(uint8_t AppSlot, uint8_t FileIndex);
181 uint8_t ReadFileType(uint8_t AppSlot, uint8_t FileIndex);
182 uint16_t ReadDataFileSize(uint8_t AppSlot, uint8_t FileIndex);
183 BYTE ReadFileCommSettings(uint8_t AppSlot, uint8_t FileIndex);
184 void WriteFileCommSettings(uint8_t AppSlot, uint8_t FileIndex, BYTE CommSettings);
185 SIZET ReadFileAccessRights(uint8_t AppSlot, uint8_t FileIndex);
186 void WriteFileAccessRights(uint8_t AppSlot, uint8_t FileIndex, SIZET AccessRights);
187 DESFireFileTypeSettings ReadFileSettings(uint8_t AppSlot, uint8_t FileIndex);
188 void WriteFileSettings(uint8_t AppSlot, uint8_t FileIndex, DESFireFileTypeSettings *FileSettings);
189 
190 /* Application selection */
191 uint8_t LookupAppSlot(const DESFireAidType Aid);
192 void SelectAppBySlot(uint8_t AppSlot);
193 bool GetAppData(uint8_t appSlot, SelectedAppCacheType *destData);
194 uint16_t SelectApp(const DESFireAidType Aid);
195 void SelectPiccApp(void);
196 bool IsPiccAppSelected(void);
197 
198 /* Application management */
199 uint16_t CreateApp(const DESFireAidType Aid, uint8_t KeyCount, uint8_t KeySettings);
200 uint16_t DeleteApp(const DESFireAidType Aid);
201 void GetApplicationIdsSetup(void);
202 TransferStatus GetApplicationIdsTransfer(uint8_t *Buffer);
203 uint16_t GetApplicationIdsIterator(uint8_t *Buffer, uint16_t ByteCount);
204 
205 #endif
+
1 /*
2 The DESFire stack portion of this firmware source
3 is free software written by Maxie Dion Schmidt (@maxieds):
4 You can redistribute it and/or modify
5 it under the terms of this license.
6 
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 
11 The complete source distribution of
12 this firmware is available at the following link:
13 https://github.com/maxieds/ChameleonMiniFirmwareDESFireStack.
14 
15 Based in part on the original DESFire code created by
16 @dev-zzo (GitHub handle) [Dmitry Janushkevich] available at
17 https://github.com/dev-zzo/ChameleonMini/tree/desfire.
18 
19 This notice must be retained at the top of all source files where indicated.
20 */
21 
22 /*
23  * DESFireApplicationDirectory.h :
24  * Maxie D. Schmidt (github.com/maxieds)
25  */
26 
27 #ifndef __DESFIRE_DFAPPDIR_H__
28 #define __DESFIRE_DFAPPDIR_H__
29 
30 #include "DESFireFirmwareSettings.h"
31 #include "DESFirePICCHeaderLayout.h"
32 #include "DESFireInstructions.h"
33 #include "DESFireFile.h"
34 
35 #define DESFIRE_MAX_FILES_EV0 16
36 #define DESFIRE_MAX_FILES_EV1 32
37 
38 #if defined(DESFIRE_MEMORY_LIMITED_TESTING) && !defined(DESFIRE_CUSTOM_MAX_APPS)
39 #define DESFIRE_MAX_APPS (6)
40 #elif defined(DESFIRE_CUSTOM_MAX_APPS)
41 #define DESFIRE_MAX_APPS (DESFIRE_CUSTOM_MAX_APPS)
42 #else
43 #define DESFIRE_MAX_APPS (28)
44 #endif
45 
46 #define DESFIRE_MAX_SLOTS (DESFIRE_MAX_APPS + 1)
47 
48 #if defined(DESFIRE_MEMORY_LIMITED_TESTING) && !defined(DESFIRE_CUSTOM_MAX_FILES)
49 #define DESFIRE_MAX_FILES (6)
50 #elif defined(DESFIRE_CUSTOM_MAX_FILES)
51 #define DESFIRE_MAX_FILES (DESFIRE_CUSTOM_MAX_FILES)
52 #else
53 #define DESFIRE_MAX_FILES (DESFIRE_MAX_FILES_EV1)
54 #endif
55 
56 #if defined(DESFIRE_MEMORY_LIMITED_TESTING) && !defined(DESFIRE_CUSTOM_MAX_KEYS)
57 #define DESFIRE_MAX_KEYS (4)
58 #elif defined(DESFIRE_CUSTOM_MAX_KEYS)
59 #define DESFIRE_MAX_KEYS (DESFIRE_CUSTOM_MAX_KEYS)
60 #else
61 #define DESFIRE_MAX_KEYS (14)
62 #endif
63 
64 #ifdef DESFIRE_USE_FACTORY_SIZES
65 #undef DESFIRE_CUSTOM_MAX_APPS
66 #define DESFIRE_CUSTOM_MAX_APPS (28)
67 #undef DESFIRE_CUSTOM_MAX_KEYS
68 #define DESFIRE_CUSTOM_MAX_KEYS (14)
69 #undef DESFIRE_CUSTOM_MAX_FILES
70 #define DESFIRE_CUSTOM_MAX_FILES (DESFIRE_MAX_FILES_EV1)
71 #elif defined(DESFIRE_MAXIMIZE_SIZES_FOR_STORAGE)
72 #undef DESFIRE_CUSTOM_MAX_APPS
73 #define DESFIRE_CUSTOM_MAX_APPS (DESFIRE_EEPROM_BLOCK_SIZE - 1)
74 #undef DESFIRE_CUSTOM_MAX_KEYS
75 #define DESFIRE_CUSTOM_MAX_KEYS (DESFIRE_EEPROM_BLOCK_SIZE)
76 #undef DESFIRE_CUSTOM_MAX_FILES
77 #define DESFIRE_CUSTOM_MAX_FILES (DESFIRE_EEPROM_BLOCK_SIZE)
78 #endif
79 
80 /* Mifare DESFire EV1 Application crypto operations */
81 #define APPLICATION_CRYPTO_DES 0x00
82 #define APPLICATION_CRYPTO_3K3DES 0x40
83 #define APPLICATION_CRYPTO_AES 0x80
84 
85 /* Define application directory identifiers: */
86 #define MAX_AID_SIZE (12)
87 #define DESFIRE_AID_SIZE (3)
88 
89 typedef BYTE DESFireAidType[DESFIRE_AID_SIZE];
90 
91 /*
92  * Defines the application directory contents.
93  * The application directory maps AIDs to application slots:
94  * the AID's index in `AppIds` is the slot number.
95  *
96  * This is the "global" structure that gets stored in the header
97  * data for the directory. To see the actual byte-for-byte storage
98  * of the accounting data for each instantiated AID slot, refer to the
99  * `DesfireApplicationDataType` structure from above.
100  */
101 typedef struct DESFIRE_FIRMWARE_PACKING {
102  BYTE FirstFreeSlot;
103  DESFireAidType AppIds[DESFIRE_MAX_SLOTS] DESFIRE_FIRMWARE_ARRAY_ALIGNAT;
104  SIZET AppCacheStructBlockOffset[DESFIRE_MAX_SLOTS];
105 } DESFireAppDirType;
106 
107 #define DESFIRE_APP_DIR_BLOCKS DESFIRE_BYTES_TO_BLOCKS(sizeof(DESFireAppDirType))
108 
109 /* Global card structure support routines */
110 void SynchronizeAppDir(void);
111 void SynchronizePICCInfo(void);
112 
113 /* PICC / Application master key settings */
114 /* Mifare DESFire master key settings
115  bit 7 - 4: Always 0.
116  bit 3: PICC master key settings frozen = 0 (WARNING - this is irreversible);
117  PICC master key settings changeable when authenticated with PICC master key = 1
118  bit 2: PICC master key authentication required for creating or deleting applications = 0;
119  Authentication not required = 1
120  bit 1: PICC master key authentication required for listing of applications or
121  reading key settings = 0;
122  Free listing of applications and reading key settings = 1
123  bit 0: PICC master key frozen (reversible with configuration change or when formatting card) = 0;
124  PICC master key changeable = 1
125 */
126 #define DESFIRE_ALLOW_MASTER_KEY_CHANGE (0x01) //(1 << 0)
127 #define DESFIRE_FREE_DIRECTORY_LIST (0x02) //(1 << 1)
128 #define DESFIRE_FREE_CREATE_DELETE (0x04) //(1 << 2)
129 #define DESFIRE_ALLOW_CONFIG_CHANGE (0x08) //(1 << 3)
130 #define DESFIRE_USE_TARGET_KEY 0xE
131 #define DESFIRE_ALL_KEYS_FROZEN 0xF
132 
133 /* PICC master key (PMK) settings for application creation / deletion
134  * (see page 34 of the datasheet)
135  */
136 BYTE PMKConfigurationChangeable(void);
137 BYTE PMKRequiredForAppCreateDelete(void);
138 BYTE PMKFreeDirectoryListing(void);
139 BYTE PMKAllowChangingKey(void);
140 
141 /* Application master key (AMK)
142  * (see page 35 of the datasheet)
143  */
144 BYTE AMKConfigurationChangeable(void);
145 BYTE AMKRequiredForFileCreateDelete(void);
146 BYTE AMKFreeDirectoryListing(void);
147 BYTE AMKAllowChangingKey(void);
148 BYTE AMKRequiredToChangeKeys(void);
149 BYTE AMKGetRequiredKeyToChangeKeys(void);
150 BYTE AMKRequireCurrentKeyToChangeKey(void);
151 BYTE AMKAllKeysFrozen(void);
152 
153 /* Application data management */
154 SIZET GetAppProperty(DesfireCardLayout propId, BYTE AppSlot);
155 void SetAppProperty(DesfireCardLayout propId, BYTE AppSlot, SIZET Value);
156 
157 /* Application key management */
158 bool KeyIdValid(uint8_t AppSlot, uint8_t KeyId);
159 BYTE ReadMaxKeyCount(uint8_t AppSlot);
160 BYTE ReadKeyCount(uint8_t AppSlot);
161 void WriteKeyCount(uint8_t AppSlot, BYTE KeyCount);
162 BYTE ReadKeySettings(uint8_t AppSlot, uint8_t KeyId);
163 void WriteKeySettings(uint8_t AppSlot, uint8_t KeyId, BYTE Value);
164 BYTE ReadKeyVersion(uint8_t AppSlot, uint8_t KeyId);
165 void WriteKeyVersion(uint8_t AppSlot, uint8_t KeyId, BYTE Value);
166 BYTE ReadKeyCryptoType(uint8_t AppSlot, uint8_t KeyId);
167 void WriteKeyCryptoType(uint8_t AppSlot, uint8_t KeyId, BYTE Value);
168 SIZET ReadKeyStorageAddress(uint8_t AppSlot);
169 void WriteKeyStorageAddress(uint8_t AppSlot, SIZET Value);
170 void ReadAppKey(uint8_t AppSlot, uint8_t KeyId, uint8_t *Key, SIZET KeySize);
171 void WriteAppKey(uint8_t AppSlot, uint8_t KeyId, const uint8_t *Key, SIZET KeySize);
172 
173 /* Application file management */
174 BYTE ReadFileCount(uint8_t AppSlot);
175 void WriteFileCount(uint8_t AppSlot, BYTE FileCount);
176 BYTE LookupFileNumberIndex(uint8_t AppSlot, BYTE FileNumber);
177 BYTE LookupFileNumberByIndex(uint8_t AppSlot, BYTE FileIndex);
178 BYTE LookupNextFreeFileSlot(uint8_t AppSlot);
179 void WriteFileNumberAtIndex(uint8_t AppSlot, uint8_t FileIndex, BYTE FileNumber);
180 SIZET ReadFileDataStructAddress(uint8_t AppSlot, uint8_t FileIndex);
181 uint8_t ReadFileType(uint8_t AppSlot, uint8_t FileIndex);
182 uint16_t ReadDataFileSize(uint8_t AppSlot, uint8_t FileIndex);
183 BYTE ReadFileCommSettings(uint8_t AppSlot, uint8_t FileIndex);
184 void WriteFileCommSettings(uint8_t AppSlot, uint8_t FileIndex, BYTE CommSettings);
185 SIZET ReadFileAccessRights(uint8_t AppSlot, uint8_t FileIndex);
186 void WriteFileAccessRights(uint8_t AppSlot, uint8_t FileIndex, SIZET AccessRights);
187 DESFireFileTypeSettings ReadFileSettings(uint8_t AppSlot, uint8_t FileIndex);
188 void WriteFileSettings(uint8_t AppSlot, uint8_t FileIndex, DESFireFileTypeSettings *FileSettings);
189 
190 /* Application selection */
191 uint8_t LookupAppSlot(const DESFireAidType Aid);
192 void SelectAppBySlot(uint8_t AppSlot);
193 bool GetAppData(uint8_t appSlot, SelectedAppCacheType *destData);
194 uint16_t SelectApp(const DESFireAidType Aid);
195 void SelectPiccApp(void);
196 bool IsPiccAppSelected(void);
197 
198 /* Application management */
199 uint16_t CreateApp(const DESFireAidType Aid, uint8_t KeyCount, uint8_t KeySettings);
200 uint16_t DeleteApp(const DESFireAidType Aid);
201 void GetApplicationIdsSetup(void);
202 TransferStatus GetApplicationIdsTransfer(uint8_t *Buffer);
203 uint16_t GetApplicationIdsIterator(uint8_t *Buffer, uint16_t ByteCount);
204 
205 #endif
diff --git a/Doc/Doxygen/html/_d_e_s_fire_chameleon_terminal_8h_source.html b/Doc/Doxygen/html/_d_e_s_fire_chameleon_terminal_8h_source.html index c78babdd..553a5da5 100644 --- a/Doc/Doxygen/html/_d_e_s_fire_chameleon_terminal_8h_source.html +++ b/Doc/Doxygen/html/_d_e_s_fire_chameleon_terminal_8h_source.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: DESFireChameleonTerminal.h Source File @@ -11,9 +12,6 @@ - @@ -31,40 +29,19 @@ - + - - + + + +
DESFireChameleonTerminal.h
-
1 /*
2 The DESFire stack portion of this firmware source
3 is free software written by Maxie Dion Schmidt (@maxieds):
4 You can redistribute it and/or modify
5 it under the terms of this license.
6 
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 
11 The complete source distribution of
12 this firmware is available at the following link:
13 https://github.com/maxieds/ChameleonMiniFirmwareDESFireStack.
14 
15 Based in part on the original DESFire code created by
16 @dev-zzo (GitHub handle) [Dmitry Janushkevich] available at
17 https://github.com/dev-zzo/ChameleonMini/tree/desfire.
18 
19 This notice must be retained at the top of all source files where indicated.
20 */
21 
22 /*
23  * DESFireChameleonTerminal.h
24  * Maxie D. Schmidt (github.com/maxieds)
25  */
26 
27 #ifndef __DESFIRE_CHAMELEON_TERMINAL_H__
28 #define __DESFIRE_CHAMELEON_TERMINAL_H__
29 
30 #if defined(CONFIG_MF_DESFIRE_SUPPORT) && !defined(DISABLE_DESFIRE_TERMINAL_COMMANDS)
31 
32 #include <stdbool.h>
33 
34 #include "../../Terminal/Commands.h"
35 #include "../../Terminal/CommandLine.h"
36 
37 bool IsDESFireConfiguration(void);
38 
39 #ifndef DISABLE_PERMISSIVE_DESFIRE_SETTINGS
40 #define DFCOMMAND_SET_HEADER "DF_SETHDR"
41 CommandStatusIdType CommandDESFireGetHeaderProperty(char *OutParam);
42 CommandStatusIdType CommandDESFireSetHeaderProperty(char *OutMessage, const char *InParams);
43 #endif
44 
45 #define DFCOMMAND_LAYOUT_PPRINT "DF_PPRINT_PICC"
46 CommandStatusIdType CommandDESFireLayoutPPrint(char *OutParam, const char *InParams);
47 
48 #define DFCOMMAND_FIRMWARE_INFO "DF_FWINFO"
49 CommandStatusIdType CommandDESFireFirmwareInfo(char *OutParam);
50 
51 #define DFCOMMAND_LOGGING_MODE "DF_LOGMODE"
52 CommandStatusIdType CommandDESFireGetLoggingMode(char *OutParam);
53 CommandStatusIdType CommandDESFireSetLoggingMode(char *OutMessage, const char *InParams);
54 
55 #define DFCOMMAND_TESTING_MODE "DF_TESTMODE"
56 CommandStatusIdType CommandDESFireGetTestingMode(char *OutParam);
57 CommandStatusIdType CommandDESFireSetTestingMode(char *OutMessage, const char *InParams);
58 
59 #endif
60 
61 #endif
+
1 /*
2 The DESFire stack portion of this firmware source
3 is free software written by Maxie Dion Schmidt (@maxieds):
4 You can redistribute it and/or modify
5 it under the terms of this license.
6 
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 
11 The complete source distribution of
12 this firmware is available at the following link:
13 https://github.com/maxieds/ChameleonMiniFirmwareDESFireStack.
14 
15 Based in part on the original DESFire code created by
16 @dev-zzo (GitHub handle) [Dmitry Janushkevich] available at
17 https://github.com/dev-zzo/ChameleonMini/tree/desfire.
18 
19 This notice must be retained at the top of all source files where indicated.
20 */
21 
22 /*
23  * DESFireChameleonTerminal.h
24  * Maxie D. Schmidt (github.com/maxieds)
25  */
26 
27 #ifndef __DESFIRE_CHAMELEON_TERMINAL_H__
28 #define __DESFIRE_CHAMELEON_TERMINAL_H__
29 
30 #if defined(CONFIG_MF_DESFIRE_SUPPORT) && !defined(DISABLE_DESFIRE_TERMINAL_COMMANDS)
31 
32 #include <stdbool.h>
33 
34 #include "../../Terminal/Commands.h"
35 #include "../../Terminal/CommandLine.h"
36 
37 bool IsDESFireConfiguration(void);
38 
39 #ifndef DISABLE_PERMISSIVE_DESFIRE_SETTINGS
40 #define DFCOMMAND_SET_HEADER "DF_SETHDR"
41 CommandStatusIdType CommandDESFireGetHeaderProperty(char *OutParam);
42 CommandStatusIdType CommandDESFireSetHeaderProperty(char *OutMessage, const char *InParams);
43 #endif
44 
45 #define DFCOMMAND_LAYOUT_PPRINT "DF_PPRINT_PICC"
46 CommandStatusIdType CommandDESFireLayoutPPrint(char *OutParam, const char *InParams);
47 
48 #define DFCOMMAND_FIRMWARE_INFO "DF_FWINFO"
49 CommandStatusIdType CommandDESFireFirmwareInfo(char *OutParam);
50 
51 #define DFCOMMAND_LOGGING_MODE "DF_LOGMODE"
52 CommandStatusIdType CommandDESFireGetLoggingMode(char *OutParam);
53 CommandStatusIdType CommandDESFireSetLoggingMode(char *OutMessage, const char *InParams);
54 
55 #define DFCOMMAND_TESTING_MODE "DF_TESTMODE"
56 CommandStatusIdType CommandDESFireGetTestingMode(char *OutParam);
57 CommandStatusIdType CommandDESFireSetTestingMode(char *OutMessage, const char *InParams);
58 
59 #endif
60 
61 #endif
diff --git a/Doc/Doxygen/html/_d_e_s_fire_crypto_8h_source.html b/Doc/Doxygen/html/_d_e_s_fire_crypto_8h_source.html index a98c08b1..c2b1e8a3 100644 --- a/Doc/Doxygen/html/_d_e_s_fire_crypto_8h_source.html +++ b/Doc/Doxygen/html/_d_e_s_fire_crypto_8h_source.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: DESFireCrypto.h Source File @@ -11,9 +12,6 @@ - @@ -31,40 +29,19 @@ - + - - + + + +
DESFireCrypto.h
-
1 /*
2 The DESFire stack portion of this firmware source
3 is free software written by Maxie Dion Schmidt (@maxieds):
4 You can redistribute it and/or modify
5 it under the terms of this license.
6 
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 
11 The complete source distribution of
12 this firmware is available at the following link:
13 https://github.com/maxieds/ChameleonMiniFirmwareDESFireStack.
14 
15 Based in part on the original DESFire code created by
16 @dev-zzo (GitHub handle) [Dmitry Janushkevich] available at
17 https://github.com/dev-zzo/ChameleonMini/tree/desfire.
18 
19 This notice must be retained at the top of all source files where indicated.
20 */
21 
22 /*
23  * DESFireCrypto.h
24  * Maxie D. Schmidt (github.com/maxieds)
25  */
26 
27 #ifndef __DESFIRE_CRYPTO_H__
28 #define __DESFIRE_CRYPTO_H__
29 
30 #include "../../Common.h"
31 
32 #include "DESFireFirmwareSettings.h"
33 
34 /* Communication modes:
35  * Define the modes of communication over the RFID channel
36  *
37  * Note there is also an AES wrapped COMMS variant called
38  * LRP Secure Messaging detailed starting on page 37
39  * (Section 7.2) of
40  * https://www.nxp.com/docs/en/application-note/AN12343.pdf
41  */
42 #define DESFIRE_COMMS_PLAINTEXT (0x00)
43 #define DESFIRE_COMMS_PLAINTEXT_MAC (0x01)
44 #define DESFIRE_COMMS_CIPHERTEXT_DES (0x03)
45 #define DESFIRE_COMMS_CIPHERTEXT_AES128 (0x04)
46 #define DESFIRE_DEFAULT_COMMS_STANDARD (DESFIRE_COMMS_PLAINTEXT)
47 
48 #define CRYPTO_TYPE_ANY (0x00)
49 #define CRYPTO_TYPE_DES (0x01)
50 #define CRYPTO_TYPE_2KTDEA (0x0A)
51 #define CRYPTO_TYPE_3K3DES (0x1A)
52 #define CRYPTO_TYPE_AES128 (0x4A)
53 
54 #define CryptoTypeDES(ct) \
55  ((ct == CRYPTO_TYPE_DES) || (ct == CRYPTO_TYPE_ANY))
56 #define CryptoType2KTDEA(ct) \
57  ((ct == CRYPTO_TYPE_2KTDEA) || (ct == CRYPTO_TYPE_ANY))
58 #define CryptoType3KTDEA(ct) \
59  ((ct == CRYPTO_TYPE_3K3DES) || (ct == CRYPTO_TYPE_ANY))
60 #define CryptoTypeAES(ct) \
61  ((ct == CRYPTO_TYPE_AES128) || (ct == CRYPTO_TYPE_ANY))
62 
63 /* Key sizes, block sizes (in bytes): */
64 #define CRYPTO_AES_KEY_SIZE (16)
65 #define CRYPTO_MAX_KEY_SIZE (24)
66 #define CRYPTO_MAX_BLOCK_SIZE (16)
67 #define DESFIRE_AES_IV_SIZE (CRYPTO_AES_BLOCK_SIZE)
68 #define DESFIRE_SESSION_KEY_SIZE (CRYPTO_3KTDEA_KEY_SIZE)
69 #define CRYPTO_CHALLENGE_RESPONSE_BYTES (8)
70 
71 typedef BYTE CryptoKeyBufferType[CRYPTO_MAX_KEY_SIZE];
72 typedef BYTE CryptoIVBufferType[CRYPTO_MAX_BLOCK_SIZE];
73 
74 extern CryptoKeyBufferType SessionKey;
75 extern CryptoIVBufferType SessionIV;
76 extern BYTE SessionIVByteSize;
77 
78 extern uint8_t Authenticated;
79 extern uint8_t AuthenticatedWithKey;
80 extern uint8_t AuthenticatedWithPICCMasterKey;
81 extern uint8_t CryptoAuthMethod;
82 extern uint8_t ActiveCommMode;
83 
84 /* Need to invalidate the authentication state after:
85  * 1) Selecting a new application;
86  * 2) Changing the active key used in the authentication;
87  * 3) A failed authentication;
88  */
89 void InvalidateAuthState(BYTE keepPICCAuthData);
90 bool IsAuthenticated(void);
91 
92 BYTE GetDefaultCryptoMethodKeySize(uint8_t cryptoType);
93 BYTE GetCryptoMethodCommSettings(uint8_t cryptoType);
94 const char * GetCryptoMethodDesc(uint8_t cryptoType);
95 const char * GetCommSettingsDesc(uint8_t cryptoType);
96 
97 #define DESFIRE_MAC_LENGTH 4
98 #define DESFIRE_CMAC_LENGTH 8 // in bytes
99 
100 /* Authentication status */
101 #define DESFIRE_NOT_AUTHENTICATED 0xFF
102 
103 typedef enum DESFIRE_FIRMWARE_ENUM_PACKING {
104  DESFIRE_AUTH_LEGACY,
105  DESFIRE_AUTH_ISO_2KTDEA,
106  DESFIRE_AUTH_ISO_3KTDEA,
107  DESFIRE_AUTH_AES,
108 } DesfireAuthType;
109 
110 BYTE GetCryptoKeyTypeFromAuthenticateMethod(BYTE authCmdMethod);
111 
112 #define CryptoBitsToBytes(cryptoBits) \
113  (cryptoBits / BITS_PER_BYTE)
114 
115 /*********************************************************
116  * AES (128) crypto routines:
117  *********************************************************/
118 
119 #include "../CryptoAES128.h"
120 
121 typedef uint8_t DesfireAESCryptoKey[CRYPTO_AES_KEY_SIZE];
122 
123 extern CryptoAESConfig_t AESCryptoContext;
124 extern DesfireAESCryptoKey AESCryptoSessionKey;
125 extern DesfireAESCryptoKey AESCryptoIVBuffer;
126 
127 void InitAESCryptoKeyData(DesfireAESCryptoKey *cryptoKeyData);
128 
129 typedef void (*CryptoAESCBCFuncType)(uint16_t, void*, void*, uint8_t*, uint8_t*);
130 
131 typedef uint8_t (*CryptoTransferSendFunc)(uint8_t*, uint8_t);
132 typedef uint8_t (*CryptoTransferReceiveFunc)(uint8_t*, uint8_t);
133 uint8_t CryptoAESTransferEncryptSend(uint8_t *Buffer, uint8_t Count, const uint8_t *Key);
134 uint8_t CryptoAESTransferEncryptReceive(uint8_t *Buffer, uint8_t Count, const uint8_t *Key);
135 
136 #define DESFIRE_MAX_PAYLOAD_AES_BLOCKS (DESFIRE_MAX_PAYLOAD_SIZE / CRYPTO_AES_BLOCK_SIZE)
137 
138 /*********************************************************
139  * TripleDES crypto routines:
140  *********************************************************/
141 
142 #include "../CryptoTDEA.h"
143 
144 #define DESFIRE_2KTDEA_NONCE_SIZE (CRYPTO_DES_BLOCK_SIZE)
145 #define DESFIRE_DES_IV_SIZE (CRYPTO_DES_BLOCK_SIZE)
146 #define DESFIRE_MAX_PAYLOAD_TDEA_BLOCKS (DESFIRE_MAX_PAYLOAD_SIZE / CRYPTO_DES_BLOCK_SIZE)
147 
148 /* Checksum routines: */
149 void TransferChecksumUpdateCRCA(const uint8_t *Buffer, uint8_t Count);
150 uint8_t TransferChecksumFinalCRCA(uint8_t *Buffer);
151 void TransferChecksumUpdateMACTDEA(const uint8_t *Buffer, uint8_t Count);
152 uint8_t TransferChecksumFinalMACTDEA(uint8_t *Buffer);
153 
154 #endif
+
1 /*
2 The DESFire stack portion of this firmware source
3 is free software written by Maxie Dion Schmidt (@maxieds):
4 You can redistribute it and/or modify
5 it under the terms of this license.
6 
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 
11 The complete source distribution of
12 this firmware is available at the following link:
13 https://github.com/maxieds/ChameleonMiniFirmwareDESFireStack.
14 
15 Based in part on the original DESFire code created by
16 @dev-zzo (GitHub handle) [Dmitry Janushkevich] available at
17 https://github.com/dev-zzo/ChameleonMini/tree/desfire.
18 
19 This notice must be retained at the top of all source files where indicated.
20 */
21 
22 /*
23  * DESFireCrypto.h
24  * Maxie D. Schmidt (github.com/maxieds)
25  */
26 
27 #ifndef __DESFIRE_CRYPTO_H__
28 #define __DESFIRE_CRYPTO_H__
29 
30 #include "../../Common.h"
31 
32 #include "DESFireFirmwareSettings.h"
33 
34 /* Communication modes:
35  * Define the modes of communication over the RFID channel
36  *
37  * Note there is also an AES wrapped COMMS variant called
38  * LRP Secure Messaging detailed starting on page 37
39  * (Section 7.2) of
40  * https://www.nxp.com/docs/en/application-note/AN12343.pdf
41  */
42 #define DESFIRE_COMMS_PLAINTEXT (0x00)
43 #define DESFIRE_COMMS_PLAINTEXT_MAC (0x01)
44 #define DESFIRE_COMMS_CIPHERTEXT_DES (0x03)
45 #define DESFIRE_COMMS_CIPHERTEXT_AES128 (0x04)
46 #define DESFIRE_DEFAULT_COMMS_STANDARD (DESFIRE_COMMS_PLAINTEXT)
47 
48 #define CRYPTO_TYPE_ANY (0x00)
49 #define CRYPTO_TYPE_DES (0x01)
50 #define CRYPTO_TYPE_2KTDEA (0x0A)
51 #define CRYPTO_TYPE_3K3DES (0x1A)
52 #define CRYPTO_TYPE_AES128 (0x4A)
53 
54 #define CryptoTypeDES(ct) \
55  ((ct == CRYPTO_TYPE_DES) || (ct == CRYPTO_TYPE_ANY))
56 #define CryptoType2KTDEA(ct) \
57  ((ct == CRYPTO_TYPE_2KTDEA) || (ct == CRYPTO_TYPE_ANY))
58 #define CryptoType3KTDEA(ct) \
59  ((ct == CRYPTO_TYPE_3K3DES) || (ct == CRYPTO_TYPE_ANY))
60 #define CryptoTypeAES(ct) \
61  ((ct == CRYPTO_TYPE_AES128) || (ct == CRYPTO_TYPE_ANY))
62 
63 /* Key sizes, block sizes (in bytes): */
64 #define CRYPTO_AES_KEY_SIZE (16)
65 #define CRYPTO_MAX_KEY_SIZE (24)
66 #define CRYPTO_MAX_BLOCK_SIZE (16)
67 #define DESFIRE_AES_IV_SIZE (CRYPTO_AES_BLOCK_SIZE)
68 #define DESFIRE_SESSION_KEY_SIZE (CRYPTO_3KTDEA_KEY_SIZE)
69 #define CRYPTO_CHALLENGE_RESPONSE_BYTES (8)
70 
71 typedef BYTE CryptoKeyBufferType[CRYPTO_MAX_KEY_SIZE];
72 typedef BYTE CryptoIVBufferType[CRYPTO_MAX_BLOCK_SIZE];
73 
74 extern CryptoKeyBufferType SessionKey;
75 extern CryptoIVBufferType SessionIV;
76 extern BYTE SessionIVByteSize;
77 
78 extern uint8_t Authenticated;
79 extern uint8_t AuthenticatedWithKey;
80 extern uint8_t AuthenticatedWithPICCMasterKey;
81 extern uint8_t CryptoAuthMethod;
82 extern uint8_t ActiveCommMode;
83 
84 /* Need to invalidate the authentication state after:
85  * 1) Selecting a new application;
86  * 2) Changing the active key used in the authentication;
87  * 3) A failed authentication;
88  */
89 void InvalidateAuthState(BYTE keepPICCAuthData);
90 bool IsAuthenticated(void);
91 
92 BYTE GetDefaultCryptoMethodKeySize(uint8_t cryptoType);
93 BYTE GetCryptoMethodCommSettings(uint8_t cryptoType);
94 const char *GetCryptoMethodDesc(uint8_t cryptoType);
95 const char *GetCommSettingsDesc(uint8_t cryptoType);
96 
97 #define DESFIRE_MAC_LENGTH 4
98 #define DESFIRE_CMAC_LENGTH 8 // in bytes
99 
100 /* Authentication status */
101 #define DESFIRE_NOT_AUTHENTICATED 0xFF
102 
103 typedef enum DESFIRE_FIRMWARE_ENUM_PACKING {
104  DESFIRE_AUTH_LEGACY,
105  DESFIRE_AUTH_ISO_2KTDEA,
106  DESFIRE_AUTH_ISO_3KTDEA,
107  DESFIRE_AUTH_AES,
108 } DesfireAuthType;
109 
110 BYTE GetCryptoKeyTypeFromAuthenticateMethod(BYTE authCmdMethod);
111 
112 #define CryptoBitsToBytes(cryptoBits) \
113  (cryptoBits / BITS_PER_BYTE)
114 
115 /*********************************************************
116  * AES (128) crypto routines:
117  *********************************************************/
118 
119 #include "../CryptoAES128.h"
120 
121 typedef uint8_t DesfireAESCryptoKey[CRYPTO_AES_KEY_SIZE];
122 
123 extern CryptoAESConfig_t AESCryptoContext;
124 extern DesfireAESCryptoKey AESCryptoSessionKey;
125 extern DesfireAESCryptoKey AESCryptoIVBuffer;
126 
127 void InitAESCryptoKeyData(DesfireAESCryptoKey *cryptoKeyData);
128 
129 typedef void (*CryptoAESCBCFuncType)(uint16_t, void *, void *, uint8_t *, uint8_t *);
130 
131 typedef uint8_t (*CryptoTransferSendFunc)(uint8_t *, uint8_t);
132 typedef uint8_t (*CryptoTransferReceiveFunc)(uint8_t *, uint8_t);
133 uint8_t CryptoAESTransferEncryptSend(uint8_t *Buffer, uint8_t Count, const uint8_t *Key);
134 uint8_t CryptoAESTransferEncryptReceive(uint8_t *Buffer, uint8_t Count, const uint8_t *Key);
135 
136 #define DESFIRE_MAX_PAYLOAD_AES_BLOCKS (DESFIRE_MAX_PAYLOAD_SIZE / CRYPTO_AES_BLOCK_SIZE)
137 
138 /*********************************************************
139  * TripleDES crypto routines:
140  *********************************************************/
141 
142 #include "../CryptoTDEA.h"
143 
144 #define DESFIRE_2KTDEA_NONCE_SIZE (CRYPTO_DES_BLOCK_SIZE)
145 #define DESFIRE_DES_IV_SIZE (CRYPTO_DES_BLOCK_SIZE)
146 #define DESFIRE_MAX_PAYLOAD_TDEA_BLOCKS (DESFIRE_MAX_PAYLOAD_SIZE / CRYPTO_DES_BLOCK_SIZE)
147 
148 /* Checksum routines: */
149 void TransferChecksumUpdateCRCA(const uint8_t *Buffer, uint8_t Count);
150 uint8_t TransferChecksumFinalCRCA(uint8_t *Buffer);
151 void TransferChecksumUpdateMACTDEA(const uint8_t *Buffer, uint8_t Count);
152 uint8_t TransferChecksumFinalMACTDEA(uint8_t *Buffer);
153 
154 #endif
diff --git a/Doc/Doxygen/html/_d_e_s_fire_crypto_tests_8h_source.html b/Doc/Doxygen/html/_d_e_s_fire_crypto_tests_8h_source.html index f81e0490..b245bf80 100644 --- a/Doc/Doxygen/html/_d_e_s_fire_crypto_tests_8h_source.html +++ b/Doc/Doxygen/html/_d_e_s_fire_crypto_tests_8h_source.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: DESFireCryptoTests.h Source File @@ -11,9 +12,6 @@ - @@ -31,40 +29,19 @@ - + - - + + + +
DESFireCryptoTests.h
-
1 /*
2 The DESFire stack portion of this firmware source
3 is free software written by Maxie Dion Schmidt (@maxieds):
4 You can redistribute it and/or modify
5 it under the terms of this license.
6 
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 
11 The complete source distribution of
12 this firmware is available at the following link:
13 https://github.com/maxieds/ChameleonMiniFirmwareDESFireStack.
14 
15 Based in part on the original DESFire code created by
16 @dev-zzo (GitHub handle) [Dmitry Janushkevich] available at
17 https://github.com/dev-zzo/ChameleonMini/tree/desfire.
18 */
19 
20 /* DESFireCryptoTests.h : Since we cannot easily compile the crypto sources as a standalone unit,
21  * this mechanism will allow to print some unit tests to the live logging
22  * console when a new DESFire emulation instance is initiated. At a minimum,
23  * this should help to verify that any side effects and errors in the
24  * protocols are not based on this logical part of the scheme.
25  */
26 
27 #ifndef __DESFIRE_CRYPTO_TESTS_H__
28 #define __DESFIRE_CRYPTO_TESTS_H__
29 
30 #ifdef DESFIRE_RUN_CRYPTO_TESTING_PROCEDURE
31 
32 #include "../../Common.h"
33 
34 #include "DESFireFirmwareSettings.h"
35 #include "DESFireMemoryOperations.h"
36 #include "DESFireLogging.h"
37 #include "DESFireCrypto.h"
38 
39 typedef bool (*UnitTestResultFunc)(uint8_t *errorResultBuf, uint8_t *bufSize);
40 
41 INLINE bool DiffCryptoResult(const uint8_t *bufData, const uint8_t *cmpBuf, uint8_t bufSize);
42 INLINE bool RunUnitTest(UnitTestResultFunc unitTestRunnerFunc);
43 INLINE bool RunCryptoUnitTests(void);
44 
45 INLINE bool TestDesfire2KTDEA(uint8_t *errorResultBuf, uint8_t *bufSize);
46 INLINE bool TestDesfire3K3DES(uint8_t *errorResultBuf, uint8_t *bufSize);
47 INLINE bool TestDesfireAES128(uint8_t *errorResultBuf, uint8_t *bufSize);
48 
49 INLINE bool
50 DiffCryptoResult(const uint8_t *bufData, const uint8_t *cmpBuf, uint8_t bufSize) {
51  return !memcmp(bufData, cmpBuf, bufSize);
52 }
53 
54 INLINE bool
55 RunUnitTest(UnitTestResultFunc unitTestRunnerFunc) {
56  uint16_t printResultLogSize = 0x00;
57  uint8_t errorResultBuf[CRYPTO_MAX_BLOCK_SIZE];
58  uint8_t errorBufSize = CRYPTO_MAX_BLOCK_SIZE;
59  bool unitTestPassed = unitTestRunnerFunc(errorResultBuf, &errorBufSize);
60  return unitTestPassed;
61 }
62 
63 INLINE bool
64 RunCryptoUnitTests(void) {
65  UnitTestResultFunc unitTestRunnerFuncs[] = {
66  //&TestDesfire2KTDEA,
67  //&TestDesfire3K3DES,
68  //&TestDesfireAES128,
69  };
70  uint8_t numUnitTests = sizeof(unitTestRunnerFuncs) / sizeof(UnitTestResultFunc);
71  uint8_t utIndex = 0x00;
72  while(utIndex < numUnitTests) {
73  if(!RunUnitTest(unitTestRunnerFuncs[utIndex])) {
74  uint8_t resultLogSize = 0x00;
75  return false;
76  }
77  utIndex++;
78  }
79  uint8_t resultLogSize = 0x00;
80  snprintf_P(__InternalStringBuffer, STRING_BUFFER_SIZE, PSTR("All crypto unit tests passed!"));
81  resultLogSize = StringLength(__InternalStringBuffer, STRING_BUFFER_SIZE);
82  DesfireLogEntry(LOG_INFO_DESFIRE_DEBUGGING_OUTPUT, (void *) __InternalStringBuffer, resultLogSize);
83  return true;
84 }
85 
86 #if 0
87 INLINE bool TestDesfire2KTDEA(uint8_t *errorResultBuf, uint8_t *bufSize) {
88 
89  uint8_t cryptoDataByteCount = 2 * CRYPTO_DES_BLOCK_SIZE;
90  uint8_t keyData[CRYPTO_2KTDEA_KEY_SIZE] = {
91  0xB4, 0x28, 0x2E, 0xFA, 0x9E, 0xB8, 0x2C, 0xAE,
92  0xB4, 0x28, 0x2E, 0xFA, 0x9E, 0xB8, 0x2C, 0xAE
93  };
94  uint8_t cryptoGramData[] = {
95  0x00, 0x10, 0x20, 0x31, 0x40, 0x50, 0x60, 0x70,
96  0x80, 0x90, 0xA0, 0xB0, 0xB0, 0xA0, 0x90, 0x80,
97  //0xC5, 0xFF, 0x01, 0x50, 0x00, 0x00, 0x00, 0x00
98  };
99  uint8_t cryptoGramEncData[] = {
100  0x87, 0x99, 0x59, 0x11, 0x8B, 0xD7, 0x7C, 0x70,
101  0x10, 0x7B, 0xCD, 0xB0, 0xC0, 0x9C, 0xC7, 0xDA,
102  //0x82, 0x15, 0x04, 0xAA, 0x1E, 0x36, 0x04, 0x9C
103  };
104  uint8_t cryptoResult[cryptoDataByteCount];
105  uint8_t ivBuf[CRYPTO_2KTDEA_BLOCK_SIZE];
106 
107  memset(ivBuf, 0x00, CRYPTO_2KTDEA_BLOCK_SIZE);
108  CryptoEncrypt2KTDEA_CBCSend(cryptoDataByteCount, cryptoGramData, cryptoResult, ivBuf, keyData);
109  if(!DiffCryptoResult(cryptoGramEncData, cryptoResult, cryptoDataByteCount)) {
110  BufferToHexString(__InternalStringBuffer, STRING_BUFFER_SIZE, cryptoResult, cryptoDataByteCount);
111  DesfireLogEntry(LOG_INFO_DESFIRE_DEBUGGING_OUTPUT, (void *) __InternalStringBuffer, 2 * cryptoDataByteCount);
112  return false;
113  }
114  return true;
115 
116 }
117 #endif
118 
119 #if 0
120 INLINE bool TestDesfire3K3DES(uint8_t *errorResultBuf, uint8_t *bufSize) {
121 
122  const uint8_t cryptoDataByteCount = 2 * CRYPTO_3KTDEA_BLOCK_SIZE;
123  const uint8_t keyData[CRYPTO_3KTDEA_KEY_SIZE] = {
124  0xF4, 0x68, 0x6E, 0x3A, 0xBA, 0x90, 0x36, 0xBA,
125  0xD2, 0x8E, 0xBC, 0x10, 0x32, 0xE6, 0x38, 0xF0,
126  0x80, 0x44, 0x5A, 0xF6, 0x06, 0x86, 0xD0, 0xC4
127  };
128  const uint8_t cryptoGramData[] = {
129  0x00, 0x10, 0x20, 0x31, 0x40, 0x50, 0x60, 0x70,
130  0x80, 0x90, 0xA0, 0xB0, 0xB0, 0xA0, 0x90, 0x80,
131  //0x70, 0x60, 0x50, 0x40, 0x30, 0x20, 0x10, 0x00,
132  //0xD6, 0x3E, 0x00, 0xA2, 0x00, 0x00, 0x00, 0x00
133  };
134  const uint8_t cryptoGramEncData[] = {
135  0x7F, 0x88, 0x90, 0xC7, 0xCA, 0xB9, 0xA4, 0x22,
136  0x81, 0x73, 0xA6, 0x41, 0xB6, 0x5F, 0x0F, 0x43,
137  //0xFD, 0x40, 0x4A, 0x01, 0x13, 0x71, 0xA9, 0x90,
138  //0x4A, 0x62, 0x9E, 0x3C, 0x20, 0xB2, 0xFF, 0x63
139  };
140  uint8_t cryptoResult[cryptoDataByteCount];
141  uint8_t ivBuf[CRYPTO_3KTDEA_BLOCK_SIZE];
142 
143  memset(ivBuf, 0x00, CRYPTO_3KTDEA_BLOCK_SIZE);
144  CryptoEncrypt3KTDEA_CBCSend(cryptoDataByteCount, cryptoGramData, cryptoResult, ivBuf, keyData);
145  if(!DiffCryptoResult(cryptoGramEncData, cryptoResult, cryptoDataByteCount)) {
146  BufferToHexString(__InternalStringBuffer, STRING_BUFFER_SIZE, cryptoResult, cryptoDataByteCount);
147  DesfireLogEntry(LOG_INFO_DESFIRE_DEBUGGING_OUTPUT, (void *) __InternalStringBuffer, 2 * cryptoDataByteCount);
148  return false;
149  }
150  return true;
151 
152 }
153 #endif
154 
155 #if 0
156 INLINE bool TestDesfireAES128(uint8_t *errorResultBuf, uint8_t *bufSize) {
157 
158  const uint8_t cryptoDataByteCount = 2 * CRYPTO_AES_BLOCK_SIZE;
159  const uint8_t keyData[CRYPTO_AES_KEY_SIZE] = {
160  0x73, 0xAE, 0x5D, 0x30, 0x1F, 0x45, 0x19, 0x27,
161  0x1F, 0x2A, 0x69, 0x8C, 0xEF, 0x69, 0x76, 0x04
162  };
163  const uint8_t cryptoGramData[] = {
164  0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70,
165  0x80, 0x90, 0xA0, 0xB0, 0xB0, 0xA0, 0x90, 0x80,
166  0x10, 0xD2, 0xC6, 0xE6, 0x6B, 0x00, 0x00, 0x00,
167  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
168  };
169  const uint8_t cryptoGramEncData[] = {
170  0x97, 0x41, 0x8E, 0x6C, 0xC0, 0x1C, 0x4E, 0x6F,
171  0xAD, 0x4D, 0x87, 0x4D, 0x8D, 0x42, 0x5C, 0xEA,
172  0x32, 0x51, 0x36, 0x11, 0x47, 0x2C, 0xDA, 0x04,
173  0xE3, 0x5E, 0xFB, 0x77, 0x9A, 0x7D, 0xA0, 0xE4
174  };
175  uint8_t cryptoResult[cryptoDataByteCount];
176  uint8_t ivBuf[CRYPTO_AES_BLOCK_SIZE];
177 
178  AESCryptoKeySizeBytes = 16;
179  DesfireAESCryptoInit(keyData, AESCryptoKeySizeBytes, &AESCryptoContext);
180  memset(ivBuf, 0x00, CRYPTO_AES_BLOCK_SIZE);
181  CryptoEncryptAES_CBCSend(cryptoDataByteCount, cryptoGramData, cryptoResult, ivBuf, &AESCryptoContext);
182  if(!DiffCryptoResult(cryptoGramEncData, cryptoResult, cryptoDataByteCount)) {
183  BufferToHexString(__InternalStringBuffer, STRING_BUFFER_SIZE, cryptoResult, cryptoDataByteCount);
184  DesfireLogEntry(LOG_INFO_DESFIRE_DEBUGGING_OUTPUT, (void *) __InternalStringBuffer, 2 * cryptoDataByteCount);
185  return false;
186  }
187  return true;
188 
189 }
190 #endif
191 
192 #endif
193 
194 #endif
+
1 /*
2 The DESFire stack portion of this firmware source
3 is free software written by Maxie Dion Schmidt (@maxieds):
4 You can redistribute it and/or modify
5 it under the terms of this license.
6 
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 
11 The complete source distribution of
12 this firmware is available at the following link:
13 https://github.com/maxieds/ChameleonMiniFirmwareDESFireStack.
14 
15 Based in part on the original DESFire code created by
16 @dev-zzo (GitHub handle) [Dmitry Janushkevich] available at
17 https://github.com/dev-zzo/ChameleonMini/tree/desfire.
18 */
19 
20 /* DESFireCryptoTests.h : Since we cannot easily compile the crypto sources as a standalone unit,
21  * this mechanism will allow to print some unit tests to the live logging
22  * console when a new DESFire emulation instance is initiated. At a minimum,
23  * this should help to verify that any side effects and errors in the
24  * protocols are not based on this logical part of the scheme.
25  */
26 
27 #ifndef __DESFIRE_CRYPTO_TESTS_H__
28 #define __DESFIRE_CRYPTO_TESTS_H__
29 
30 #ifdef DESFIRE_RUN_CRYPTO_TESTING_PROCEDURE
31 
32 #include "../../Common.h"
33 
34 #include "DESFireFirmwareSettings.h"
35 #include "DESFireMemoryOperations.h"
36 #include "DESFireLogging.h"
37 #include "DESFireCrypto.h"
38 
39 typedef bool (*UnitTestResultFunc)(uint8_t *errorResultBuf, uint8_t *bufSize);
40 
41 INLINE bool DiffCryptoResult(const uint8_t *bufData, const uint8_t *cmpBuf, uint8_t bufSize);
42 INLINE bool RunUnitTest(UnitTestResultFunc unitTestRunnerFunc);
43 INLINE bool RunCryptoUnitTests(void);
44 
45 INLINE bool TestDesfire2KTDEA(uint8_t *errorResultBuf, uint8_t *bufSize);
46 INLINE bool TestDesfire3K3DES(uint8_t *errorResultBuf, uint8_t *bufSize);
47 INLINE bool TestDesfireAES128(uint8_t *errorResultBuf, uint8_t *bufSize);
48 
49 INLINE bool
50 DiffCryptoResult(const uint8_t *bufData, const uint8_t *cmpBuf, uint8_t bufSize) {
51  return !memcmp(bufData, cmpBuf, bufSize);
52 }
53 
54 INLINE bool
55 RunUnitTest(UnitTestResultFunc unitTestRunnerFunc) {
56  uint16_t printResultLogSize = 0x00;
57  uint8_t errorResultBuf[CRYPTO_MAX_BLOCK_SIZE];
58  uint8_t errorBufSize = CRYPTO_MAX_BLOCK_SIZE;
59  bool unitTestPassed = unitTestRunnerFunc(errorResultBuf, &errorBufSize);
60  return unitTestPassed;
61 }
62 
63 INLINE bool
64 RunCryptoUnitTests(void) {
65  UnitTestResultFunc unitTestRunnerFuncs[] = {
66  //&TestDesfire2KTDEA,
67  //&TestDesfire3K3DES,
68  //&TestDesfireAES128,
69  };
70  uint8_t numUnitTests = sizeof(unitTestRunnerFuncs) / sizeof(UnitTestResultFunc);
71  uint8_t utIndex = 0x00;
72  while (utIndex < numUnitTests) {
73  if (!RunUnitTest(unitTestRunnerFuncs[utIndex])) {
74  uint8_t resultLogSize = 0x00;
75  return false;
76  }
77  utIndex++;
78  }
79  uint8_t resultLogSize = 0x00;
80  snprintf_P(__InternalStringBuffer, STRING_BUFFER_SIZE, PSTR("All crypto unit tests passed!"));
81  resultLogSize = StringLength(__InternalStringBuffer, STRING_BUFFER_SIZE);
82  DesfireLogEntry(LOG_INFO_DESFIRE_DEBUGGING_OUTPUT, (void *) __InternalStringBuffer, resultLogSize);
83  return true;
84 }
85 
86 #if 0
87 INLINE bool TestDesfire2KTDEA(uint8_t *errorResultBuf, uint8_t *bufSize) {
88 
89  uint8_t cryptoDataByteCount = 2 * CRYPTO_DES_BLOCK_SIZE;
90  uint8_t keyData[CRYPTO_2KTDEA_KEY_SIZE] = {
91  0xB4, 0x28, 0x2E, 0xFA, 0x9E, 0xB8, 0x2C, 0xAE,
92  0xB4, 0x28, 0x2E, 0xFA, 0x9E, 0xB8, 0x2C, 0xAE
93  };
94  uint8_t cryptoGramData[] = {
95  0x00, 0x10, 0x20, 0x31, 0x40, 0x50, 0x60, 0x70,
96  0x80, 0x90, 0xA0, 0xB0, 0xB0, 0xA0, 0x90, 0x80,
97  //0xC5, 0xFF, 0x01, 0x50, 0x00, 0x00, 0x00, 0x00
98  };
99  uint8_t cryptoGramEncData[] = {
100  0x87, 0x99, 0x59, 0x11, 0x8B, 0xD7, 0x7C, 0x70,
101  0x10, 0x7B, 0xCD, 0xB0, 0xC0, 0x9C, 0xC7, 0xDA,
102  //0x82, 0x15, 0x04, 0xAA, 0x1E, 0x36, 0x04, 0x9C
103  };
104  uint8_t cryptoResult[cryptoDataByteCount];
105  uint8_t ivBuf[CRYPTO_2KTDEA_BLOCK_SIZE];
106 
107  memset(ivBuf, 0x00, CRYPTO_2KTDEA_BLOCK_SIZE);
108  CryptoEncrypt2KTDEA_CBCSend(cryptoDataByteCount, cryptoGramData, cryptoResult, ivBuf, keyData);
109  if (!DiffCryptoResult(cryptoGramEncData, cryptoResult, cryptoDataByteCount)) {
110  BufferToHexString(__InternalStringBuffer, STRING_BUFFER_SIZE, cryptoResult, cryptoDataByteCount);
111  DesfireLogEntry(LOG_INFO_DESFIRE_DEBUGGING_OUTPUT, (void *) __InternalStringBuffer, 2 * cryptoDataByteCount);
112  return false;
113  }
114  return true;
115 
116 }
117 #endif
118 
119 #if 0
120 INLINE bool TestDesfire3K3DES(uint8_t *errorResultBuf, uint8_t *bufSize) {
121 
122  const uint8_t cryptoDataByteCount = 2 * CRYPTO_3KTDEA_BLOCK_SIZE;
123  const uint8_t keyData[CRYPTO_3KTDEA_KEY_SIZE] = {
124  0xF4, 0x68, 0x6E, 0x3A, 0xBA, 0x90, 0x36, 0xBA,
125  0xD2, 0x8E, 0xBC, 0x10, 0x32, 0xE6, 0x38, 0xF0,
126  0x80, 0x44, 0x5A, 0xF6, 0x06, 0x86, 0xD0, 0xC4
127  };
128  const uint8_t cryptoGramData[] = {
129  0x00, 0x10, 0x20, 0x31, 0x40, 0x50, 0x60, 0x70,
130  0x80, 0x90, 0xA0, 0xB0, 0xB0, 0xA0, 0x90, 0x80,
131  //0x70, 0x60, 0x50, 0x40, 0x30, 0x20, 0x10, 0x00,
132  //0xD6, 0x3E, 0x00, 0xA2, 0x00, 0x00, 0x00, 0x00
133  };
134  const uint8_t cryptoGramEncData[] = {
135  0x7F, 0x88, 0x90, 0xC7, 0xCA, 0xB9, 0xA4, 0x22,
136  0x81, 0x73, 0xA6, 0x41, 0xB6, 0x5F, 0x0F, 0x43,
137  //0xFD, 0x40, 0x4A, 0x01, 0x13, 0x71, 0xA9, 0x90,
138  //0x4A, 0x62, 0x9E, 0x3C, 0x20, 0xB2, 0xFF, 0x63
139  };
140  uint8_t cryptoResult[cryptoDataByteCount];
141  uint8_t ivBuf[CRYPTO_3KTDEA_BLOCK_SIZE];
142 
143  memset(ivBuf, 0x00, CRYPTO_3KTDEA_BLOCK_SIZE);
144  CryptoEncrypt3KTDEA_CBCSend(cryptoDataByteCount, cryptoGramData, cryptoResult, ivBuf, keyData);
145  if (!DiffCryptoResult(cryptoGramEncData, cryptoResult, cryptoDataByteCount)) {
146  BufferToHexString(__InternalStringBuffer, STRING_BUFFER_SIZE, cryptoResult, cryptoDataByteCount);
147  DesfireLogEntry(LOG_INFO_DESFIRE_DEBUGGING_OUTPUT, (void *) __InternalStringBuffer, 2 * cryptoDataByteCount);
148  return false;
149  }
150  return true;
151 
152 }
153 #endif
154 
155 #if 0
156 INLINE bool TestDesfireAES128(uint8_t *errorResultBuf, uint8_t *bufSize) {
157 
158  const uint8_t cryptoDataByteCount = 2 * CRYPTO_AES_BLOCK_SIZE;
159  const uint8_t keyData[CRYPTO_AES_KEY_SIZE] = {
160  0x73, 0xAE, 0x5D, 0x30, 0x1F, 0x45, 0x19, 0x27,
161  0x1F, 0x2A, 0x69, 0x8C, 0xEF, 0x69, 0x76, 0x04
162  };
163  const uint8_t cryptoGramData[] = {
164  0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70,
165  0x80, 0x90, 0xA0, 0xB0, 0xB0, 0xA0, 0x90, 0x80,
166  0x10, 0xD2, 0xC6, 0xE6, 0x6B, 0x00, 0x00, 0x00,
167  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
168  };
169  const uint8_t cryptoGramEncData[] = {
170  0x97, 0x41, 0x8E, 0x6C, 0xC0, 0x1C, 0x4E, 0x6F,
171  0xAD, 0x4D, 0x87, 0x4D, 0x8D, 0x42, 0x5C, 0xEA,
172  0x32, 0x51, 0x36, 0x11, 0x47, 0x2C, 0xDA, 0x04,
173  0xE3, 0x5E, 0xFB, 0x77, 0x9A, 0x7D, 0xA0, 0xE4
174  };
175  uint8_t cryptoResult[cryptoDataByteCount];
176  uint8_t ivBuf[CRYPTO_AES_BLOCK_SIZE];
177 
178  AESCryptoKeySizeBytes = 16;
179  DesfireAESCryptoInit(keyData, AESCryptoKeySizeBytes, &AESCryptoContext);
180  memset(ivBuf, 0x00, CRYPTO_AES_BLOCK_SIZE);
181  CryptoEncryptAES_CBCSend(cryptoDataByteCount, cryptoGramData, cryptoResult, ivBuf, &AESCryptoContext);
182  if (!DiffCryptoResult(cryptoGramEncData, cryptoResult, cryptoDataByteCount)) {
183  BufferToHexString(__InternalStringBuffer, STRING_BUFFER_SIZE, cryptoResult, cryptoDataByteCount);
184  DesfireLogEntry(LOG_INFO_DESFIRE_DEBUGGING_OUTPUT, (void *) __InternalStringBuffer, 2 * cryptoDataByteCount);
185  return false;
186  }
187  return true;
188 
189 }
190 #endif
191 
192 #endif
193 
194 #endif
diff --git a/Doc/Doxygen/html/_d_e_s_fire_file_8h_source.html b/Doc/Doxygen/html/_d_e_s_fire_file_8h_source.html index 77f8e671..a006f030 100644 --- a/Doc/Doxygen/html/_d_e_s_fire_file_8h_source.html +++ b/Doc/Doxygen/html/_d_e_s_fire_file_8h_source.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: DESFireFile.h Source File @@ -11,9 +12,6 @@ - @@ -31,40 +29,19 @@ - + - - + + + +
DESFireFile.h
-
1 /*
2 The DESFire stack portion of this firmware source
3 is free software written by Maxie Dion Schmidt (@maxieds):
4 You can redistribute it and/or modify
5 it under the terms of this license.
6 
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 
11 The complete source distribution of
12 this firmware is available at the following link:
13 https://github.com/maxieds/ChameleonMiniFirmwareDESFireStack.
14 
15 Based in part on the original DESFire code created by
16 @dev-zzo (GitHub handle) [Dmitry Janushkevich] available at
17 https://github.com/dev-zzo/ChameleonMini/tree/desfire.
18 
19 This notice must be retained at the top of all source files where indicated.
20 */
21 
22 /*
23  * DESFireFile.h :
24  * Maxie D. Schmidt (github.com/maxieds)
25  */
26 
27 #ifndef __DESFIRE_EFFILE_H__
28 #define __DESFIRE_EFFILE_H__
29 
30 #include "DESFireFirmwareSettings.h"
31 #include "DESFireInstructions.h"
32 
33 #define EFFILE_DATA_CHUNK_SIZE (4)
34 #define EFFILE_DATA_CHUNK_ALIGNAT __attribute__((align(EFFILE_DATA_CHUNK_SIZE)))
35 
36 // TODO: See type 4 tags on CC and NTAG AIDs and FIDs
37 #define ISO7816_4_CURRENT_EF_FILE_ID 0x0000
38 #define ISO7816_4_CURRENT_DF_FILE_ID 0x3FFF
39 #define ISO7816_4_MASTER_FILE_ID 0x3F00
40 
41 /* File types */
42 
43 // NOTE: See pages 48-49 of the datasheet for more details:
44 #define DESFIRE_FILE_STANDARD_DATA 0
45 #define DESFIRE_FILE_BACKUP_DATA 1
46 #define DESFIRE_FILE_VALUE_DATA 2
47 #define DESFIRE_FILE_LINEAR_RECORDS 3
48 #define DESFIRE_FILE_CIRCULAR_RECORDS 4
49 
50 #define DESFIRE_FILE_NOFILE_INDEX (0xff)
51 
52 /* Data about an application's file is currently kept in this structure.
53  * The location of these structures is defined by the file index.
54  */
55 typedef struct DESFIRE_FIRMWARE_PACKING {
56  uint8_t FileType;
57  uint8_t FileNumber;
58  uint16_t FileSize;
59  uint16_t FileDataAddress; /* FRAM address of the storage of the data for the file */
60  union DESFIRE_FIRMWARE_ALIGNAT {
61  struct DESFIRE_FIRMWARE_ALIGNAT {
62  uint16_t FileSize;
63  } StandardFile;
64  struct DESFIRE_FIRMWARE_ALIGNAT {
65  uint16_t FileSize;
66  uint8_t BlockCount;
67  } BackupFile;
68  struct DESFIRE_FIRMWARE_ALIGNAT {
69  int32_t CleanValue;
70  int32_t DirtyValue;
71  int32_t LowerLimit;
72  int32_t UpperLimit;
73  uint8_t LimitedCreditEnabled;
74  int32_t PreviousDebit;
75  } ValueFile;
76  struct DESFIRE_FIRMWARE_ALIGNAT {
77  uint16_t BlockCount;
78  uint16_t RecordPointer;
79  //uint8_t ClearPending; // USED ???
80  uint8_t RecordSize[3];
81  uint8_t CurrentNumRecords[3];
82  uint8_t MaxRecordCount[3];
83  } RecordFile;
84  };
85 } DESFireFileTypeSettings;
86 
87 uint16_t GetFileSizeFromFileType(DESFireFileTypeSettings *File);
88 
89 typedef struct DESFIRE_FIRMWARE_PACKING {
90  BYTE Num;
91  DESFireFileTypeSettings File;
92 } SelectedFileCacheType;
93 
94 /*
95  * File management: creation, deletion, and misc routines
96  */
97 
98 uint16_t GetFileDataAreaBlockId(uint8_t FileIndex);
99 uint8_t ReadFileControlBlockIntoCacheStructure(uint8_t FileNum, SelectedFileCacheType *FileCache);
100 uint8_t ReadFileControlBlock(uint8_t FileNum, DESFireFileTypeSettings *File);
101 uint8_t WriteFileControlBlock(uint8_t FileNum, DESFireFileTypeSettings *File);
102 
103 /* Creation and deletion */
104 uint8_t CreateFileHeaderData(uint8_t FileNum, uint8_t CommSettings,
105  uint16_t AccessRights, DESFireFileTypeSettings *File);
106 uint8_t CreateStandardFile(uint8_t FileNum, uint8_t CommSettings, uint16_t AccessRights, uint16_t FileSize);
107 uint8_t CreateBackupFile(uint8_t FileNum, uint8_t CommSettings, uint16_t AccessRights, uint16_t FileSize);
108 uint8_t CreateValueFile(uint8_t FileNum, uint8_t CommSettings, uint16_t AccessRights,
109  int32_t LowerLimit, int32_t UpperLimit, int32_t Value, bool LimitedCreditEnabled);
110 uint8_t CreateRecordFile(uint8_t FileType, uint8_t FileNum, uint8_t CommSettings, uint16_t AccessRights,
111  uint8_t *RecordSize, uint8_t *MaxRecordSize);
112 uint8_t DeleteFile(uint8_t FileIndex);
113 
114 /* Transactions */
115 
116 /* File transfers */
117 TransferStatus ReadDataFileTransfer(uint8_t* Buffer);
118 uint8_t WriteDataFileTransfer(uint8_t* Buffer, uint8_t ByteCount);
119 uint8_t ReadDataFileSetup(uint8_t FileIndex, uint8_t CommSettings, uint16_t Offset, uint16_t Length);
120 uint8_t WriteDataFileSetup(uint8_t FileIndex, uint8_t FileType, uint8_t CommSettings, uint16_t Offset, uint16_t Length);
121 uint16_t ReadDataFileIterator(uint8_t *Buffer);
122 uint8_t WriteDataFileInternal(uint8_t *Buffer, uint16_t ByteCount);
123 uint16_t WriteDataFileIterator(uint8_t *Buffer, uint16_t ByteCount);
124 
125 /* Special values for access key IDs */
126 #define DESFIRE_ACCESS_FREE 0xE
127 #define DESFIRE_ACCESS_DENY 0xF
128 
129 /* Validation routines */
130 #define VALIDATE_ACCESS_READWRITE ((uint16_t) (0x000f))
131 #define VALIDATE_ACCESS_WRITE ((uint16_t) (0x000f << 4))
132 #define VALIDATE_ACCESS_READ ((uint16_t) (0x000f << 8))
133 #define VALIDATE_ACCESS_CHANGE ((uint16_t) (0x000f << 12))
134 
135 #define VALIDATED_ACCESS_DENIED 0
136 #define VALIDATED_ACCESS_GRANTED 1
137 #define VALIDATED_ACCESS_GRANTED_PLAINTEXT 2
138 
139 /*
140  * [READ (4 bits) | WRITE | READ-WRITE | CHANGE]
141  * Stored in little endian format from memory:
142  */
143 #define GetReadPermissions(AccessRights) \
144  (BYTE) (AccessRights & 0x000f)
145 #define GetWritePermissions(AccessRights) \
146  (BYTE) (((0x00f0 & AccessRights) >> 4) & 0x000f)
147 #define GetReadWritePermissions(AccessRights) \
148  (BYTE) (((0x0f00 & AccessRights) >> 8) & 0x000f)
149 #define GetChangePermissions(AccessRights) \
150  (BYTE) (((0xf000 & AccessRights) >> 12) & 0x000f)
151 
152 const char * GetFileAccessPermissionsDesc(uint16_t fileAccessRights);
153 
154 /*
155  * There are also command/instruction-wise
156  * citations given from file's access permissions. This data is taken
157  * from the table on page 21 of the NXP application note:
158  * https://www.nxp.com/docs/en/application-note/AN12343.pdf
159  */
160 uint8_t CreateFileCommonValidation(uint8_t FileNum);
161 uint8_t ValidateAuthentication(uint16_t AccessRights, uint16_t CheckMask);
162 
163 #endif
+
1 /*
2 The DESFire stack portion of this firmware source
3 is free software written by Maxie Dion Schmidt (@maxieds):
4 You can redistribute it and/or modify
5 it under the terms of this license.
6 
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 
11 The complete source distribution of
12 this firmware is available at the following link:
13 https://github.com/maxieds/ChameleonMiniFirmwareDESFireStack.
14 
15 Based in part on the original DESFire code created by
16 @dev-zzo (GitHub handle) [Dmitry Janushkevich] available at
17 https://github.com/dev-zzo/ChameleonMini/tree/desfire.
18 
19 This notice must be retained at the top of all source files where indicated.
20 */
21 
22 /*
23  * DESFireFile.h :
24  * Maxie D. Schmidt (github.com/maxieds)
25  */
26 
27 #ifndef __DESFIRE_EFFILE_H__
28 #define __DESFIRE_EFFILE_H__
29 
30 #include "DESFireFirmwareSettings.h"
31 #include "DESFireInstructions.h"
32 
33 #define EFFILE_DATA_CHUNK_SIZE (4)
34 #define EFFILE_DATA_CHUNK_ALIGNAT __attribute__((align(EFFILE_DATA_CHUNK_SIZE)))
35 
36 // TODO: See type 4 tags on CC and NTAG AIDs and FIDs
37 #define ISO7816_4_CURRENT_EF_FILE_ID 0x0000
38 #define ISO7816_4_CURRENT_DF_FILE_ID 0x3FFF
39 #define ISO7816_4_MASTER_FILE_ID 0x3F00
40 
41 /* File types */
42 
43 // NOTE: See pages 48-49 of the datasheet for more details:
44 #define DESFIRE_FILE_STANDARD_DATA 0
45 #define DESFIRE_FILE_BACKUP_DATA 1
46 #define DESFIRE_FILE_VALUE_DATA 2
47 #define DESFIRE_FILE_LINEAR_RECORDS 3
48 #define DESFIRE_FILE_CIRCULAR_RECORDS 4
49 
50 #define DESFIRE_FILE_NOFILE_INDEX (0xff)
51 
52 /* Data about an application's file is currently kept in this structure.
53  * The location of these structures is defined by the file index.
54  */
55 typedef struct DESFIRE_FIRMWARE_PACKING {
56  uint8_t FileType;
57  uint8_t FileNumber;
58  uint16_t FileSize;
59  uint16_t FileDataAddress; /* FRAM address of the storage of the data for the file */
60  union DESFIRE_FIRMWARE_ALIGNAT {
61  struct DESFIRE_FIRMWARE_ALIGNAT {
62  uint16_t FileSize;
63  } StandardFile;
64  struct DESFIRE_FIRMWARE_ALIGNAT {
65  uint16_t FileSize;
66  uint8_t BlockCount;
67  } BackupFile;
68  struct DESFIRE_FIRMWARE_ALIGNAT {
69  int32_t CleanValue;
70  int32_t DirtyValue;
71  int32_t LowerLimit;
72  int32_t UpperLimit;
73  uint8_t LimitedCreditEnabled;
74  int32_t PreviousDebit;
75  } ValueFile;
76  struct DESFIRE_FIRMWARE_ALIGNAT {
77  uint16_t BlockCount;
78  uint16_t RecordPointer;
79  //uint8_t ClearPending; // USED ???
80  uint8_t RecordSize[3];
81  uint8_t CurrentNumRecords[3];
82  uint8_t MaxRecordCount[3];
83  } RecordFile;
84  };
85 } DESFireFileTypeSettings;
86 
87 uint16_t GetFileSizeFromFileType(DESFireFileTypeSettings *File);
88 
89 typedef struct DESFIRE_FIRMWARE_PACKING {
90  BYTE Num;
91  DESFireFileTypeSettings File;
92 } SelectedFileCacheType;
93 
94 /*
95  * File management: creation, deletion, and misc routines
96  */
97 
98 uint16_t GetFileDataAreaBlockId(uint8_t FileIndex);
99 uint8_t ReadFileControlBlockIntoCacheStructure(uint8_t FileNum, SelectedFileCacheType *FileCache);
100 uint8_t ReadFileControlBlock(uint8_t FileNum, DESFireFileTypeSettings *File);
101 uint8_t WriteFileControlBlock(uint8_t FileNum, DESFireFileTypeSettings *File);
102 
103 /* Creation and deletion */
104 uint8_t CreateFileHeaderData(uint8_t FileNum, uint8_t CommSettings,
105  uint16_t AccessRights, DESFireFileTypeSettings *File);
106 uint8_t CreateStandardFile(uint8_t FileNum, uint8_t CommSettings, uint16_t AccessRights, uint16_t FileSize);
107 uint8_t CreateBackupFile(uint8_t FileNum, uint8_t CommSettings, uint16_t AccessRights, uint16_t FileSize);
108 uint8_t CreateValueFile(uint8_t FileNum, uint8_t CommSettings, uint16_t AccessRights,
109  int32_t LowerLimit, int32_t UpperLimit, int32_t Value, bool LimitedCreditEnabled);
110 uint8_t CreateRecordFile(uint8_t FileType, uint8_t FileNum, uint8_t CommSettings, uint16_t AccessRights,
111  uint8_t *RecordSize, uint8_t *MaxRecordSize);
112 uint8_t DeleteFile(uint8_t FileIndex);
113 
114 /* Transactions */
115 
116 /* File transfers */
117 TransferStatus ReadDataFileTransfer(uint8_t *Buffer);
118 uint8_t WriteDataFileTransfer(uint8_t *Buffer, uint8_t ByteCount);
119 uint8_t ReadDataFileSetup(uint8_t FileIndex, uint8_t CommSettings, uint16_t Offset, uint16_t Length);
120 uint8_t WriteDataFileSetup(uint8_t FileIndex, uint8_t FileType, uint8_t CommSettings, uint16_t Offset, uint16_t Length);
121 uint16_t ReadDataFileIterator(uint8_t *Buffer);
122 uint8_t WriteDataFileInternal(uint8_t *Buffer, uint16_t ByteCount);
123 uint16_t WriteDataFileIterator(uint8_t *Buffer, uint16_t ByteCount);
124 
125 /* Special values for access key IDs */
126 #define DESFIRE_ACCESS_FREE 0xE
127 #define DESFIRE_ACCESS_DENY 0xF
128 
129 /* Validation routines */
130 #define VALIDATE_ACCESS_READWRITE ((uint16_t) (0x000f))
131 #define VALIDATE_ACCESS_WRITE ((uint16_t) (0x000f << 4))
132 #define VALIDATE_ACCESS_READ ((uint16_t) (0x000f << 8))
133 #define VALIDATE_ACCESS_CHANGE ((uint16_t) (0x000f << 12))
134 
135 #define VALIDATED_ACCESS_DENIED 0
136 #define VALIDATED_ACCESS_GRANTED 1
137 #define VALIDATED_ACCESS_GRANTED_PLAINTEXT 2
138 
139 /*
140  * [READ (4 bits) | WRITE | READ-WRITE | CHANGE]
141  * Stored in little endian format from memory:
142  */
143 #define GetReadPermissions(AccessRights) \
144  (BYTE) (AccessRights & 0x000f)
145 #define GetWritePermissions(AccessRights) \
146  (BYTE) (((0x00f0 & AccessRights) >> 4) & 0x000f)
147 #define GetReadWritePermissions(AccessRights) \
148  (BYTE) (((0x0f00 & AccessRights) >> 8) & 0x000f)
149 #define GetChangePermissions(AccessRights) \
150  (BYTE) (((0xf000 & AccessRights) >> 12) & 0x000f)
151 
152 const char *GetFileAccessPermissionsDesc(uint16_t fileAccessRights);
153 
154 /*
155  * There are also command/instruction-wise
156  * citations given from file's access permissions. This data is taken
157  * from the table on page 21 of the NXP application note:
158  * https://www.nxp.com/docs/en/application-note/AN12343.pdf
159  */
160 uint8_t CreateFileCommonValidation(uint8_t FileNum);
161 uint8_t ValidateAuthentication(uint16_t AccessRights, uint16_t CheckMask);
162 
163 #endif
diff --git a/Doc/Doxygen/html/_d_e_s_fire_firmware_settings_8h_source.html b/Doc/Doxygen/html/_d_e_s_fire_firmware_settings_8h_source.html index 67a64924..435b424e 100644 --- a/Doc/Doxygen/html/_d_e_s_fire_firmware_settings_8h_source.html +++ b/Doc/Doxygen/html/_d_e_s_fire_firmware_settings_8h_source.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: DESFireFirmwareSettings.h Source File @@ -11,9 +12,6 @@ - @@ -31,40 +29,19 @@ - + - - + + + +
DESFireFirmwareSettings.h
-
1 /*
2 The DESFire stack portion of this firmware source
3 is free software written by Maxie Dion Schmidt (@maxieds):
4 You can redistribute it and/or modify
5 it under the terms of this license.
6 
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 
11 The complete source distribution of
12 this firmware is available at the following link:
13 https://github.com/maxieds/ChameleonMiniFirmwareDESFireStack.
14 
15 Based in part on the original DESFire code created by
16 @dev-zzo (GitHub handle) [Dmitry Janushkevich] available at
17 https://github.com/dev-zzo/ChameleonMini/tree/desfire.
18 
19 This notice must be retained at the top of all source files where indicated.
20 */
21 
22 /*
23  * DESFireFirmwareSettings.h :
24  * Maxie D. Schmidt (github.com/maxieds)
25  */
26 
27 #ifndef __DESFIRE_FIRMWARE_SETTINGS_H__
28 #define __DESFIRE_FIRMWARE_SETTINGS_H__
29 
30 #include <stdint.h>
31 #include <stdbool.h>
32 
33 #include "../../Common.h"
34 
35 #define DESFIRE_FIRMWARE_DEBUGGING (1)
36 
37 #define DESFIRE_FIRMWARE_BUILD_TIMESTAMP (BUILD_DATE)
38 #define DESFIRE_FIRMWARE_GIT_COMMIT_ID (COMMIT_ID)
39 #define DESFIRE_FIRMWARE_REVISION ("0.0.2")
40 #define DESFIRE_FIRMWARE_PICC_LAYOUT_REVISION (0x02)
41 
42 #define DESFIRE_LITTLE_ENDIAN (1)
43 
44 #define DESFIRE_PICC_STRUCT_PACKING //__attribute__((aligned(1)))
45 #define DESFIRE_FIRMWARE_PACKING __attribute__((packed))
46 #define DESFIRE_FIRMWARE_ALIGNAT __attribute__((aligned(1)))
47 #define DESFIRE_PICC_ARRAY_ALIGNAT //__attribute__((aligned(1)))
48 #define DESFIRE_FIRMWARE_ARRAY_ALIGNAT //__attribute__((aligned(1)))
49 #define DESFIRE_FIRMWARE_ENUM_PACKING //__attribute__((aligned(1)))
50 #define DESFIRE_FIRMWARE_NOINIT //__attribute__ ((section (".noinit")))
51 
52 /* Some standard boolean interpreted and other values for types and return values: */
53 typedef int BOOL;
54 typedef uint8_t BYTE;
55 typedef uint16_t NIBBLE;
56 typedef uint16_t SIZET;
57 typedef uint32_t UINT;
58 
59 #define TRUE ((BOOL) 0x01)
60 #define FALSE ((BOOL) 0x00)
61 
62 #define IsTrue(rcond) (rcond != FALSE)
63 #define IsFalse(rcond) (rcond == FALSE)
64 
65 /* Allow users to modify typically reserved and protected read-only data on the tag
66  like the manufacturer bytes and the serial number (set in Makefile)? */
67 #ifdef ENABLE_PERMISSIVE_DESFIRE_SETTINGS
68  #define DESFIRE_ALLOW_PROTECTED_MODIFY (1)
69 #else
70  #define DESFIRE_ALLOW_PROTECTED_MODIFY (0)
71 #endif
72 
73 /* Whether to auto select application ID and file before the user (input system)
74  even invokes an ISO SELECT APPLICATION [0x00 0xa4 0x04] command? */
75 #define DESFIRE_LEGACY_SUPPORT (0)
76 
77 #endif
+
1 /*
2 The DESFire stack portion of this firmware source
3 is free software written by Maxie Dion Schmidt (@maxieds):
4 You can redistribute it and/or modify
5 it under the terms of this license.
6 
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 
11 The complete source distribution of
12 this firmware is available at the following link:
13 https://github.com/maxieds/ChameleonMiniFirmwareDESFireStack.
14 
15 Based in part on the original DESFire code created by
16 @dev-zzo (GitHub handle) [Dmitry Janushkevich] available at
17 https://github.com/dev-zzo/ChameleonMini/tree/desfire.
18 
19 This notice must be retained at the top of all source files where indicated.
20 */
21 
22 /*
23  * DESFireFirmwareSettings.h :
24  * Maxie D. Schmidt (github.com/maxieds)
25  */
26 
27 #ifndef __DESFIRE_FIRMWARE_SETTINGS_H__
28 #define __DESFIRE_FIRMWARE_SETTINGS_H__
29 
30 #include <stdint.h>
31 #include <stdbool.h>
32 
33 #include "../../Common.h"
34 
35 #define DESFIRE_FIRMWARE_DEBUGGING (1)
36 
37 #define DESFIRE_FIRMWARE_BUILD_TIMESTAMP (BUILD_DATE)
38 #define DESFIRE_FIRMWARE_GIT_COMMIT_ID (COMMIT_ID)
39 #define DESFIRE_FIRMWARE_REVISION ("0.0.2")
40 #define DESFIRE_FIRMWARE_PICC_LAYOUT_REVISION (0x02)
41 
42 #define DESFIRE_LITTLE_ENDIAN (1)
43 
44 #define DESFIRE_PICC_STRUCT_PACKING //__attribute__((aligned(1)))
45 #define DESFIRE_FIRMWARE_PACKING __attribute__((packed))
46 #define DESFIRE_FIRMWARE_ALIGNAT __attribute__((aligned(1)))
47 #define DESFIRE_PICC_ARRAY_ALIGNAT //__attribute__((aligned(1)))
48 #define DESFIRE_FIRMWARE_ARRAY_ALIGNAT //__attribute__((aligned(1)))
49 #define DESFIRE_FIRMWARE_ENUM_PACKING //__attribute__((aligned(1)))
50 #define DESFIRE_FIRMWARE_NOINIT //__attribute__ ((section (".noinit")))
51 
52 /* Some standard boolean interpreted and other values for types and return values: */
53 typedef int BOOL;
54 typedef uint8_t BYTE;
55 typedef uint16_t NIBBLE;
56 typedef uint16_t SIZET;
57 typedef uint32_t UINT;
58 
59 #define TRUE ((BOOL) 0x01)
60 #define FALSE ((BOOL) 0x00)
61 
62 #define IsTrue(rcond) (rcond != FALSE)
63 #define IsFalse(rcond) (rcond == FALSE)
64 
65 /* Allow users to modify typically reserved and protected read-only data on the tag
66  like the manufacturer bytes and the serial number (set in Makefile)? */
67 #ifdef ENABLE_PERMISSIVE_DESFIRE_SETTINGS
68 #define DESFIRE_ALLOW_PROTECTED_MODIFY (1)
69 #else
70 #define DESFIRE_ALLOW_PROTECTED_MODIFY (0)
71 #endif
72 
73 /* Whether to auto select application ID and file before the user (input system)
74  even invokes an ISO SELECT APPLICATION [0x00 0xa4 0x04] command? */
75 #define DESFIRE_LEGACY_SUPPORT (0)
76 
77 #endif
diff --git a/Doc/Doxygen/html/_d_e_s_fire_i_s_o14443_support_8h_source.html b/Doc/Doxygen/html/_d_e_s_fire_i_s_o14443_support_8h_source.html index 4425d2c2..e4f66ef3 100644 --- a/Doc/Doxygen/html/_d_e_s_fire_i_s_o14443_support_8h_source.html +++ b/Doc/Doxygen/html/_d_e_s_fire_i_s_o14443_support_8h_source.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: DESFireISO14443Support.h Source File @@ -11,9 +12,6 @@ - @@ -31,40 +29,19 @@ - + - - + + + +
DESFireISO14443Support.h
-
1 /*
2 The DESFire stack portion of this firmware source
3 is free software written by Maxie Dion Schmidt (@maxieds):
4 You can redistribute it and/or modify
5 it under the terms of this license.
6 
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 
11 The complete source distribution of
12 this firmware is available at the following link:
13 https://github.com/maxieds/ChameleonMiniFirmwareDESFireStack.
14 
15 Based in part on the original DESFire code created by
16 @dev-zzo (GitHub handle) [Dmitry Janushkevich] available at
17 https://github.com/dev-zzo/ChameleonMini/tree/desfire.
18 
19 This notice must be retained at the top of all source files where indicated.
20 */
21 
22 /*
23  * DESFireISO14443Support.h
24  * Maxie D. Schmidt (github.com/maxieds)
25  */
26 
27 #ifndef __DESFIRE_ISO14443_SUPPORT_H__
28 #define __DESFIRE_ISO14443_SUPPORT_H__
29 
30 #include "DESFireFirmwareSettings.h"
31 
32 #include "../ISO14443-3A.h"
33 #include "../../Codec/ISO14443-2A.h"
34 
35 /* General structure of a ISO 14443-4 block:
36  * PCB (protocol control byte)
37  * CID (card identifier byte; presence controlled by PCB)
38  * NAD (node address byte; presence controlled by PCB)
39  * Payload (arbitrary bytes)
40  * CRC-16
41  */
42 
43 #define ISO14443A_CMD_RATS 0xE0
44 #define ISO14443A_RATS_FRAME_SIZE (6 * BITS_PER_BYTE) //(4 * 8) /* Bit */
45 #define ISO14443A_CRC_BYTES_FRAME_SIZE (ISO14443A_CRCA_SIZE * BITS_PER_BYTE)
46 
47 #define ISO14443_PCB_BLOCK_TYPE_MASK 0xC0
48 #define ISO14443_PCB_I_BLOCK 0x00
49 #define ISO14443_PCB_R_BLOCK 0x80
50 #define ISO14443_PCB_S_BLOCK 0xC0
51 
52 #define ISO14443_PCB_I_BLOCK_STATIC 0x02
53 #define ISO14443_PCB_R_BLOCK_STATIC 0xA2
54 #define ISO14443_PCB_S_BLOCK_STATIC 0xC2
55 
56 #define ISO14443_PCB_BLOCK_NUMBER_MASK 0x01
57 #define ISO14443_PCB_HAS_NAD_MASK 0x04
58 #define ISO14443_PCB_HAS_CID_MASK 0x08
59 #define ISO14443_PCB_I_BLOCK_CHAINING_MASK 0x10
60 #define ISO14443_PCB_R_BLOCK_ACKNAK_MASK 0x10
61 #define ISO14443_PCB_R_BLOCK_ACK 0x00
62 #define ISO14443_PCB_R_BLOCK_NAK 0x10
63 
64 #define ISO14443_R_BLOCK_SIZE 1 /* Bytes */
65 
66 #define ISO14443_PCB_S_DESELECT (ISO14443_PCB_S_BLOCK_STATIC)
67 #define ISO14443_PCB_S_WTX (ISO14443_PCB_S_BLOCK_STATIC | 0x30)
68 
69 #define IS_ISO14443A_4_COMPLIANT(buf) (buf[0] & 0x20)
70 #define MAKE_ISO14443A_4_COMPLIANT(buf) (buf[0] |= 0x20)
71 
72 /*
73  * ISO/IEC 14443-4 implementation
74  * To support EV2 cards emulation, proper support for handling 14443-4
75  * blocks will be implemented.
76  * Currently NOT supported:
77  * + Block chaining
78  * + Frame waiting time extension
79  */
80 
81 typedef enum DESFIRE_FIRMWARE_ENUM_PACKING {
82  ISO14443_4_STATE_EXPECT_RATS,
83  ISO14443_4_STATE_ACTIVE,
84  ISO14443_4_STATE_LAST,
85 } Iso144434StateType;
86 
87 extern Iso144434StateType Iso144434State;
88 extern uint8_t Iso144434BlockNumber;
89 extern uint8_t Iso144434CardID;
90 
91 /* Setup some fuzzy response handling for problematic readers like the ACR122U */
92 #define MAX_STATE_RETRY_COUNT (2)
93 extern uint8_t StateRetryCount;
94 bool CheckStateRetryCount(bool resetByDefault);
95 bool CheckStateRetryCount2(bool resetByDefault, bool performLogging);
96 
97 #define IGNORE_ACK_BYTE (0x92)
98 
99 /* Support functions */
100 void ISO144434SwitchState(Iso144434StateType NewState);
101 void ISO144434SwitchState2(Iso144434StateType NewState, bool performLogging);
102 
103 void ISO144434Reset(void);
104 uint16_t ISO144434ProcessBlock(uint8_t* Buffer, uint16_t ByteCount, uint16_t BitCount);
105 
106 /*
107  * ISO/IEC 14443-3A implementation
108  */
109 
110 #define ISO14443A_CRCA_INIT ((uint16_t) 0x6363)
111 
112 uint16_t ISO14443AUpdateCRCA(const uint8_t *Buffer, uint16_t ByteCount, uint16_t InitCRCA);
113 
114 typedef enum DESFIRE_FIRMWARE_ENUM_PACKING {
115  /* The card is powered up but not selected */
116  ISO14443_3A_STATE_IDLE = ISO14443_4_STATE_LAST,
117  /* Entered on REQA or WUPA; anticollision is being performed */
118  ISO14443_3A_STATE_READY1,
119  ISO14443_3A_STATE_READY2,
120  /* Entered when the card has been selected */
121  ISO14443_3A_STATE_ACTIVE,
122  /* Something went wrong or we've received a halt command */
123  ISO14443_3A_STATE_HALT,
124 } Iso144433AStateType;
125 
126 extern Iso144433AStateType Iso144433AState;
127 extern Iso144433AStateType Iso144433AIdleState;
128 
129 /* Support functions */
130 void ISO144433ASwitchState(Iso144433AStateType NewState);
131 void ISO144433AReset(void);
132 void ISO144433AHalt(void);
133 bool ISO144433AIsHalt(const uint8_t* Buffer, uint16_t BitCount);
134 uint16_t ISO144433APiccProcess(uint8_t* Buffer, uint16_t BitCount);
135 
136 #endif
+
1 /*
2 The DESFire stack portion of this firmware source
3 is free software written by Maxie Dion Schmidt (@maxieds):
4 You can redistribute it and/or modify
5 it under the terms of this license.
6 
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 
11 The complete source distribution of
12 this firmware is available at the following link:
13 https://github.com/maxieds/ChameleonMiniFirmwareDESFireStack.
14 
15 Based in part on the original DESFire code created by
16 @dev-zzo (GitHub handle) [Dmitry Janushkevich] available at
17 https://github.com/dev-zzo/ChameleonMini/tree/desfire.
18 
19 This notice must be retained at the top of all source files where indicated.
20 */
21 
22 /*
23  * DESFireISO14443Support.h
24  * Maxie D. Schmidt (github.com/maxieds)
25  */
26 
27 #ifndef __DESFIRE_ISO14443_SUPPORT_H__
28 #define __DESFIRE_ISO14443_SUPPORT_H__
29 
30 #include "DESFireFirmwareSettings.h"
31 
32 #include "../ISO14443-3A.h"
33 #include "../../Codec/ISO14443-2A.h"
34 
35 /* General structure of a ISO 14443-4 block:
36  * PCB (protocol control byte)
37  * CID (card identifier byte; presence controlled by PCB)
38  * NAD (node address byte; presence controlled by PCB)
39  * Payload (arbitrary bytes)
40  * CRC-16
41  */
42 
43 #define ISO14443A_CMD_RATS 0xE0
44 #define ISO14443A_RATS_FRAME_SIZE (6 * BITS_PER_BYTE) //(4 * 8) /* Bit */
45 #define ISO14443A_CMD_RNAK 0xB2
46 #define ISO14443A_CRC_FRAME_SIZE (ISO14443A_CRCA_SIZE * BITS_PER_BYTE)
47 
48 #define ISO14443_PCB_BLOCK_TYPE_MASK 0xC0
49 #define ISO14443_PCB_I_BLOCK 0x00
50 #define ISO14443_PCB_R_BLOCK 0x80
51 #define ISO14443_PCB_S_BLOCK 0xC0
52 
53 #define ISO14443_PCB_I_BLOCK_STATIC 0x02
54 #define ISO14443_PCB_R_BLOCK_STATIC 0xA2
55 #define ISO14443_PCB_S_BLOCK_STATIC 0xC2
56 
57 #define ISO14443_PCB_BLOCK_NUMBER_MASK 0x01
58 #define ISO14443_PCB_HAS_NAD_MASK 0x04
59 #define ISO14443_PCB_HAS_CID_MASK 0x08
60 #define ISO14443_PCB_I_BLOCK_CHAINING_MASK 0x10
61 #define ISO14443_PCB_R_BLOCK_ACKNAK_MASK 0x10
62 #define ISO14443_PCB_R_BLOCK_ACK 0x00
63 #define ISO14443_PCB_R_BLOCK_NAK 0x10
64 
65 #define ISO14443_R_BLOCK_SIZE 1 /* Bytes */
66 
67 #define ISO14443_PCB_S_DESELECT (ISO14443_PCB_S_BLOCK_STATIC)
68 #define ISO14443_PCB_S_DESELECT_V2 0xCA
69 #define ISO14443_PCB_S_WTX (ISO14443_PCB_S_BLOCK_STATIC | 0x30)
70 #define ISO14443A_CMD_PPS 0xD0
71 
72 #define IS_ISO14443A_4_COMPLIANT(buf) (buf[0] & 0x20)
73 #define MAKE_ISO14443A_4_COMPLIANT(buf) (buf[0] |= 0x20)
74 
75 /*
76  * ISO/IEC 14443-4 implementation
77  * To support EV2 cards emulation, proper support for handling 14443-4
78  * blocks will be implemented.
79  * Currently NOT supported:
80  * + Block chaining
81  * + Frame waiting time extension
82  */
83 
84 typedef enum DESFIRE_FIRMWARE_ENUM_PACKING {
85  ISO14443_4_STATE_EXPECT_RATS,
86  ISO14443_4_STATE_ACTIVE,
87  ISO14443_4_STATE_LAST,
88 } Iso144434StateType;
89 
90 extern Iso144434StateType Iso144434State;
91 extern uint8_t Iso144434BlockNumber;
92 extern uint8_t Iso144434CardID;
93 extern uint8_t LastReaderSentCmd;
94 
95 /* Setup some fuzzy response handling for problematic readers like the ACR122U */
96 #define MAX_STATE_RETRY_COUNT (4)
97 extern uint8_t StateRetryCount;
98 bool CheckStateRetryCount(bool resetByDefault);
99 bool CheckStateRetryCount2(bool resetByDefault, bool performLogging);
100 
101 #define IGNORE_ACK_BYTE (0x92)
102 
103 /* Support functions */
104 void ISO144434SwitchState(Iso144434StateType NewState);
105 void ISO144434SwitchState2(Iso144434StateType NewState, bool performLogging);
106 
107 void ISO144434Reset(void);
108 static uint16_t ISO144434ProcessBlock(uint8_t *Buffer, uint16_t ByteCount, uint16_t BitCount);
109 
110 /*
111  * ISO/IEC 14443-3A implementation
112  */
113 #define ISO14443A_CRCA_INIT ((uint16_t) 0x6363)
114 
115 #define GetAndSetBufferCRCA(Buffer, ByteCount) ({ \
116  uint16_t fullReturnBits = 0; \
117  ISO14443AAppendCRCA(Buffer, ByteCount); \
118  fullReturnBits = ByteCount * BITS_PER_BYTE + ISO14443A_CRC_FRAME_SIZE; \
119  fullReturnBits; \
120  })
121 /* TODO: Should we return CRC bytes when giving a NO_RESPONSE ??? ... Apparently "No". */
122 #define GetAndSetNoResponseCRCA(Buffer) ({ \
123  uint16_t fullReturnBits = 0; \
124  ISO14443AAppendCRCA(Buffer, 0); \
125  fullReturnBits = ISO14443A_CRC_FRAME_SIZE; \
126  fullReturnBits; \
127  })
128 
129 uint16_t ISO14443AUpdateCRCA(const uint8_t *Buffer, uint16_t ByteCount, uint16_t InitCRCA);
130 
131 typedef enum DESFIRE_FIRMWARE_ENUM_PACKING {
132  /* The card is powered up but not selected */
133  ISO14443_3A_STATE_IDLE = ISO14443_4_STATE_LAST,
134  /* Entered on REQA or WUPA; anticollision is being performed */
135  ISO14443_3A_STATE_READY1,
136  ISO14443_3A_STATE_READY2,
137  /* Entered when the card has been selected */
138  ISO14443_3A_STATE_ACTIVE,
139  /* Something went wrong or we've received a halt command */
140  ISO14443_3A_STATE_HALT,
141 } Iso144433AStateType;
142 
143 extern Iso144433AStateType Iso144433AState;
144 extern Iso144433AStateType Iso144433AIdleState;
145 
146 /* Support functions */
147 void ISO144433ASwitchState(Iso144433AStateType NewState);
148 void ISO144433AReset(void);
149 void ISO144433AHalt(void);
150 bool ISO144433AIsHalt(const uint8_t *Buffer, uint16_t BitCount);
151 uint16_t ISO144433APiccProcess(uint8_t *Buffer, uint16_t BitCount);
152 
153 #endif
diff --git a/Doc/Doxygen/html/_d_e_s_fire_i_s_o7816_support_8h_source.html b/Doc/Doxygen/html/_d_e_s_fire_i_s_o7816_support_8h_source.html index 5ba6ad04..148d0139 100644 --- a/Doc/Doxygen/html/_d_e_s_fire_i_s_o7816_support_8h_source.html +++ b/Doc/Doxygen/html/_d_e_s_fire_i_s_o7816_support_8h_source.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: DESFireISO7816Support.h Source File @@ -11,9 +12,6 @@ - @@ -31,40 +29,19 @@ - + - - + + + +
DESFireISO7816Support.h
-
1 /*
2 The DESFire stack portion of this firmware source
3 is free software written by Maxie Dion Schmidt (@maxieds):
4 You can redistribute it and/or modify
5 it under the terms of this license.
6 
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 
11 The complete source distribution of
12 this firmware is available at the following link:
13 https://github.com/maxieds/ChameleonMiniFirmwareDESFireStack.
14 
15 Based in part on the original DESFire code created by
16 @dev-zzo (GitHub handle) [Dmitry Janushkevich] available at
17 https://github.com/dev-zzo/ChameleonMini/tree/desfire.
18 
19 This notice must be retained at the top of all source files where indicated.
20 */
21 
22 /* DESFireISO7816Support.h */
23 
24 #ifndef __DESFIRE_ISO7816_SUPPORT_H__
25 #define __DESFIRE_ISO7816_SUPPORT_H__
26 
27 #include <inttypes.h>
28 #include <stdbool.h>
29 
30 #define Iso7816CLA(cmdCode) \
31  (cmdCode == DESFIRE_ISO7816_CLA)
32 
33 #define ISO7816_STATUS_RESPONSE_SIZE (0x02)
34 #define ISO7816_EF_NOT_SPECIFIED (0xff)
35 #define ISO7816_EFID_NUMBER_MAX (0x0f)
36 #define ISO7816_MAX_FILE_SIZE (0xfd)
37 #define ISO7816_READ_ALL_BYTES_SIZE (0x00)
38 #define ISO7816_CMD_NO_ERROR (0x00)
39 #define ISO7816_ERROR_SW1 (0x6a)
40 #define ISO7816_ERROR_SW1_ACCESS (0x69)
41 #define ISO7816_ERROR_SW1_FSE (0x62)
42 #define ISO7816_ERROR_SW1_WRONG_FSPARAMS (0x6b)
43 #define ISO7816_ERROR_SW2_INCORRECT_P1P2 (0x86)
44 #define ISO7816_ERROR_SW2_UNSUPPORTED (0x81)
45 #define ISO7816_SELECT_ERROR_SW2_UNSUPPORTED (0x81)
46 #define ISO7816_SELECT_ERROR_SW2_NOFILE (0x82)
47 #define ISO7816_ERROR_SW2_FILE_NOMEM (0x84)
48 #define ISO7816_GET_CHALLENGE_ERROR_SW2_UNSUPPORTED (0x81)
49 #define ISO7816_ERROR_SW2_INCOMPATFS (0x81)
50 #define ISO7816_ERROR_SW2_SECURITY (0x82)
51 #define ISO7816_ERROR_SW2_NOEF (0x86)
52 #define ISO7816_ERROR_SW2_WRONG_FSPARAMS (0x00)
53 #define ISO7816_ERROR_SW2_EOF (0x82)
54 
55 #define AppendSW12Bytes(sw1, sw2) \
56  ((uint16_t) ((sw1 << 8) | (sw2 & 0xff)))
57 
58 /* Some of the wrapped ISO7816 commands have extra meaning
59  * packed into the P1-P2 bytes of the APDU byte array.
60  * When we support these extra modes, this is a way to keep
61  * track of the local meanings without needing extra handling
62  * functions to distinguish between the wrapped command types
63  * for the ISO7816 versus native DESFire instructions.
64  */
65 typedef enum {
66  ISO7816_NO_DATA = 0,
67  ISO7816_UNSUPPORTED_MODE,
68  ISO7816_SELECT_EF,
69  ISO7816_SELECT_DF,
70  ISO7816_FILE_FIRST_RECORD,
71  ISO7816_FILE_LAST_RECORD,
72  ISO7816_FILE_NEXT_RECORD,
73  ISO7816_FILE_PREV_RECORD,
74 } Iso7816WrappedParams_t;
75 
76 extern Iso7816WrappedParams_t Iso7816P1Data;
77 extern Iso7816WrappedParams_t Iso7816P2Data;
78 extern bool Iso7816FileSelected;
79 extern uint8_t Iso7816FileOffset;
80 extern uint8_t Iso7816EfIdNumber;
81 
82 uint16_t SetIso7816WrappedParametersType(uint8_t *Buffer, uint16_t ByteCount);
83 
84 #endif
+
1 /*
2 The DESFire stack portion of this firmware source
3 is free software written by Maxie Dion Schmidt (@maxieds):
4 You can redistribute it and/or modify
5 it under the terms of this license.
6 
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 
11 The complete source distribution of
12 this firmware is available at the following link:
13 https://github.com/maxieds/ChameleonMiniFirmwareDESFireStack.
14 
15 Based in part on the original DESFire code created by
16 @dev-zzo (GitHub handle) [Dmitry Janushkevich] available at
17 https://github.com/dev-zzo/ChameleonMini/tree/desfire.
18 
19 This notice must be retained at the top of all source files where indicated.
20 */
21 
22 /* DESFireISO7816Support.h */
23 
24 #ifndef __DESFIRE_ISO7816_SUPPORT_H__
25 #define __DESFIRE_ISO7816_SUPPORT_H__
26 
27 #include <inttypes.h>
28 #include <stdbool.h>
29 
30 #define Iso7816CLA(cmdCode) \
31  (cmdCode == DESFIRE_ISO7816_CLA)
32 
33 #define ISO7816_PROLOGUE_SIZE (2)
34 #define ISO7816_STATUS_RESPONSE_SIZE (0x02)
35 #define ISO7816_EF_NOT_SPECIFIED (0xff)
36 #define ISO7816_EFID_NUMBER_MAX (0x0f)
37 #define ISO7816_MAX_FILE_SIZE (0xfd)
38 #define ISO7816_READ_ALL_BYTES_SIZE (0x00)
39 #define ISO7816_CMD_NO_ERROR (0x00)
40 #define ISO7816_ERROR_SW1 (0x6a)
41 #define ISO7816_ERROR_SW1_INS_UNSUPPORTED (0x6d)
42 #define ISO7816_ERROR_SW1_ACCESS (0x69)
43 #define ISO7816_ERROR_SW1_FSE (0x62)
44 #define ISO7816_ERROR_SW1_WRONG_FSPARAMS (0x6b)
45 #define ISO7816_ERROR_SW2_INCORRECT_P1P2 (0x86)
46 #define ISO7816_ERROR_SW2_UNSUPPORTED (0x81)
47 #define ISO7816_ERROR_SW2_FUNC_UNSUPPORTED (0x81)
48 #define ISO7816_ERROR_SW2_INS_UNSUPPORTED (0x00)
49 #define ISO7816_SELECT_ERROR_SW2_FUNC_UNSUPPORTED (0x81)
50 #define ISO7816_SELECT_ERROR_SW2_NOFILE (0x82)
51 #define ISO7816_ERROR_SW2_FILE_NOMEM (0x84)
52 #define ISO7816_GET_CHALLENGE_ERROR_SW2_UNSUPPORTED (0x81)
53 #define ISO7816_ERROR_SW2_INCOMPATFS (0x81)
54 #define ISO7816_ERROR_SW2_SECURITY (0x82)
55 #define ISO7816_ERROR_SW2_NOEF (0x86)
56 #define ISO7816_ERROR_SW2_WRONG_FSPARAMS (0x00)
57 #define ISO7816_ERROR_SW2_EOF (0x82)
58 
59 #define AppendSW12Bytes(sw1, sw2) \
60  ((uint16_t) ((sw1 << 8) | (sw2 & 0xff)))
61 
62 /* Some of the wrapped ISO7816 commands have extra meaning
63  * packed into the P1-P2 bytes of the APDU byte array.
64  * When we support these extra modes, this is a way to keep
65  * track of the local meanings without needing extra handling
66  * functions to distinguish between the wrapped command types
67  * for the ISO7816 versus native DESFire instructions.
68  */
69 typedef enum {
70  ISO7816_NO_DATA = 0,
71  ISO7816_UNSUPPORTED_MODE,
72  ISO7816_SELECT_EF,
73  ISO7816_SELECT_DF,
74  ISO7816_FILE_FIRST_RECORD,
75  ISO7816_FILE_LAST_RECORD,
76  ISO7816_FILE_NEXT_RECORD,
77  ISO7816_FILE_PREV_RECORD,
78 } Iso7816WrappedParams_t;
79 
80 extern Iso7816WrappedParams_t Iso7816P1Data;
81 extern Iso7816WrappedParams_t Iso7816P2Data;
82 extern bool Iso7816FileSelected;
83 extern uint8_t Iso7816FileOffset;
84 extern uint8_t Iso7816EfIdNumber;
85 
86 bool IsWrappedISO7816CommandType(uint8_t *Buffer, uint16_t ByteCount);
87 uint16_t SetIso7816WrappedParametersType(uint8_t *Buffer, uint16_t ByteCount);
88 
89 #endif
diff --git a/Doc/Doxygen/html/_d_e_s_fire_instructions_8h_source.html b/Doc/Doxygen/html/_d_e_s_fire_instructions_8h_source.html index 81da37da..c5f501e7 100644 --- a/Doc/Doxygen/html/_d_e_s_fire_instructions_8h_source.html +++ b/Doc/Doxygen/html/_d_e_s_fire_instructions_8h_source.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: DESFireInstructions.h Source File @@ -11,9 +12,6 @@ - @@ -31,40 +29,19 @@ - + - - + + + +
DESFireInstructions.h
-
1 /*
2 The DESFire stack portion of this firmware source
3 is free software written by Maxie Dion Schmidt (@maxieds):
4 You can redistribute it and/or modify
5 it under the terms of this license.
6 
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 
11 The complete source distribution of
12 this firmware is available at the following link:
13 https://github.com/maxieds/ChameleonMiniFirmwareDESFireStack.
14 
15 Based in part on the original DESFire code created by
16 @dev-zzo (GitHub handle) [Dmitry Janushkevich] available at
17 https://github.com/dev-zzo/ChameleonMini/tree/desfire.
18 
19 This notice must be retained at the top of all source files where indicated.
20 */
21 
22 /*
23  * DESFireInstructions.h :
24  * Maxie D. Schmidt (github.com/maxieds)
25  */
26 
27 #ifndef __DESFIRE_INS_COMMANDS_H__
28 #define __DESFIRE_INS_COMMANDS_H__
29 
30 #include "DESFireFirmwareSettings.h"
31 #include "DESFireCrypto.h"
32 
33 #define DESFIRE_VERSION1_BYTES_PROCESSED (8)
34 #define DESFIRE_VERSION2_BYTES_PROCESSED (8)
35 #define DESFIRE_VERSION3_BYTES_PROCESSED (15)
36 
37 typedef struct DESFIRE_FIRMWARE_PACKING {
38  uint8_t NextIndex;
39  uint8_t CryptoMethodType;
40  uint8_t ActiveCommMode;
41  uint8_t KeyId;
42  uint8_t RndB[CRYPTO_CHALLENGE_RESPONSE_BYTES] DESFIRE_FIRMWARE_ARRAY_ALIGNAT;
43 } DesfireSavedCommandStateType;
44 extern DesfireSavedCommandStateType DesfireCommandState;
45 
46 typedef struct DESFIRE_FIRMWARE_PACKING {
47  BYTE BytesProcessed;
48  BOOL IsComplete;
49 } TransferStatus;
50 
51 typedef enum DESFIRE_FIRMWARE_ENUM_PACKING {
52 
53  /* DESFire native command support: */
54  NO_COMMAND_TO_CONTINUE = 0x00,
55  CMD_AUTHENTICATE = 0x0A, /* Authenticate Legacy */
56  CMD_AUTHENTICATE_ISO = 0x1A,
57  CMD_AUTHENTICATE_AES = 0xAA,
58  CMD_AUTHENTICATE_EV2_FIRST = 0x71, /* See page 32 of AN12343.pdf */
59  CMD_AUTHENTICATE_EV2_NONFIRST = 0x77, /* See page 32 of AN12343.pdf */
60  CMD_CHANGE_KEY_SETTINGS = 0x54,
61  CMD_SET_CONFIGURATION = 0x5C,
62  CMD_CHANGE_KEY = 0xC4,
63  CMD_GET_KEY_VERSION = 0x64,
64  CMD_CREATE_APPLICATION = 0xCA,
65  CMD_DELETE_APPLICATION = 0xDA,
66  CMD_GET_APPLICATION_IDS = 0x6A,
67  CMD_FREE_MEMORY = 0x6E,
68  CMD_GET_DF_NAMES = 0x6D,
69  CMD_GET_KEY_SETTINGS = 0x45,
70  CMD_SELECT_APPLICATION = 0x5A,
71  CMD_FORMAT_PICC = 0xFC,
72  CMD_GET_VERSION = 0x60,
73  CMD_GET_CARD_UID = 0x51,
74  CMD_GET_FILE_IDS = 0x6F,
75  CMD_GET_FILE_SETTINGS = 0xF5,
76  CMD_CHANGE_FILE_SETTINGS = 0x5F,
77  CMD_CREATE_STDDATA_FILE = 0xCD,
78  CMD_CREATE_BACKUPDATA_FILE = 0xCB,
79  CMD_CREATE_VALUE_FILE = 0xCC,
80  CMD_CREATE_LINEAR_RECORD_FILE = 0xC1,
81  CMD_CREATE_CYCLIC_RECORD_FILE = 0xC0,
82  CMD_DELETE_FILE = 0xDF,
83  CMD_GET_ISO_FILE_IDS = 0x61,
84  CMD_READ_DATA = 0xBD,
85  CMD_WRITE_DATA = 0x3D,
86  CMD_GET_VALUE = 0x6C,
87  CMD_CREDIT = 0x0C,
88  CMD_DEBIT = 0xDC,
89  CMD_LIMITED_CREDIT = 0x1C,
90  CMD_WRITE_RECORD = 0x3B,
91  CMD_READ_RECORDS = 0xBB,
92  CMD_CLEAR_RECORD_FILE = 0xEB,
93  CMD_COMMIT_TRANSACTION = 0xC7,
94  CMD_ABORT_TRANSACTION = 0xA7,
95  CMD_CONTINUE = 0xAF,
96 
97  /* ISO7816 Command Set Support: */
98  CMD_ISO7816_SELECT = 0xA4,
99  CMD_ISO7816_GET_CHALLENGE = 0x84,
100  CMD_ISO7816_EXTERNAL_AUTHENTICATE = 0x82,
101  CMD_ISO7816_INTERNAL_AUTHENTICATE = 0x88,
102  CMD_ISO7816_READ_BINARY = 0xB0,
103  CMD_ISO7816_UPDATE_BINARY = 0xD6,
104  CMD_ISO7816_READ_RECORDS = 0xB2,
105  CMD_ISO7816_APPEND_RECORD = 0xE2,
106 
107  /* Space for undocumented command codes --
108  * Need command codes and parameters to make these work moving forward: */
109  //CMD_READ_SIGNATURE /* See page 87 of AN12343.pdf (for Mifare DESFire Light tags) */
110 
111 } DESFireCommandType;
112 
113 typedef uint16_t (*InsCodeHandlerFunc)(uint8_t *Buffer, uint16_t ByteCount);
114 
115 typedef struct {
116  DESFireCommandType insCode;
117  InsCodeHandlerFunc insFunc;
118  const __flash char *insDesc;
119 } DESFireCommand;
120 
121 extern const __flash DESFireCommand DESFireCommandSet[];
122 
123 /* Helper and batch process functions */
124 uint16_t CallInstructionHandler(uint8_t *Buffer, uint16_t ByteCount);
125 uint16_t ExitWithStatus(uint8_t *Buffer, uint8_t StatusCode, uint16_t DefaultReturnValue);
126 uint16_t CmdNotImplemented(uint8_t *Buffer, uint16_t ByteCount);
127 
128 /*
129  * The following section implements:
130  * DESFire EV0 / D40 specific commands
131  */
132 
133 /* General commands */
134 uint16_t EV0CmdGetVersion1(uint8_t *Buffer, uint16_t ByteCount);
135 uint16_t EV0CmdGetVersion2(uint8_t *Buffer, uint16_t ByteCount);
136 uint16_t EV0CmdGetVersion3(uint8_t *Buffer, uint16_t ByteCount);
137 uint16_t EV0CmdFormatPicc(uint8_t *Buffer, uint16_t ByteCount);
138 uint16_t DesfireCmdGetCardUID(uint8_t *Buffer, uint16_t ByteCount);
139 uint16_t DesfireCmdSetConfiguration(uint8_t *Buffer, uint16_t ByteCount); // ?? Docs ??
140 uint16_t DesfireCmdFreeMemory(uint8_t *Buffer, uint16_t ByteCount); // returns free memory on the tag
141 
142 /* Key management commands */
143 uint16_t EV0CmdChangeKey(uint8_t *Buffer, uint16_t ByteCount);
144 uint16_t EV0CmdGetKeySettings(uint8_t *Buffer, uint16_t ByteCount);
145 uint16_t EV0CmdChangeKeySettings(uint8_t *Buffer, uint16_t ByteCount);
146 uint16_t DesfireCmdGetKeyVersion(uint8_t *Buffer, uint16_t ByteCount);
147 
148 /* Application management commands */
149 uint16_t EV0CmdGetApplicationIds1(uint8_t *Buffer, uint16_t ByteCount);
150 uint16_t EV0CmdCreateApplication(uint8_t *Buffer, uint16_t ByteCount);
151 uint16_t EV0CmdDeleteApplication(uint8_t *Buffer, uint16_t ByteCount);
152 uint16_t EV0CmdSelectApplication(uint8_t *Buffer, uint16_t ByteCount);
153 uint16_t DesfireCmdGetDFNames(uint8_t *Buffer, uint16_t ByteCount);
154 
155 /* File management commands */
156 uint16_t EV0CmdCreateStandardDataFile(uint8_t *Buffer, uint16_t ByteCount);
157 uint16_t EV0CmdCreateBackupDataFile(uint8_t *Buffer, uint16_t ByteCount);
158 uint16_t EV0CmdCreateValueFile(uint8_t *Buffer, uint16_t ByteCount);
159 uint16_t EV0CmdCreateLinearRecordFile(uint8_t *Buffer, uint16_t ByteCount);
160 uint16_t EV0CmdCreateCyclicRecordFile(uint8_t *Buffer, uint16_t ByteCount);
161 uint16_t EV0CmdDeleteFile(uint8_t *Buffer, uint16_t ByteCount);
162 uint16_t EV0CmdGetFileIds(uint8_t *Buffer, uint16_t ByteCount);
163 uint16_t EV0CmdGetFileSettings(uint8_t *Buffer, uint16_t ByteCount);
164 uint16_t EV0CmdChangeFileSettings(uint8_t *Buffer, uint16_t ByteCount);
165 
166 /* Data manipulation commands */
167 // NOTE: Page 57: Read file functions:
168 uint16_t EV0CmdReadData(uint8_t *Buffer, uint16_t ByteCount);
169 uint16_t EV0CmdWriteData(uint8_t *Buffer, uint16_t ByteCount);
170 uint16_t EV0CmdGetValue(uint8_t *Buffer, uint16_t ByteCount);
171 uint16_t EV0CmdCredit(uint8_t *Buffer, uint16_t ByteCount);
172 uint16_t EV0CmdDebit(uint8_t *Buffer, uint16_t ByteCount);
173 uint16_t EV0CmdLimitedCredit(uint8_t *Buffer, uint16_t ByteCount);
174 uint16_t EV0CmdReadRecords(uint8_t *Buffer, uint16_t ByteCount);
175 uint16_t EV0CmdWriteRecord(uint8_t *Buffer, uint16_t ByteCount);
176 uint16_t EV0CmdClearRecords(uint8_t *Buffer, uint16_t ByteCount);
177 
178 /* Transaction handling commands */
179 uint16_t EV0CmdCommitTransaction(uint8_t *Buffer, uint16_t ByteCount);
180 uint16_t EV0CmdAbortTransaction(uint8_t *Buffer, uint16_t ByteCount);
181 
182 /* EV1/EV2 supported commands */
183 uint16_t EV0CmdAuthenticateLegacy1(uint8_t *Buffer, uint16_t ByteCount);
184 uint16_t EV0CmdAuthenticateLegacy2(uint8_t *Buffer, uint16_t ByteCount);
185 uint16_t DesfireCmdAuthenticate3KTDEA1(uint8_t *Buffer, uint16_t ByteCount);
186 uint16_t DesfireCmdAuthenticate3KTDEA2(uint8_t *Buffer, uint16_t ByteCount);
187 uint16_t DesfireCmdAuthenticateAES1(uint8_t *Buffer, uint16_t ByteCount);
188 uint16_t DesfireCmdAuthenticateAES2(uint8_t *Buffer, uint16_t ByteCount);
189 
190 /* ISO7816 command handling */
191 uint16_t ISO7816CmdSelect(uint8_t *Buffer, uint16_t ByteCount);
192 uint16_t ISO7816CmdSelectEF(uint8_t *Buffer, uint16_t ByteCount);
193 uint16_t ISO7816CmdSelectDF(uint8_t *Buffer, uint16_t ByteCount);
194 uint16_t ISO7816CmdGetChallenge(uint8_t *Buffer, uint16_t ByteCount);
195 uint16_t ISO7816CmdExternalAuthenticate(uint8_t *Buffer, uint16_t ByteCount);
196 uint16_t ISO7816CmdInternalAuthenticate(uint8_t *Buffer, uint16_t ByteCount);
197 uint16_t ISO7816CmdReadBinary(uint8_t *Buffer, uint16_t ByteCount);
198 uint16_t ISO7816CmdUpdateBinary(uint8_t *Buffer, uint16_t ByteCount);
199 uint16_t ISO7816CmdReadRecords(uint8_t *Buffer, uint16_t ByteCount);
200 uint16_t ISO7816CmdAppendRecord(uint8_t *Buffer, uint16_t ByteCount);
201 
202 #endif
+
1 /*
2 The DESFire stack portion of this firmware source
3 is free software written by Maxie Dion Schmidt (@maxieds):
4 You can redistribute it and/or modify
5 it under the terms of this license.
6 
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 
11 The complete source distribution of
12 this firmware is available at the following link:
13 https://github.com/maxieds/ChameleonMiniFirmwareDESFireStack.
14 
15 Based in part on the original DESFire code created by
16 @dev-zzo (GitHub handle) [Dmitry Janushkevich] available at
17 https://github.com/dev-zzo/ChameleonMini/tree/desfire.
18 
19 This notice must be retained at the top of all source files where indicated.
20 */
21 
22 /*
23  * DESFireInstructions.h :
24  * Maxie D. Schmidt (github.com/maxieds)
25  */
26 
27 #ifndef __DESFIRE_INS_COMMANDS_H__
28 #define __DESFIRE_INS_COMMANDS_H__
29 
30 #include "DESFireFirmwareSettings.h"
31 #include "DESFireCrypto.h"
32 
33 #define DESFIRE_VERSION1_BYTES_PROCESSED (8)
34 #define DESFIRE_VERSION2_BYTES_PROCESSED (8)
35 #define DESFIRE_VERSION3_BYTES_PROCESSED (15)
36 
37 typedef struct DESFIRE_FIRMWARE_PACKING {
38  uint8_t NextIndex;
39  uint8_t CryptoMethodType;
40  uint8_t ActiveCommMode;
41  uint8_t KeyId;
42  uint8_t RndB[CRYPTO_CHALLENGE_RESPONSE_BYTES] DESFIRE_FIRMWARE_ARRAY_ALIGNAT;
43 } DesfireSavedCommandStateType;
44 extern DesfireSavedCommandStateType DesfireCommandState;
45 
46 typedef struct DESFIRE_FIRMWARE_PACKING {
47  BYTE BytesProcessed;
48  BOOL IsComplete;
49 } TransferStatus;
50 
51 typedef enum DESFIRE_FIRMWARE_ENUM_PACKING {
52 
53  /* DESFire native command support: */
54  NO_COMMAND_TO_CONTINUE = 0x00,
55  CMD_AUTHENTICATE = 0x0A, /* Authenticate Legacy */
56  CMD_AUTHENTICATE_ISO = 0x1A,
57  CMD_AUTHENTICATE_AES = 0xAA,
58  CMD_AUTHENTICATE_EV2_FIRST = 0x71, /* See page 32 of AN12343.pdf */
59  CMD_AUTHENTICATE_EV2_NONFIRST = 0x77, /* See page 32 of AN12343.pdf */
60  CMD_CHANGE_KEY_SETTINGS = 0x54,
61  CMD_SET_CONFIGURATION = 0x5C,
62  CMD_CHANGE_KEY = 0xC4,
63  CMD_GET_KEY_VERSION = 0x64,
64  CMD_CREATE_APPLICATION = 0xCA,
65  CMD_DELETE_APPLICATION = 0xDA,
66  CMD_GET_APPLICATION_IDS = 0x6A,
67  CMD_FREE_MEMORY = 0x6E,
68  CMD_GET_DF_NAMES = 0x6D,
69  CMD_GET_KEY_SETTINGS = 0x45,
70  CMD_SELECT_APPLICATION = 0x5A,
71  CMD_FORMAT_PICC = 0xFC,
72  CMD_GET_VERSION = 0x60,
73  CMD_GET_CARD_UID = 0x51,
74  CMD_GET_FILE_IDS = 0x6F,
75  CMD_GET_FILE_SETTINGS = 0xF5,
76  CMD_CHANGE_FILE_SETTINGS = 0x5F,
77  CMD_CREATE_STDDATA_FILE = 0xCD,
78  CMD_CREATE_BACKUPDATA_FILE = 0xCB,
79  CMD_CREATE_VALUE_FILE = 0xCC,
80  CMD_CREATE_LINEAR_RECORD_FILE = 0xC1,
81  CMD_CREATE_CYCLIC_RECORD_FILE = 0xC0,
82  CMD_DELETE_FILE = 0xDF,
83  CMD_GET_ISO_FILE_IDS = 0x61,
84  CMD_READ_DATA = 0xBD,
85  CMD_WRITE_DATA = 0x3D,
86  CMD_GET_VALUE = 0x6C,
87  CMD_CREDIT = 0x0C,
88  CMD_DEBIT = 0xDC,
89  CMD_LIMITED_CREDIT = 0x1C,
90  CMD_WRITE_RECORD = 0x3B,
91  CMD_READ_RECORDS = 0xBB,
92  CMD_CLEAR_RECORD_FILE = 0xEB,
93  CMD_COMMIT_TRANSACTION = 0xC7,
94  CMD_ABORT_TRANSACTION = 0xA7,
95  CMD_CONTINUE = 0xAF,
96 
97  /* ISO7816 Command Set Support: */
98  CMD_ISO7816_SELECT = 0xA4,
99  CMD_ISO7816_GET_CHALLENGE = 0x84,
100  CMD_ISO7816_EXTERNAL_AUTHENTICATE = 0x82,
101  CMD_ISO7816_INTERNAL_AUTHENTICATE = 0x88,
102  CMD_ISO7816_READ_BINARY = 0xB0,
103  CMD_ISO7816_UPDATE_BINARY = 0xD6,
104  CMD_ISO7816_READ_RECORDS = 0xB2,
105  CMD_ISO7816_APPEND_RECORD = 0xE2,
106 
107  /* Space for undocumented command codes --
108  * Need command codes and parameters to make these work moving forward: */
109  //CMD_READ_SIGNATURE /* See page 87 of AN12343.pdf (for Mifare DESFire Light tags) */
110 
111 } DESFireCommandType;
112 
113 typedef uint16_t (*InsCodeHandlerFunc)(uint8_t *Buffer, uint16_t ByteCount);
114 
115 typedef struct {
116  DESFireCommandType insCode;
117  InsCodeHandlerFunc insFunc;
118  const __flash char *insDesc;
119 } DESFireCommand;
120 
121 extern const __flash DESFireCommand DESFireCommandSet[];
122 
123 /* Helper and batch process functions */
124 uint16_t CallInstructionHandler(uint8_t *Buffer, uint16_t ByteCount);
125 uint16_t ExitWithStatus(uint8_t *Buffer, uint8_t StatusCode, uint16_t DefaultReturnValue);
126 uint16_t CmdNotImplemented(uint8_t *Buffer, uint16_t ByteCount);
127 
128 /*
129  * The following section implements:
130  * DESFire EV0 / D40 specific commands
131  */
132 
133 /* General commands */
134 uint16_t EV0CmdGetVersion1(uint8_t *Buffer, uint16_t ByteCount);
135 uint16_t EV0CmdGetVersion2(uint8_t *Buffer, uint16_t ByteCount);
136 uint16_t EV0CmdGetVersion3(uint8_t *Buffer, uint16_t ByteCount);
137 uint16_t EV0CmdFormatPicc(uint8_t *Buffer, uint16_t ByteCount);
138 uint16_t DesfireCmdGetCardUID(uint8_t *Buffer, uint16_t ByteCount);
139 uint16_t DesfireCmdSetConfiguration(uint8_t *Buffer, uint16_t ByteCount); // ?? Docs ??
140 uint16_t DesfireCmdFreeMemory(uint8_t *Buffer, uint16_t ByteCount); // returns free memory on the tag
141 
142 /* Key management commands */
143 uint16_t EV0CmdChangeKey(uint8_t *Buffer, uint16_t ByteCount);
144 uint16_t EV0CmdGetKeySettings(uint8_t *Buffer, uint16_t ByteCount);
145 uint16_t EV0CmdChangeKeySettings(uint8_t *Buffer, uint16_t ByteCount);
146 uint16_t DesfireCmdGetKeyVersion(uint8_t *Buffer, uint16_t ByteCount);
147 
148 /* Application management commands */
149 uint16_t EV0CmdGetApplicationIds1(uint8_t *Buffer, uint16_t ByteCount);
150 uint16_t EV0CmdCreateApplication(uint8_t *Buffer, uint16_t ByteCount);
151 uint16_t EV0CmdDeleteApplication(uint8_t *Buffer, uint16_t ByteCount);
152 uint16_t EV0CmdSelectApplication(uint8_t *Buffer, uint16_t ByteCount);
153 uint16_t DesfireCmdGetDFNames(uint8_t *Buffer, uint16_t ByteCount);
154 
155 /* File management commands */
156 uint16_t EV0CmdCreateStandardDataFile(uint8_t *Buffer, uint16_t ByteCount);
157 uint16_t EV0CmdCreateBackupDataFile(uint8_t *Buffer, uint16_t ByteCount);
158 uint16_t EV0CmdCreateValueFile(uint8_t *Buffer, uint16_t ByteCount);
159 uint16_t EV0CmdCreateLinearRecordFile(uint8_t *Buffer, uint16_t ByteCount);
160 uint16_t EV0CmdCreateCyclicRecordFile(uint8_t *Buffer, uint16_t ByteCount);
161 uint16_t EV0CmdDeleteFile(uint8_t *Buffer, uint16_t ByteCount);
162 uint16_t EV0CmdGetFileIds(uint8_t *Buffer, uint16_t ByteCount);
163 uint16_t EV0CmdGetFileSettings(uint8_t *Buffer, uint16_t ByteCount);
164 uint16_t EV0CmdChangeFileSettings(uint8_t *Buffer, uint16_t ByteCount);
165 
166 /* Data manipulation commands */
167 // NOTE: Page 57: Read file functions:
168 uint16_t EV0CmdReadData(uint8_t *Buffer, uint16_t ByteCount);
169 uint16_t EV0CmdWriteData(uint8_t *Buffer, uint16_t ByteCount);
170 uint16_t EV0CmdGetValue(uint8_t *Buffer, uint16_t ByteCount);
171 uint16_t EV0CmdCredit(uint8_t *Buffer, uint16_t ByteCount);
172 uint16_t EV0CmdDebit(uint8_t *Buffer, uint16_t ByteCount);
173 uint16_t EV0CmdLimitedCredit(uint8_t *Buffer, uint16_t ByteCount);
174 uint16_t EV0CmdReadRecords(uint8_t *Buffer, uint16_t ByteCount);
175 uint16_t EV0CmdWriteRecord(uint8_t *Buffer, uint16_t ByteCount);
176 uint16_t EV0CmdClearRecords(uint8_t *Buffer, uint16_t ByteCount);
177 
178 /* Transaction handling commands */
179 uint16_t EV0CmdCommitTransaction(uint8_t *Buffer, uint16_t ByteCount);
180 uint16_t EV0CmdAbortTransaction(uint8_t *Buffer, uint16_t ByteCount);
181 
182 /* EV1/EV2 supported commands */
183 uint16_t EV0CmdAuthenticateLegacy1(uint8_t *Buffer, uint16_t ByteCount);
184 uint16_t EV0CmdAuthenticateLegacy2(uint8_t *Buffer, uint16_t ByteCount);
185 uint16_t DesfireCmdAuthenticate3KTDEA1(uint8_t *Buffer, uint16_t ByteCount);
186 uint16_t DesfireCmdAuthenticate3KTDEA2(uint8_t *Buffer, uint16_t ByteCount);
187 uint16_t DesfireCmdAuthenticateAES1(uint8_t *Buffer, uint16_t ByteCount);
188 uint16_t DesfireCmdAuthenticateAES2(uint8_t *Buffer, uint16_t ByteCount);
189 
190 /* ISO7816 command handling */
191 uint16_t ISO7816CmdSelect(uint8_t *Buffer, uint16_t ByteCount);
192 uint16_t ISO7816CmdSelectEF(uint8_t *Buffer, uint16_t ByteCount);
193 uint16_t ISO7816CmdSelectDF(uint8_t *Buffer, uint16_t ByteCount);
194 uint16_t ISO7816CmdGetChallenge(uint8_t *Buffer, uint16_t ByteCount);
195 uint16_t ISO7816CmdExternalAuthenticate(uint8_t *Buffer, uint16_t ByteCount);
196 uint16_t ISO7816CmdInternalAuthenticate(uint8_t *Buffer, uint16_t ByteCount);
197 uint16_t ISO7816CmdReadBinary(uint8_t *Buffer, uint16_t ByteCount);
198 uint16_t ISO7816CmdUpdateBinary(uint8_t *Buffer, uint16_t ByteCount);
199 uint16_t ISO7816CmdReadRecords(uint8_t *Buffer, uint16_t ByteCount);
200 uint16_t ISO7816CmdAppendRecord(uint8_t *Buffer, uint16_t ByteCount);
201 
202 #endif
diff --git a/Doc/Doxygen/html/_d_e_s_fire_logging_8h_source.html b/Doc/Doxygen/html/_d_e_s_fire_logging_8h_source.html index a5b051b4..56e2af64 100644 --- a/Doc/Doxygen/html/_d_e_s_fire_logging_8h_source.html +++ b/Doc/Doxygen/html/_d_e_s_fire_logging_8h_source.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: DESFireLogging.h Source File @@ -11,9 +12,6 @@ - @@ -31,40 +29,19 @@ - + - - + + + +
DESFireLogging.h
-
1 /*
2 The DESFire stack portion of this firmware source
3 is free software written by Maxie Dion Schmidt (@maxieds):
4 You can redistribute it and/or modify
5 it under the terms of this license.
6 
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 
11 The complete source distribution of
12 this firmware is available at the following link:
13 https://github.com/maxieds/ChameleonMiniFirmwareDESFireStack.
14 
15 Based in part on the original DESFire code created by
16 @dev-zzo (GitHub handle) [Dmitry Janushkevich] available at
17 https://github.com/dev-zzo/ChameleonMini/tree/desfire.
18 
19 This notice must be retained at the top of all source files where indicated.
20 */
21 
22 /*
23  * DESFireLogging.h :
24  * Maxie D. Schmidt (github.com/maxieds)
25  */
26 
27 #ifndef __DESFIRE_LOGGING_UTILS_H__
28 #define __DESFIRE_LOGGING_UTILS_H__
29 
30 #include "../../Log.h"
31 #include "../../Common.h"
32 #include "DESFireFirmwareSettings.h"
33 #include "DESFireMemoryOperations.h"
34 
35 #ifndef DESFIRE_MIN_INCOMING_LOGSIZE
36  #define DESFIRE_MIN_INCOMING_LOGSIZE (1)
37 #endif
38 #ifndef DESFIRE_MIN_OUTGOING_LOGSIZE
39  #define DESFIRE_MIN_OUTGOING_LOGSIZE (1)
40 #endif
41 
42 INLINE void DesfireLogEntry(LogEntryEnum LogCode, void *LogDataBuffer, uint16_t BufSize) {
43  if(DESFIRE_MIN_OUTGOING_LOGSIZE <= BufSize) {
44  LogEntry(LogCode, LogDataBuffer, BufSize);
45  }
46 }
47 
48 typedef enum DESFIRE_FIRMWARE_ENUM_PACKING {
49  OFF = 0,
50  NORMAL = 1,
51  VERBOSE = 2,
52  DEBUGGING = 3,
53 } DESFireLoggingMode;
54 
55 extern DESFireLoggingMode LocalLoggingMode;
56 
57 /*
58  * This variable can be toggled to indicated whether to employ
59  * testable pseudo-randomness in the encrypted transfers.
60  * When this value id non-zero, then any random session numbers
61  * (e.g., RndB) and IV salt vectors should default back to
62  * predictable constant values for testing purposes.
63  */
64 extern BYTE LocalTestingMode;
65 
66 void DESFireLogErrorMessage(char *fmtMsg, ...);
67 void DESFireLogStatus(BYTE *bufMsg, SIZET bufSize);
68 void DESFireLogDebuggingMessage(char *fmtMsg, ...);
69 void DESFireLogSourceCodeTODO(char *implNoteMsg, char *srcFileLoggingData);
70 void DESFireLogIncomingData(BYTE *byteBuf, SIZET bufLength);
71 void DESFireLogOutgoingData(BYTE *byteBuf, SIZET bufLength);
72 void DESFireLogNativeCommand(BYTE *Buffer, SIZET ByteCount);
73 void DESFireLogISO1443Command(BYTE *Buffer, SIZET ByteCount);
74 void DESFireLogISO7816Command(BYTE *Buffer, SIZET ByteCount);
75 void DESFireLogSetProtectedData(BYTE *pdataBuf, SIZET byteBufSize);
76 void DESFireLogPICCHardReset(BYTE *strBuf, SIZET strLength);
77 void DESFireLogPICCSoftReset(BYTE *strBuf, SIZET strLength);
78 
79 void DebugPrintP(const char *fmt, ...);
80 #define DEBUG_PRINT(fmt, ...) \
81  DebugPrintP(PSTR(fmt), ##__VA_ARGS__)
82 
83 #define DEBUG_PRINT_P(fmtStr, ...) ({ \
84  uint8_t logLength = 0; \
85  do { \
86  snprintf_P(__InternalStringBuffer, STRING_BUFFER_SIZE, \
87  fmtStr, ##__VA_ARGS__); \
88  logLength = StringLength(__InternalStringBuffer, \
89  STRING_BUFFER_SIZE); \
90  DesfireLogEntry(LOG_ERR_DESFIRE_GENERIC_ERROR, \
91  __InternalStringBuffer, logLength); \
92  } while(0); \
93  })
94 
95 #define GetSourceFileLoggingData() ({ \
96  char *strBuffer; \
97  do { \
98  snprintf_P(__InternalStringBuffer, STRING_BUFFER_SIZE, \
99  PSTR("@@ LINE #%d in *%s @@"), \
100  __LINE__, __FILE__); \
101  __InternalStringBuffer[STRING_BUFFER_SIZE - 1] = '\0'; \
102  } while(0); \
103  strBuffer = __InternalStringBuffer; \
104  strBuffer; \
105  })
106 
107 #define GetSymbolNameString(symbolName) ({ \
108  char *strBuffer; \
109  do { \
110  strncpy_P(__InternalStringBuffer2, PSTR(#symbolName), \
111  DATA_BUFFER_SIZE_SMALL); \
112  } while(0); \
113  strBuffer = __InternalStringBuffer2; \
114  strBuffer; \
115  })
116 
117 #define GetHexBytesString(byteArray, arrSize) ({ \
118  char *strBuffer; \
119  do { \
120  BufferToHexString(__InternalStringBuffer, \
121  STRING_BUFFER_SIZE, \
122  byteArray, arrSize); \
123  __InternalStringBuffer[STRING_BUFFER_SIZE - 1] = '\0'; \
124  } while(0); \
125  strBuffer = __InternalStringBuffer; \
126  strBuffer; \
127  })
128 
129 #define LogDebuggingMsg(msg) ({ \
130  char *strBuffer; \
131  do { \
132  strncpy_P(__InternalStringBuffer, msg, STRING_BUFFER_SIZE); \
133  uint8_t sbufLength = StringLength(__InternalStringBuffer, STRING_BUFFER_SIZE); \
134  LogEntry(LOG_INFO_DESFIRE_OUTGOING_DATA, (void *) __InternalStringBuffer, \
135  sbufLength); \
136  } while(0); \
137  strBuffer = __InternalStringBuffer; \
138  strBuffer; \
139  })
140 
141 //#define DesfireLogIncoming(incBuf, bitCount) ({ \
142  uint8_t logLength = 0; \
143  do { \
144  logLength = BufferToHexString(__InternalStringBuffer, STRING_BUFFER_SIZE, \
145  incBuf, (bitCount + 7) / 8); \
146  snprintf_P(__InternalStringBuffer + logLength, PSTR(" [#=%d] <-- IN"), \
147  bitCount); \
148  logLength = StringLength(__InternalStringBuffer, STRING_BUFFER_SIZE); \
149  DesfireLogEntry(LOG_INFO_DESFIRE_INCOMING_DATA, __InternalStringBuffer, logLength); \
150  } while(0); \
151  })
152 
153 //#define DesfireLogOutgoing(incBuf, bitCount) ({ \
154  uint8_t logLength = 0; \
155  do { \
156  logLength = BufferToHexString(__InternalStringBuffer, STRING_BUFFER_SIZE, \
157  incBuf, (bitCount + 7) / 8); \
158  snprintf_P(__InternalStringBuffer + logLength, PSTR(" [#=%d] --> OUT"), \
159  bitCount); \
160  logLength = StringLength(__InternalStringBuffer, STRING_BUFFER_SIZE); \
161  DesfireLogEntry(LOG_INFO_DESFIRE_OUTGOING_DATA, __InternalStringBuffer, logLength); \
162  } while(0); \
163  })
164 
165 #define DesfireLogISOStateChange(state, logCode)
166 //#define DesfireLogISOStateChange(state, logCode) ({ \
167  const char *stateSymbName = NULL; \
168  uint8_t logLength = 0x00; \
169  do { \
170  switch(state) { \
171  case ISO14443_3A_STATE_IDLE: \
172  stateSymbName = PSTR("ISO14443_3A_STATE_IDLE"); \
173  break; \
174  case ISO14443_3A_STATE_READY1: \
175  stateSymbName = PSTR("ISO14443_3A_STATE_READY1"); \
176  break; \
177  case ISO14443_3A_STATE_READY2: \
178  stateSymbName = PSTR("ISO14443_3A_STATE_READY2"); \
179  break; \
180  case ISO14443_3A_STATE_ACTIVE: \
181  stateSymbName = PSTR("ISO14443_3A_STATE_ACTIVE"); \
182  break; \
183  case ISO14443_3A_STATE_HALT: \
184  stateSymbName = PSTR("ISO14443_3A_STATE_HALT"); \
185  break; \
186  case ISO14443_4_STATE_EXPECT_RATS: \
187  stateSymbName = PSTR("ISO14443_4_STATE_EXPECT_RATS"); \
188  break; \
189  case ISO14443_4_STATE_ACTIVE: \
190  stateSymbName = PSTR("ISO14443_4_STATE_ACTIVE"); \
191  break; \
192  default: \
193  stateSymbName = PSTR("UNKNOWN_STATE"); \
194  break; \
195  } \
196  snprintf_P(__InternalStringBuffer, STRING_BUFFER_SIZE, PSTR(" => ")); \
197  strcat_P(__InternalStringBuffer, stateSymbName); \
198  logLength = StringLength(__InternalStringBuffer, STRING_BUFFER_SIZE); \
199  DesfireLogEntry(logCode, __InternalStringBuffer, logLength); \
200  } while(0); \
201  })
202 
203 #endif
LogEntryEnum
Definition: Log.h:16
+
1 /*
2 The DESFire stack portion of this firmware source
3 is free software written by Maxie Dion Schmidt (@maxieds):
4 You can redistribute it and/or modify
5 it under the terms of this license.
6 
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 
11 The complete source distribution of
12 this firmware is available at the following link:
13 https://github.com/maxieds/ChameleonMiniFirmwareDESFireStack.
14 
15 Based in part on the original DESFire code created by
16 @dev-zzo (GitHub handle) [Dmitry Janushkevich] available at
17 https://github.com/dev-zzo/ChameleonMini/tree/desfire.
18 
19 This notice must be retained at the top of all source files where indicated.
20 */
21 
22 /*
23  * DESFireLogging.h :
24  * Maxie D. Schmidt (github.com/maxieds)
25  */
26 
27 #ifndef __DESFIRE_LOGGING_UTILS_H__
28 #define __DESFIRE_LOGGING_UTILS_H__
29 
30 #include "../../Log.h"
31 #include "../../Common.h"
32 #include "DESFireFirmwareSettings.h"
33 #include "DESFireMemoryOperations.h"
34 
35 #ifndef DESFIRE_MIN_INCOMING_LOGSIZE
36 #define DESFIRE_MIN_INCOMING_LOGSIZE (1)
37 #endif
38 #ifndef DESFIRE_MIN_OUTGOING_LOGSIZE
39 #define DESFIRE_MIN_OUTGOING_LOGSIZE (1)
40 #endif
41 
42 INLINE void DesfireLogEntry(LogEntryEnum LogCode, void *LogDataBuffer, uint16_t BufSize) {
43  if (DESFIRE_MIN_OUTGOING_LOGSIZE <= BufSize) {
44  LogEntry(LogCode, (void *) LogDataBuffer, BufSize);
45  }
46 }
47 
48 typedef enum DESFIRE_FIRMWARE_ENUM_PACKING {
49  OFF = 0,
50  NORMAL = 1,
51  VERBOSE = 2,
52  DEBUGGING = 3,
53 } DESFireLoggingMode;
54 
55 extern DESFireLoggingMode LocalLoggingMode;
56 
57 /*
58  * This variable can be toggled to indicated whether to employ
59  * testable pseudo-randomness in the encrypted transfers.
60  * When this value id non-zero, then any random session numbers
61  * (e.g., RndB) and IV salt vectors should default back to
62  * predictable constant values for testing purposes.
63  */
64 extern BYTE LocalTestingMode;
65 
66 void DESFireLogErrorMessage(char *fmtMsg, ...);
67 void DESFireLogStatus(BYTE *bufMsg, SIZET bufSize);
68 void DESFireLogDebuggingMessage(char *fmtMsg, ...);
69 void DESFireLogSourceCodeTODO(char *implNoteMsg, char *srcFileLoggingData);
70 void DESFireLogIncomingData(BYTE *byteBuf, SIZET bufLength);
71 void DESFireLogOutgoingData(BYTE *byteBuf, SIZET bufLength);
72 void DESFireLogNativeCommand(BYTE *Buffer, SIZET ByteCount);
73 void DESFireLogISO1443Command(BYTE *Buffer, SIZET ByteCount);
74 void DESFireLogISO7816Command(BYTE *Buffer, SIZET ByteCount);
75 void DESFireLogSetProtectedData(BYTE *pdataBuf, SIZET byteBufSize);
76 void DESFireLogPICCHardReset(BYTE *strBuf, SIZET strLength);
77 void DESFireLogPICCSoftReset(BYTE *strBuf, SIZET strLength);
78 
79 void DebugPrintP(const char *fmt, ...);
80 #define DEBUG_PRINT(fmt, ...) DebugPrintP(PSTR(fmt), ##__VA_ARGS__)
81 
82 #define DEBUG_PRINT_P(fmtStr, ...) ({ \
83  uint8_t logLength = 0; \
84  do { \
85  snprintf_P((char *) __InternalStringBuffer, STRING_BUFFER_SIZE, \
86  fmtStr, ##__VA_ARGS__); \
87  logLength = StringLength((char *) __InternalStringBuffer, \
88  STRING_BUFFER_SIZE); \
89  DesfireLogEntry(LOG_ERR_DESFIRE_GENERIC_ERROR, \
90  (char *) __InternalStringBuffer, logLength); \
91  } while(0); \
92  })
93 
94 #define GetSourceFileLoggingData() ({ \
95  char *strBuffer; \
96  do { \
97  snprintf_P(__InternalStringBuffer, STRING_BUFFER_SIZE, \
98  PSTR("@@ LINE #%d in *%s @@"), \
99  __LINE__, __FILE__); \
100  __InternalStringBuffer[STRING_BUFFER_SIZE - 1] = '\0'; \
101  } while(0); \
102  strBuffer = __InternalStringBuffer; \
103  strBuffer; \
104  })
105 
106 #define GetSymbolNameString(symbolName) ({ \
107  char *strBuffer; \
108  do { \
109  strncpy_P(__InternalStringBuffer2, PSTR(#symbolName), \
110  DATA_BUFFER_SIZE_SMALL); \
111  } while(0); \
112  strBuffer = __InternalStringBuffer2; \
113  strBuffer; \
114  })
115 
116 #define GetHexBytesString(byteArray, arrSize) ({ \
117  char *strBuffer; \
118  do { \
119  BufferToHexString(__InternalStringBuffer, \
120  STRING_BUFFER_SIZE, \
121  byteArray, arrSize); \
122  __InternalStringBuffer[STRING_BUFFER_SIZE - 1] = '\0'; \
123  } while(0); \
124  strBuffer = __InternalStringBuffer; \
125  strBuffer; \
126  })
127 
128 #if defined(DESFIRE_DEFAULT_LOGGING_MODE) && DESFIRE_DEFAULT_LOGGING_MODE != 0
129 #define LogDebuggingMsg(msg) ({ \
130  do { \
131  strncpy_P((char *) __InternalStringBuffer, msg, STRING_BUFFER_SIZE); \
132  uint8_t sbufLength = StringLength((char *) __InternalStringBuffer, STRING_BUFFER_SIZE); \
133  LogEntry(LOG_INFO_DESFIRE_OUTGOING_DATA, (void *) __InternalStringBuffer, \
134  sbufLength); \
135  } while(0); \
136  })
137 #else
138 #define LogDebuggingMsg(msg) ({})
139 #endif
140 
141 /*#define DesfireLogIncoming(incBuf, bitCount) ({ \
142  uint8_t logLength = 0; \
143  do { \
144  logLength = BufferToHexString(__InternalStringBuffer, STRING_BUFFER_SIZE, \
145  incBuf, (bitCount + 7) / 8); \
146  snprintf_P(__InternalStringBuffer + logLength, PSTR(" [#=%d] <-- IN"), \
147  bitCount); \
148  logLength = StringLength(__InternalStringBuffer, STRING_BUFFER_SIZE); \
149  DesfireLogEntry(LOG_INFO_DESFIRE_INCOMING_DATA, __InternalStringBuffer, logLength); \
150  } while(0); \
151  })
152 
153 #define DesfireLogOutgoing(incBuf, bitCount) ({ \
154  uint8_t logLength = 0; \
155  do { \
156  logLength = BufferToHexString(__InternalStringBuffer, STRING_BUFFER_SIZE, \
157  incBuf, (bitCount + 7) / 8); \
158  snprintf_P(__InternalStringBuffer + logLength, PSTR(" [#=%d] --> OUT"), \
159  bitCount); \
160  logLength = StringLength(__InternalStringBuffer, STRING_BUFFER_SIZE); \
161  DesfireLogEntry(LOG_INFO_DESFIRE_OUTGOING_DATA, __InternalStringBuffer, logLength); \
162  } while(0); \
163  })
164 */
165 
166 #define DesfireLogISOStateChange(state, logCode) ({})
167 /*#define DesfireLogISOStateChange(state, logCode) ({ \
168  const char *stateSymbName = NULL; \
169  uint8_t logLength = 0x00; \
170  do { \
171  switch(state) { \
172  case ISO14443_3A_STATE_IDLE: \
173  stateSymbName = PSTR("ISO14443_3A_STATE_IDLE"); \
174  break; \
175  case ISO14443_3A_STATE_READY1: \
176  stateSymbName = PSTR("ISO14443_3A_STATE_READY1"); \
177  break; \
178  case ISO14443_3A_STATE_READY2: \
179  stateSymbName = PSTR("ISO14443_3A_STATE_READY2"); \
180  break; \
181  case ISO14443_3A_STATE_ACTIVE: \
182  stateSymbName = PSTR("ISO14443_3A_STATE_ACTIVE"); \
183  break; \
184  case ISO14443_3A_STATE_HALT: \
185  stateSymbName = PSTR("ISO14443_3A_STATE_HALT"); \
186  break; \
187  case ISO14443_4_STATE_EXPECT_RATS: \
188  stateSymbName = PSTR("ISO14443_4_STATE_EXPECT_RATS"); \
189  break; \
190  case ISO14443_4_STATE_ACTIVE: \
191  stateSymbName = PSTR("ISO14443_4_STATE_ACTIVE"); \
192  break; \
193  default: \
194  stateSymbName = PSTR("UNKNOWN_STATE"); \
195  break; \
196  } \
197  snprintf_P(__InternalStringBuffer, STRING_BUFFER_SIZE, PSTR(" => ")); \
198  strcat_P(__InternalStringBuffer, stateSymbName); \
199  logLength = StringLength(__InternalStringBuffer, STRING_BUFFER_SIZE); \
200  DesfireLogEntry(logCode, __InternalStringBuffer, logLength); \
201  } while(0); \
202  })
203 */
204 
205 #endif
LogEntryEnum
Definition: Log.h:16
diff --git a/Doc/Doxygen/html/_d_e_s_fire_memory_operations_8h_source.html b/Doc/Doxygen/html/_d_e_s_fire_memory_operations_8h_source.html index 6cd5a4f4..b78a0d46 100644 --- a/Doc/Doxygen/html/_d_e_s_fire_memory_operations_8h_source.html +++ b/Doc/Doxygen/html/_d_e_s_fire_memory_operations_8h_source.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: DESFireMemoryOperations.h Source File @@ -11,9 +12,6 @@ - @@ -31,40 +29,19 @@
- + - - + + + +
DESFireMemoryOperations.h
-
1 /*
2 The DESFire stack portion of this firmware source
3 is free software written by Maxie Dion Schmidt (@maxieds):
4 You can redistribute it and/or modify
5 it under the terms of this license.
6 
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 
11 The complete source distribution of
12 this firmware is available at the following link:
13 https://github.com/maxieds/ChameleonMiniFirmwareDESFireStack.
14 
15 Based in part on the original DESFire code created by
16 @dev-zzo (GitHub handle) [Dmitry Janushkevich] available at
17 https://github.com/dev-zzo/ChameleonMini/tree/desfire.
18 
19 This notice must be retained at the top of all source files where indicated.
20 */
21 
22 /*
23  * DESFireMemoryOperations.h :
24  * Maxie D. Schmidt (github.com/maxieds)
25  */
26 
27 #ifndef __DESFIRE_MEMORY_OPERATIONS_H__
28 #define __DESFIRE_MEMORY_OPERATIONS_H__
29 
30 #include "DESFireFirmwareSettings.h"
31 #include "DESFireLogging.h"
32 
33 /* Reserve some space on the stack (text / data segment) for intermediate
34  storage of strings and data we need to write so we do not have to rely
35  on a bothersome heap-based scheme for passing pointers to functions: */
36 #define DATA_BUFFER_SIZE_SMALL (32)
37 #define STRING_BUFFER_SIZE (92)
38 extern volatile char __InternalStringBuffer[STRING_BUFFER_SIZE];
39 extern char __InternalStringBuffer2[DATA_BUFFER_SIZE_SMALL];
40 
41 /*
42  * EEPROM and FRAM memory management routines:
43  */
44 void ReadBlockBytes(void *Buffer, SIZET StartBlock, SIZET Count);
45 
46 void WriteBlockBytesMain(const void *Buffer, SIZET StartBlock, SIZET Count);
47 //#define WriteBlockBytes(Buffer, StartBlock, Count) ({ \
48  snprintf_P(__InternalStringBuffer2, DATA_BUFFER_SIZE_SMALL, \
49  PSTR("%s @ %d"), __func__, __LINE__); \
50  __InternalStringBuffer2[DATA_BUFFER_SIZE_SMALL - 1] = '\0'; \
51  WriteBlockBytesMain(Buffer, StartBlock, Count); \
52  })
53 #define WriteBlockBytes(Buffer, StartBlock, Count) \
54  WriteBlockBytesMain(Buffer, StartBlock, Count);
55 
56 void CopyBlockBytes(SIZET DestBlock, SIZET SrcBlock, SIZET Count);
57 
58 uint16_t AllocateBlocksMain(uint16_t BlockCount);
59 #define AllocateBlocks(BlockCount) \
60  AllocateBlocksMain(BlockCount);
61 
62 BYTE GetCardCapacityBlocks(void);
63 
64 void MemsetBlockBytes(uint8_t initValue, SIZET startBlock, SIZET byteCount);
65 
66 /* File data transfer related routines: */
67 void ReadDataEEPROMSource(uint8_t *Buffer, uint8_t Count);
68 void WriteDataEEPROMSink(uint8_t *Buffer, uint8_t Count);
69 
70 #endif
+
1 /*
2 The DESFire stack portion of this firmware source
3 is free software written by Maxie Dion Schmidt (@maxieds):
4 You can redistribute it and/or modify
5 it under the terms of this license.
6 
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 
11 The complete source distribution of
12 this firmware is available at the following link:
13 https://github.com/maxieds/ChameleonMiniFirmwareDESFireStack.
14 
15 Based in part on the original DESFire code created by
16 @dev-zzo (GitHub handle) [Dmitry Janushkevich] available at
17 https://github.com/dev-zzo/ChameleonMini/tree/desfire.
18 
19 This notice must be retained at the top of all source files where indicated.
20 */
21 
22 /*
23  * DESFireMemoryOperations.h :
24  * Maxie D. Schmidt (github.com/maxieds)
25  */
26 
27 #ifndef __DESFIRE_MEMORY_OPERATIONS_H__
28 #define __DESFIRE_MEMORY_OPERATIONS_H__
29 
30 #include "DESFireFirmwareSettings.h"
31 #include "DESFireLogging.h"
32 
33 /* Reserve some space on the stack (text / data segment) for intermediate
34  storage of strings and data we need to write so we do not have to rely
35  on a bothersome heap-based scheme for passing pointers to functions: */
36 #define DATA_BUFFER_SIZE_SMALL (32)
37 #define STRING_BUFFER_SIZE (92)
38 extern volatile char __InternalStringBuffer[STRING_BUFFER_SIZE];
39 extern char __InternalStringBuffer2[DATA_BUFFER_SIZE_SMALL];
40 
41 /*
42  * EEPROM and FRAM memory management routines:
43  */
44 void ReadBlockBytes(void *Buffer, SIZET StartBlock, SIZET Count);
45 
46 void WriteBlockBytesMain(const void *Buffer, SIZET StartBlock, SIZET Count);
47 #define WriteBlockBytes(Buffer, StartBlock, Count) \
48  WriteBlockBytesMain(Buffer, StartBlock, Count);
49 
50 void CopyBlockBytes(SIZET DestBlock, SIZET SrcBlock, SIZET Count);
51 
52 uint16_t AllocateBlocksMain(uint16_t BlockCount);
53 #define AllocateBlocks(BlockCount) \
54  AllocateBlocksMain(BlockCount);
55 
56 BYTE GetCardCapacityBlocks(void);
57 
58 void MemsetBlockBytes(uint8_t initValue, SIZET startBlock, SIZET byteCount);
59 
60 /* File data transfer related routines: */
61 void ReadDataEEPROMSource(uint8_t *Buffer, uint8_t Count);
62 void WriteDataEEPROMSink(uint8_t *Buffer, uint8_t Count);
63 
64 #endif
diff --git a/Doc/Doxygen/html/_d_e_s_fire_p_i_c_c_control_8h_source.html b/Doc/Doxygen/html/_d_e_s_fire_p_i_c_c_control_8h_source.html index 3bc28e7f..e130e35b 100644 --- a/Doc/Doxygen/html/_d_e_s_fire_p_i_c_c_control_8h_source.html +++ b/Doc/Doxygen/html/_d_e_s_fire_p_i_c_c_control_8h_source.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: DESFirePICCControl.h Source File @@ -11,9 +12,6 @@ - @@ -31,40 +29,19 @@ - + - - + + + +
DESFirePICCControl.h
-
1 /*
2 The DESFire stack portion of this firmware source
3 is free software written by Maxie Dion Schmidt (@maxieds):
4 You can redistribute it and/or modify
5 it under the terms of this license.
6 
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 
11 The complete source distribution of
12 this firmware is available at the following link:
13 https://github.com/maxieds/ChameleonMiniFirmwareDESFireStack.
14 
15 Based in part on the original DESFire code created by
16 @dev-zzo (GitHub handle) [Dmitry Janushkevich] available at
17 https://github.com/dev-zzo/ChameleonMini/tree/desfire.
18 
19 This notice must be retained at the top of all source files where indicated.
20 */
21 
22 /*
23  * DESFirePICCControl.h :
24  * Maxie D. Schmidt (github.com/maxieds)
25  */
26 
27 #ifndef __DESFIRE_PICC_CONTROL_H__
28 #define __DESFIRE_PICC_CONTROL_H__
29 
30 #include "../../Configuration.h"
31 
32 #include "DESFireFirmwareSettings.h"
33 #include "DESFirePICCHeaderLayout.h"
34 #include "DESFireInstructions.h"
35 #include "DESFireApplicationDirectory.h"
36 #include "DESFireFile.h"
37 #include "DESFireCrypto.h"
38 
39 /*
40  * Internal state variables:
41  */
42 
43 /* Cached data: flush to FRAM or relevant EEPROM addresses if changed */
44 extern DESFirePICCInfoType Picc;
45 extern DESFireAppDirType AppDir;
46 
47 /* Cached app data */
48 extern SelectedAppCacheType SelectedApp;
49 extern SelectedFileCacheType SelectedFile;
50 
51 typedef void (*TransferSourceFuncType)(BYTE *Buffer, BYTE Count);
52 typedef void (*TransferSinkFuncType)(BYTE *Buffer, BYTE Count);
53 typedef void (*TransferChecksumUpdateFuncType)(const BYTE *Buffer, BYTE Count);
54 typedef BYTE (*TransferChecksumFinalFuncType)(BYTE *Buffer);
55 typedef BYTE (*TransferEncryptFuncType)(BYTE *Buffer, BYTE Count);
56 typedef TransferStatus (*PiccToPcdTransferFilterFuncType)(BYTE *Buffer);
57 typedef BYTE (*PcdToPiccTransferFilterFuncType)(BYTE *Buffer, BYTE Count);
58 
59 /* Stored transfer state for all transfers */
60 typedef union DESFIRE_FIRMWARE_PACKING {
61  struct DESFIRE_FIRMWARE_ALIGNAT {
62  BYTE NextIndex;
63  } GetApplicationIds;
64  BYTE BlockBuffer[CRYPTO_MAX_BLOCK_SIZE];
65  struct DESFIRE_FIRMWARE_ALIGNAT {
66  TransferChecksumUpdateFuncType UpdateFunc;
67  TransferChecksumFinalFuncType FinalFunc;
68  BYTE AvailablePlaintext;
69  struct DESFIRE_FIRMWARE_ALIGNAT {
70  union DESFIRE_FIRMWARE_ALIGNAT {
71  CryptoAESCBCFuncType AESFunc;
72  CryptoTDEACBCFuncType TDEAFunc;
73  } CryptoChecksumFunc;
74  union {
75  SIZET CRCA;
76  UINT CRC32;
77  BYTE CMAC[DESFIRE_CMAC_LENGTH];
78  };
79  } MACData;
80  } Checksums;
81  struct DESFIRE_FIRMWARE_ALIGNAT {
82  SIZET BytesLeft;
83  struct DESFIRE_FIRMWARE_ALIGNAT {
84  TransferSourceFuncType Func;
85  SIZET Pointer; /* in FRAM */
86  } Source;
87  struct DESFIRE_FIRMWARE_ALIGNAT {
88  BOOL FirstPaddingBitSet;
89  TransferEncryptFuncType Func;
90  BYTE AvailablePlaintext;
91  } Encryption;
92  } ReadData;
93  struct DESFIRE_FIRMWARE_ALIGNAT {
94  SIZET BytesLeft;
95  struct DESFIRE_FIRMWARE_ALIGNAT {
96  TransferSinkFuncType Func;
97  SIZET Pointer; /* in FRAM */
98  } Sink;
99  struct DESFIRE_FIRMWARE_ALIGNAT {
100  TransferEncryptFuncType Func;
101  BYTE AvailablePlaintext;
102  } Encryption;
103  } WriteData;
104 } TransferStateType;
105 extern TransferStateType TransferState;
106 
107 /* Transfer routines */
108 void SyncronizePICCInfo(void);
109 TransferStatus PiccToPcdTransfer(uint8_t *Buffer);
110 uint8_t PcdToPiccTransfer(uint8_t *Buffer, uint8_t Count);
111 
112 /* Setup routines */
113 uint8_t ReadDataFilterSetup(uint8_t CommSettings);
114 uint8_t WriteDataFilterSetup(uint8_t CommSettings);
115 
116 /* PICC management */
117 void InitialisePiccBackendEV0(uint8_t StorageSize);
118 void InitialisePiccBackendEV1(uint8_t StorageSize);
119 void ResetPiccBackend(void);
120 bool IsEmulatingEV1(void);
121 void GetPiccHardwareVersionInfo(uint8_t* Buffer);
122 void GetPiccSoftwareVersionInfo(uint8_t* Buffer);
123 void GetPiccManufactureInfo(uint8_t* Buffer);
124 uint8_t GetPiccKeySettings(void);
125 void FormatPicc(void);
126 void CreatePiccApp(void);
127 void FactoryFormatPiccEV0(void);
128 void FactoryFormatPiccEV1(uint8_t StorageSize);
129 void GetPiccUid(ConfigurationUidType Uid);
130 void SetPiccUid(ConfigurationUidType Uid);
131 
132 #endif
+
1 /*
2 The DESFire stack portion of this firmware source
3 is free software written by Maxie Dion Schmidt (@maxieds):
4 You can redistribute it and/or modify
5 it under the terms of this license.
6 
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 
11 The complete source distribution of
12 this firmware is available at the following link:
13 https://github.com/maxieds/ChameleonMiniFirmwareDESFireStack.
14 
15 Based in part on the original DESFire code created by
16 @dev-zzo (GitHub handle) [Dmitry Janushkevich] available at
17 https://github.com/dev-zzo/ChameleonMini/tree/desfire.
18 
19 This notice must be retained at the top of all source files where indicated.
20 */
21 
22 /*
23  * DESFirePICCControl.h :
24  * Maxie D. Schmidt (github.com/maxieds)
25  */
26 
27 #ifndef __DESFIRE_PICC_CONTROL_H__
28 #define __DESFIRE_PICC_CONTROL_H__
29 
30 #include "../../Configuration.h"
31 
32 #include "DESFireFirmwareSettings.h"
33 #include "DESFirePICCHeaderLayout.h"
34 #include "DESFireInstructions.h"
35 #include "DESFireApplicationDirectory.h"
36 #include "DESFireFile.h"
37 #include "DESFireCrypto.h"
38 
39 /*
40  * Internal state variables:
41  */
42 
43 /* Cached data: flush to FRAM or relevant EEPROM addresses if changed */
44 extern DESFirePICCInfoType Picc;
45 extern DESFireAppDirType AppDir;
46 
47 /* Cached app data */
48 extern SelectedAppCacheType SelectedApp;
49 extern SelectedFileCacheType SelectedFile;
50 
51 typedef void (*TransferSourceFuncType)(BYTE *Buffer, BYTE Count);
52 typedef void (*TransferSinkFuncType)(BYTE *Buffer, BYTE Count);
53 typedef void (*TransferChecksumUpdateFuncType)(const BYTE *Buffer, BYTE Count);
54 typedef BYTE(*TransferChecksumFinalFuncType)(BYTE *Buffer);
55 typedef BYTE(*TransferEncryptFuncType)(BYTE *Buffer, BYTE Count);
56 typedef TransferStatus(*PiccToPcdTransferFilterFuncType)(BYTE *Buffer);
57 typedef BYTE(*PcdToPiccTransferFilterFuncType)(BYTE *Buffer, BYTE Count);
58 
59 /* Stored transfer state for all transfers */
60 typedef union DESFIRE_FIRMWARE_PACKING {
61  struct DESFIRE_FIRMWARE_ALIGNAT {
62  BYTE NextIndex;
63  } GetApplicationIds;
64  BYTE BlockBuffer[CRYPTO_MAX_BLOCK_SIZE];
65  struct DESFIRE_FIRMWARE_ALIGNAT {
66  TransferChecksumUpdateFuncType UpdateFunc;
67  TransferChecksumFinalFuncType FinalFunc;
68  BYTE AvailablePlaintext;
69  struct DESFIRE_FIRMWARE_ALIGNAT {
70  union DESFIRE_FIRMWARE_ALIGNAT {
71  CryptoAESCBCFuncType AESFunc;
72  CryptoTDEACBCFuncType TDEAFunc;
73  } CryptoChecksumFunc;
74  union {
75  SIZET CRCA;
76  UINT CRC32;
77  BYTE CMAC[DESFIRE_CMAC_LENGTH];
78  };
79  } MACData;
80  } Checksums;
81  struct DESFIRE_FIRMWARE_ALIGNAT {
82  SIZET BytesLeft;
83  struct DESFIRE_FIRMWARE_ALIGNAT {
84  TransferSourceFuncType Func;
85  SIZET Pointer; /* in FRAM */
86  } Source;
87  struct DESFIRE_FIRMWARE_ALIGNAT {
88  BOOL FirstPaddingBitSet;
89  TransferEncryptFuncType Func;
90  BYTE AvailablePlaintext;
91  } Encryption;
92  } ReadData;
93  struct DESFIRE_FIRMWARE_ALIGNAT {
94  SIZET BytesLeft;
95  struct DESFIRE_FIRMWARE_ALIGNAT {
96  TransferSinkFuncType Func;
97  SIZET Pointer; /* in FRAM */
98  } Sink;
99  struct DESFIRE_FIRMWARE_ALIGNAT {
100  TransferEncryptFuncType Func;
101  BYTE AvailablePlaintext;
102  } Encryption;
103  } WriteData;
104 } TransferStateType;
105 extern TransferStateType TransferState;
106 
107 /* Transfer routines */
108 void SyncronizePICCInfo(void);
109 TransferStatus PiccToPcdTransfer(uint8_t *Buffer);
110 uint8_t PcdToPiccTransfer(uint8_t *Buffer, uint8_t Count);
111 
112 /* Setup routines */
113 uint8_t ReadDataFilterSetup(uint8_t CommSettings);
114 uint8_t WriteDataFilterSetup(uint8_t CommSettings);
115 
116 /* PICC management */
117 void InitialisePiccBackendEV0(uint8_t StorageSize);
118 void InitialisePiccBackendEV1(uint8_t StorageSize);
119 void ResetPiccBackend(void);
120 bool IsEmulatingEV1(void);
121 void GetPiccHardwareVersionInfo(uint8_t *Buffer);
122 void GetPiccSoftwareVersionInfo(uint8_t *Buffer);
123 void GetPiccManufactureInfo(uint8_t *Buffer);
124 uint8_t GetPiccKeySettings(void);
125 void FormatPicc(void);
126 void CreatePiccApp(void);
127 void FactoryFormatPiccEV0(void);
128 void FactoryFormatPiccEV1(uint8_t StorageSize);
129 void GetPiccUid(ConfigurationUidType Uid);
130 void SetPiccUid(ConfigurationUidType Uid);
131 
132 #endif
diff --git a/Doc/Doxygen/html/_d_e_s_fire_p_i_c_c_header_layout_8h_source.html b/Doc/Doxygen/html/_d_e_s_fire_p_i_c_c_header_layout_8h_source.html index 2134bade..91e3d3b6 100644 --- a/Doc/Doxygen/html/_d_e_s_fire_p_i_c_c_header_layout_8h_source.html +++ b/Doc/Doxygen/html/_d_e_s_fire_p_i_c_c_header_layout_8h_source.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: DESFirePICCHeaderLayout.h Source File @@ -11,9 +12,6 @@ - @@ -31,40 +29,19 @@ - + - - + + + +
DESFirePICCHeaderLayout.h
-
1 /*
2 The DESFire stack portion of this firmware source
3 is free software written by Maxie Dion Schmidt (@maxieds):
4 You can redistribute it and/or modify
5 it under the terms of this license.
6 
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 
11 The complete source distribution of
12 this firmware is available at the following link:
13 https://github.com/maxieds/ChameleonMiniFirmwareDESFireStack.
14 
15 Based in part on the original DESFire code created by
16 @dev-zzo (GitHub handle) [Dmitry Janushkevich] available at
17 https://github.com/dev-zzo/ChameleonMini/tree/desfire.
18 
19 This notice must be retained at the top of all source files where indicated.
20 */
21 
22 /*
23  * DESFirePICCHeaderLayout.h
24  * Maxie D. Schmidt (github.com/maxieds)
25  */
26 
27 #ifndef __DESFIRE_PICC_HDRLAYOUT_H__
28 #define __DESFIRE_PICC_HDRLAYOUT_H__
29 
30 #include "DESFireFirmwareSettings.h"
31 #include "DESFireISO14443Support.h"
32 
33 #define DESFIRE_PICC_APP_SLOT 0x00
34 #define DESFIRE_MASTER_KEY_ID 0x00
35 
36 #define DESFIRE_NATIVE_CLA 0x90
37 #define DESFIRE_ISO7816_CLA 0x00
38 
39 /* Storage allocation constants */
40 #define DESFIRE_EEPROM_BLOCK_SIZE 16 //32 /* Bytes */
41 #define DESFIRE_BYTES_TO_BLOCKS(x) \
42  ( ((x) + DESFIRE_EEPROM_BLOCK_SIZE - 1) / DESFIRE_EEPROM_BLOCK_SIZE )
43 
44 #define DESFIRE_UID_SIZE ISO14443A_UID_SIZE_DOUBLE
45 
46 #define DESFIRE_MAX_PAYLOAD_SIZE 55 // 64 /* Bytes */
47 
48 /*
49  * Definitions pertaining to on-card data
50  */
51 
52 /* Anticollision parameters */
53 #define ATQA_VALUE 0x0344
54 #define SAK_CL1_VALUE (ISO14443A_SAK_INCOMPLETE)
55 #define SAK_CL2_VALUE (ISO14443A_SAK_COMPLETE_COMPLIANT)
56 #define SAK_UID_NOT_FINISHED 0x04
57 
58 #define STATUS_FRAME_SIZE (1 * 8) /* Bits */
59 
60 #define DESFIRE_EV0_ATS_TL_BYTE 0x06 /* TL: ATS length, 6 bytes */
61 #define DESFIRE_EV0_ATS_T0_BYTE 0x75 /* T0: TA, TB, TC present; max accepted frame is 64 bytes */
62 #define DESFIRE_EV0_ATS_TA_BYTE 0x77 /* TA: Only the lowest bit rate is supported */
63 #define DESFIRE_EV0_ATS_TB_BYTE 0x81 /* TB: taken from the DESFire spec */
64 #define DESFIRE_EV0_ATS_TC_BYTE 0x02 /* TC: taken from the DESFire spec */
65 
66 #define GET_LE16(p) (*((uint16_t*)&(p)[0]))
67 #define GET_LE24(p) (*((__uint24*)&(p)[0]))
68 #define GET_LE32(p) (*((uint32_t*)&(p)[0]))
69 
70 /* Defines for GetVersion */
71 #define ID_PHILIPS_NXP 0x04
72 #define DESFIRE_MANUFACTURER_ID ID_PHILIPS_NXP
73 
74 /* These do not change */
75 #define DESFIRE_TYPE 0x01
76 #define DESFIRE_SUBTYPE 0x01
77 #define DESFIRE_HW_PROTOCOL_TYPE 0x05
78 #define DESFIRE_SW_PROTOCOL_TYPE 0x05
79 
81 /* DESFire EV0 versions */
82 #define DESFIRE_HW_MAJOR_EV0 0x00
83 #define DESFIRE_HW_MINOR_EV0 0x01
84 #define DESFIRE_SW_MAJOR_EV0 0x00
85 #define DESFIRE_SW_MINOR_EV0 0x01
86 
87 #define IsPiccEV0(picc) \
88  (picc.HwVersionMajor == DESFIRE_HW_MAJOR_EV0 && picc.SwVersionMajor == DESFIRE_SW_MAJOR_EV0)
89 
90 /* DESFire EV1 versions */
91 #define DESFIRE_HW_MAJOR_EV1 0x01
92 #define DESFIRE_HW_MINOR_EV1 0x01
93 #define DESFIRE_SW_MAJOR_EV1 0x01
94 #define DESFIRE_SW_MINOR_EV1 0x01
95 
96 /* DESFire EV2 versions */
97 #define DESFIRE_HW_MAJOR_EV2 0x12
98 #define DESFIRE_HW_MINOR_EV2 0x01
99 #define DESFIRE_SW_MAJOR_EV2 0x12
100 #define DESFIRE_SW_MINOR_EV2 0x01
101 
102 /* Other HW product types for DESFire tags: See page 7 of
103  * https://www.nxp.com/docs/en/application-note/AN12343.pdf
104  */
105 // typedef enum DESFIRE_FIRMWARE_ENUM_PACKING {
106 // NATIVEIC_PHYS_CARD = 0x01,
107 // LIGHT_NATIVEIC_PHYS_CARD = 0x08,
108 // MICROCONTROLLER_PHYS_CARDI = 0x81,
109 // MICROCONTROLLER_PHYS_CARDII = 0x83,
110 // JAVACARD_SECURE_ELEMENT_PHYS_CARD = 0x91,
111 // HCE_MIFARE_2GO = 0xa1,
112 // } DESFireHWProductCodes;
113 //
114 // const BYTE DefaultDESFireATS[] = {
115 // 0x06, 0x75, 0x77, 0x81, 0x02, 0x80
116 // };
117 // const BYTE DefaultJCOPDESFireATS[] = {
118 // 0x06, 0x75, 0xf7, 0xb1, 0x02, 0x80
119 // };
120 //
121 // const BYTE DEFAULT_SELECT_DESFIRE_AID[] = {
122 // 0xd2, 0x76, 0x00, 0x00, 0x85, 0x01, 0x00
123 // };
124 // const BYTE DEFAULT_SELECT_ISO7816_AID[] = {
125 // 0xa0, 0x00, 0x00, 0x00, 0x03, 0x96
126 // };
127 //
128 // const BYTE VERSION1[] = {
129 // 0x04, 0x01, 0x01, 0x01, 0x00, 0x1a, 0x05
130 // };
131 // const BYTE VERSION2[] = {
132 // 0x04, 0x01, 0x01, 0x01, 0x03, 0x1a, 0x05
133 // };
134 // const BYTE VERSION3[] = {
135 // // Expected Response: 00 04 91 3a 29 93 26 80 00 00 00 00 00 39 08 91 00
136 // 0x04, (BYTE) 0x91, 0x3a, 0x29, (BYTE) 0x93,
137 // 0x26, (BYTE) 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x39, 0x08
138 // };
139 
140 #define DESFIRE_STORAGE_SIZE_2K 0x16
141 #define DESFIRE_STORAGE_SIZE_4K 0x18
142 #define DESFIRE_STORAGE_SIZE_8K 0x1A
143 
144 /*
145  * Defines the global PICC configuration.
146  * This is located in the very first block on the card.
147  */
148 #define PICC_FORMAT_BYTE (0xff)
149 #define PICC_EMPTY_BYTE (0x00)
150 
151 typedef struct DESFIRE_FIRMWARE_PACKING {
152  /* Static data: does not change during the PICC's lifetime.
153  * We will add Chameleon Mini terminal commands to enable
154  * resetting this data so tags can be emulated authentically.
155  * This structure is stored verbatim (using memcpy) at the
156  * start of the FRAM setting space for the configuration.
157  */
158  uint8_t Uid[DESFIRE_UID_SIZE] DESFIRE_FIRMWARE_ALIGNAT;
159  uint8_t StorageSize;
160  uint8_t HwVersionMajor;
161  uint8_t HwVersionMinor;
162  uint8_t SwVersionMajor;
163  uint8_t SwVersionMinor;
164  uint8_t BatchNumber[5] DESFIRE_FIRMWARE_ALIGNAT;
165  uint8_t ProductionWeek;
166  uint8_t ProductionYear;
167  uint8_t ATSBytes[5];
168  /* Dynamic data: changes during the PICC's lifetime */
169  uint16_t FirstFreeBlock;
170  uint8_t TransactionStarted; // USED ???
171  uint8_t Spare[9] DESFIRE_FIRMWARE_ALIGNAT; // USED ???
172 } DESFirePICCInfoType;
173 
174 typedef struct DESFIRE_FIRMWARE_PACKING {
175  BYTE Slot;
176  BYTE KeyCount;
177  BYTE MaxKeyCount;
178  BYTE FileCount;
179  BYTE CryptoCommStandard;
180  SIZET KeySettings; /* Block offset in FRAM */
181  SIZET FileNumbersArrayMap; /* Block offset in FRAM */
182  SIZET FileCommSettings; /* Block offset in FRAM */
183  SIZET FileAccessRights; /* Block offset in FRAM */
184  SIZET FilesAddress; /* Block offset in FRAM */
185  SIZET KeyVersionsArray; /* Block offset in FRAM */
186  SIZET KeyTypesArray; /* Block offset in FRAM */
187  SIZET KeyAddress; /* Block offset in FRAM */
188  UINT DirtyFlags; // USED ???
189 } SelectedAppCacheType;
190 
191 extern BYTE SELECTED_APP_CACHE_TYPE_BLOCK_SIZE;
192 extern BYTE APP_CACHE_KEY_SETTINGS_ARRAY_BLOCK_SIZE;
193 extern BYTE APP_CACHE_FILE_NUMBERS_HASHMAP_BLOCK_SIZE;
194 extern BYTE APP_CACHE_FILE_COMM_SETTINGS_ARRAY_BLOCK_SIZE;
195 extern BYTE APP_CACHE_FILE_ACCESS_RIGHTS_ARRAY_BLOCK_SIZE;
196 extern BYTE APP_CACHE_KEY_VERSIONS_ARRAY_BLOCK_SIZE;
197 extern BYTE APP_CACHE_KEY_TYPES_ARRAY_BLOCK_SIZE;
198 extern BYTE APP_CACHE_KEY_BLOCKIDS_ARRAY_BLOCK_SIZE;
199 extern BYTE APP_CACHE_FILE_BLOCKIDS_ARRAY_BLOCK_SIZE;
200 extern BYTE APP_CACHE_MAX_KEY_BLOCK_SIZE;
201 
202 extern SIZET DESFIRE_PICC_INFO_BLOCK_ID;
203 extern SIZET DESFIRE_APP_DIR_BLOCK_ID;
204 extern SIZET DESFIRE_APP_CACHE_DATA_ARRAY_BLOCK_ID;
205 extern SIZET DESFIRE_INITIAL_FIRST_FREE_BLOCK_ID;
206 extern SIZET DESFIRE_FIRST_FREE_BLOCK_ID;
207 extern SIZET CardCapacityBlocks;
208 
209 typedef enum DESFIRE_FIRMWARE_ENUM_PACKING {
210  /* AppData keeping track how many keys each app has */
211  DESFIRE_APP_KEY_COUNT,
212  DESFIRE_APP_MAX_KEY_COUNT,
213  /* AppData active file count */
214  DESFIRE_APP_FILE_COUNT,
215  /* AppData keep track of default crypto comm standard */
216  DESFIRE_APP_CRYPTO_COMM_STANDARD,
217  /* AppData keeping track of apps key settings */
218  DESFIRE_APP_KEY_SETTINGS_BLOCK_ID,
219  /* AppData hash-like unsorted array mapping file indices to their labeled numbers */
220  DESFIRE_APP_FILE_NUMBER_ARRAY_MAP_BLOCK_ID,
221  /* AppData communication settings (crypto transfer protocols) per file */
222  DESFIRE_APP_FILE_COMM_SETTINGS_BLOCK_ID,
223  /* AppData file access rights */
224  DESFIRE_APP_FILE_ACCESS_RIGHTS_BLOCK_ID,
225  /* AppData keep track of newer EVx revisions key versioning schemes */
226  DESFIRE_APP_KEY_VERSIONS_ARRAY_BLOCK_ID,
227  /* AppData keep track of the key types (and hence, byte sizes) by crypto method */
228  DESFIRE_APP_KEY_TYPES_ARRAY_BLOCK_ID,
229  /* AppData keeping track of apps file index blocks */
230  DESFIRE_APP_FILES_PTR_BLOCK_ID,
231  /* AppData keeping track of apps key locations */
232  DESFIRE_APP_KEYS_PTR_BLOCK_ID,
233 } DesfireCardLayout;
234 
235 SIZET PrettyPrintPICCHeaderData(BYTE *outputBuffer, SIZET maxLength, BYTE verbose);
236 SIZET PrettyPrintFileContentsData(BYTE *outputBuffer, SIZET maxLength, BYTE fileNumber);
237 SIZET PrettyPrintPICCFile(SelectedAppCacheType *appData, uint8_t fileIndex,
238  BYTE *outputBuffer, SIZET maxLength, BYTE verbose);
239 SIZET PrettyPrintPICCFilesFull(SelectedAppCacheType *appData, BYTE *outputBuffer, SIZET maxLength, BYTE verbose);
240 SIZET PrettyPrintPICCKey(SelectedAppCacheType *appData, uint8_t keyIndex,
241  BYTE *outputBuffer, SIZET maxLength, BYTE verbose);
242 SIZET PrettyPrintPICCKeysFull(SelectedAppCacheType *appData, BYTE *outputBuffer, SIZET maxLength, BYTE verbose);
243 SIZET PrettyPrintPICCAppDir(uint8_t appIndex,
244  BYTE *outputBuffer, SIZET maxLength, BYTE verbose);
245 SIZET PrettyPrintPICCAppDirsFull(BYTE *outputBuffer, SIZET maxLength, BYTE verbose);
246 SIZET PrettyPrintPICCImageData(BYTE *outputBuffer, SIZET maxLength, BYTE verbose);
247 
248 #endif
+
1 /*
2 The DESFire stack portion of this firmware source
3 is free software written by Maxie Dion Schmidt (@maxieds):
4 You can redistribute it and/or modify
5 it under the terms of this license.
6 
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 
11 The complete source distribution of
12 this firmware is available at the following link:
13 https://github.com/maxieds/ChameleonMiniFirmwareDESFireStack.
14 
15 Based in part on the original DESFire code created by
16 @dev-zzo (GitHub handle) [Dmitry Janushkevich] available at
17 https://github.com/dev-zzo/ChameleonMini/tree/desfire.
18 
19 This notice must be retained at the top of all source files where indicated.
20 */
21 
22 /*
23  * DESFirePICCHeaderLayout.h
24  * Maxie D. Schmidt (github.com/maxieds)
25  */
26 
27 #ifndef __DESFIRE_PICC_HDRLAYOUT_H__
28 #define __DESFIRE_PICC_HDRLAYOUT_H__
29 
30 #include "DESFireFirmwareSettings.h"
31 #include "DESFireISO14443Support.h"
32 
33 #define DESFIRE_PICC_APP_SLOT 0x00
34 #define DESFIRE_MASTER_KEY_ID 0x00
35 
36 #define DESFIRE_NATIVE_CLA 0x90
37 #define DESFIRE_ISO7816_CLA 0x00
38 
39 /* Storage allocation constants */
40 #define DESFIRE_EEPROM_BLOCK_SIZE 16 //32 /* Bytes */
41 #define DESFIRE_BYTES_TO_BLOCKS(x) \
42  ( ((x) + DESFIRE_EEPROM_BLOCK_SIZE - 1) / DESFIRE_EEPROM_BLOCK_SIZE )
43 
44 #define DESFIRE_UID_SIZE ISO14443A_UID_SIZE_DOUBLE
45 
46 #define DESFIRE_MAX_PAYLOAD_SIZE 55 // 64 /* Bytes */
47 
48 /*
49  * Definitions pertaining to on-card data
50  */
51 
52 /* Anticollision parameters */
53 #define ATQA_VALUE 0x0344
54 #define SAK_CL1_VALUE (ISO14443A_SAK_INCOMPLETE)
55 #define SAK_CL2_VALUE (ISO14443A_SAK_COMPLETE_COMPLIANT)
56 #define SAK_UID_NOT_FINISHED 0x04
57 
58 #define STATUS_FRAME_SIZE (1 * 8) /* Bits */
59 
60 #define DESFIRE_EV0_ATS_TL_BYTE 0x06 /* TL: ATS length, 6 bytes */
61 #define DESFIRE_EV0_ATS_T0_BYTE 0x75 /* T0: TA, TB, TC present; max accepted frame is 64 bytes */
62 #define DESFIRE_EV0_ATS_TA_BYTE 0x00 /* TA: Only the lowest bit rate is supported (normal is 0x77) */
63 #define DESFIRE_EV0_ATS_TB_BYTE 0x81 /* TB: taken from the DESFire spec */
64 #define DESFIRE_EV0_ATS_TC_BYTE 0x02 /* TC: taken from the DESFire spec */
65 
66 #define GET_LE16(p) (*((uint16_t*)&(p)[0]))
67 #define GET_LE24(p) (*((__uint24*)&(p)[0]))
68 #define GET_LE32(p) (*((uint32_t*)&(p)[0]))
69 
70 /* Defines for GetVersion */
71 #define ID_PHILIPS_NXP 0x04
72 #define DESFIRE_MANUFACTURER_ID ID_PHILIPS_NXP
73 
74 /* These do not change */
75 #define DESFIRE_TYPE 0x01
76 #define DESFIRE_SUBTYPE 0x01
77 #define DESFIRE_HW_PROTOCOL_TYPE 0x05
78 #define DESFIRE_SW_PROTOCOL_TYPE 0x05
79 
81 /* DESFire EV0 versions */
82 #define DESFIRE_HW_MAJOR_EV0 0x00
83 #define DESFIRE_HW_MINOR_EV0 0x01
84 #define DESFIRE_SW_MAJOR_EV0 0x00
85 #define DESFIRE_SW_MINOR_EV0 0x01
86 
87 #define IsPiccEV0(picc) \
88  (picc.HwVersionMajor == DESFIRE_HW_MAJOR_EV0 && picc.SwVersionMajor == DESFIRE_SW_MAJOR_EV0)
89 
90 /* DESFire EV1 versions */
91 #define DESFIRE_HW_MAJOR_EV1 0x01
92 #define DESFIRE_HW_MINOR_EV1 0x01
93 #define DESFIRE_SW_MAJOR_EV1 0x01
94 #define DESFIRE_SW_MINOR_EV1 0x01
95 
96 /* DESFire EV2 versions */
97 #define DESFIRE_HW_MAJOR_EV2 0x12
98 #define DESFIRE_HW_MINOR_EV2 0x01
99 #define DESFIRE_SW_MAJOR_EV2 0x12
100 #define DESFIRE_SW_MINOR_EV2 0x01
101 
102 /* Other HW product types for DESFire tags: See page 7 of
103  * https://www.nxp.com/docs/en/application-note/AN12343.pdf
104  */
105 // typedef enum DESFIRE_FIRMWARE_ENUM_PACKING {
106 // NATIVEIC_PHYS_CARD = 0x01,
107 // LIGHT_NATIVEIC_PHYS_CARD = 0x08,
108 // MICROCONTROLLER_PHYS_CARDI = 0x81,
109 // MICROCONTROLLER_PHYS_CARDII = 0x83,
110 // JAVACARD_SECURE_ELEMENT_PHYS_CARD = 0x91,
111 // HCE_MIFARE_2GO = 0xa1,
112 // } DESFireHWProductCodes;
113 //
114 // const BYTE DefaultDESFireATS[] = {
115 // 0x06, 0x75, 0x77, 0x81, 0x02, 0x80
116 // };
117 // const BYTE DefaultJCOPDESFireATS[] = {
118 // 0x06, 0x75, 0xf7, 0xb1, 0x02, 0x80
119 // };
120 //
121 // const BYTE DEFAULT_SELECT_DESFIRE_AID[] = {
122 // 0xd2, 0x76, 0x00, 0x00, 0x85, 0x01, 0x00
123 // };
124 // const BYTE DEFAULT_SELECT_ISO7816_AID[] = {
125 // 0xa0, 0x00, 0x00, 0x00, 0x03, 0x96
126 // };
127 //
128 // const BYTE VERSION1[] = {
129 // 0x04, 0x01, 0x01, 0x01, 0x00, 0x1a, 0x05
130 // };
131 // const BYTE VERSION2[] = {
132 // 0x04, 0x01, 0x01, 0x01, 0x03, 0x1a, 0x05
133 // };
134 // const BYTE VERSION3[] = {
135 // // Expected Response: 00 04 91 3a 29 93 26 80 00 00 00 00 00 39 08 91 00
136 // 0x04, (BYTE) 0x91, 0x3a, 0x29, (BYTE) 0x93,
137 // 0x26, (BYTE) 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x39, 0x08
138 // };
139 
140 #define DESFIRE_STORAGE_SIZE_2K 0x16
141 #define DESFIRE_STORAGE_SIZE_4K 0x18
142 #define DESFIRE_STORAGE_SIZE_8K 0x1A
143 
144 /*
145  * Defines the global PICC configuration.
146  * This is located in the very first block on the card.
147  */
148 #define PICC_FORMAT_BYTE (0xff)
149 #define PICC_EMPTY_BYTE (0x00)
150 
151 typedef struct DESFIRE_FIRMWARE_PACKING {
152  /* Static data: does not change during the PICC's lifetime.
153  * We will add Chameleon Mini terminal commands to enable
154  * resetting this data so tags can be emulated authentically.
155  * This structure is stored verbatim (using memcpy) at the
156  * start of the FRAM setting space for the configuration.
157  */
158  uint8_t Uid[DESFIRE_UID_SIZE] DESFIRE_FIRMWARE_ALIGNAT;
159  uint8_t StorageSize;
160  uint8_t HwVersionMajor;
161  uint8_t HwVersionMinor;
162  uint8_t SwVersionMajor;
163  uint8_t SwVersionMinor;
164  uint8_t BatchNumber[5] DESFIRE_FIRMWARE_ALIGNAT;
165  uint8_t ProductionWeek;
166  uint8_t ProductionYear;
167  uint8_t ATSBytes[5];
168  /* Dynamic data: changes during the PICC's lifetime */
169  uint16_t FirstFreeBlock;
170  uint8_t TransactionStarted; // USED ???
171  uint8_t Spare[9] DESFIRE_FIRMWARE_ALIGNAT; // USED ???
172 } DESFirePICCInfoType;
173 
174 typedef struct DESFIRE_FIRMWARE_PACKING {
175  BYTE Slot;
176  BYTE KeyCount;
177  BYTE MaxKeyCount;
178  BYTE FileCount;
179  BYTE CryptoCommStandard;
180  SIZET KeySettings; /* Block offset in FRAM */
181  SIZET FileNumbersArrayMap; /* Block offset in FRAM */
182  SIZET FileCommSettings; /* Block offset in FRAM */
183  SIZET FileAccessRights; /* Block offset in FRAM */
184  SIZET FilesAddress; /* Block offset in FRAM */
185  SIZET KeyVersionsArray; /* Block offset in FRAM */
186  SIZET KeyTypesArray; /* Block offset in FRAM */
187  SIZET KeyAddress; /* Block offset in FRAM */
188  UINT DirtyFlags; // USED ???
189 } SelectedAppCacheType;
190 
191 extern BYTE SELECTED_APP_CACHE_TYPE_BLOCK_SIZE;
192 extern BYTE APP_CACHE_KEY_SETTINGS_ARRAY_BLOCK_SIZE;
193 extern BYTE APP_CACHE_FILE_NUMBERS_HASHMAP_BLOCK_SIZE;
194 extern BYTE APP_CACHE_FILE_COMM_SETTINGS_ARRAY_BLOCK_SIZE;
195 extern BYTE APP_CACHE_FILE_ACCESS_RIGHTS_ARRAY_BLOCK_SIZE;
196 extern BYTE APP_CACHE_KEY_VERSIONS_ARRAY_BLOCK_SIZE;
197 extern BYTE APP_CACHE_KEY_TYPES_ARRAY_BLOCK_SIZE;
198 extern BYTE APP_CACHE_KEY_BLOCKIDS_ARRAY_BLOCK_SIZE;
199 extern BYTE APP_CACHE_FILE_BLOCKIDS_ARRAY_BLOCK_SIZE;
200 extern BYTE APP_CACHE_MAX_KEY_BLOCK_SIZE;
201 
202 extern SIZET DESFIRE_PICC_INFO_BLOCK_ID;
203 extern SIZET DESFIRE_APP_DIR_BLOCK_ID;
204 extern SIZET DESFIRE_APP_CACHE_DATA_ARRAY_BLOCK_ID;
205 extern SIZET DESFIRE_INITIAL_FIRST_FREE_BLOCK_ID;
206 extern SIZET DESFIRE_FIRST_FREE_BLOCK_ID;
207 extern SIZET CardCapacityBlocks;
208 
209 typedef enum DESFIRE_FIRMWARE_ENUM_PACKING {
210  /* AppData keeping track how many keys each app has */
211  DESFIRE_APP_KEY_COUNT,
212  DESFIRE_APP_MAX_KEY_COUNT,
213  /* AppData active file count */
214  DESFIRE_APP_FILE_COUNT,
215  /* AppData keep track of default crypto comm standard */
216  DESFIRE_APP_CRYPTO_COMM_STANDARD,
217  /* AppData keeping track of apps key settings */
218  DESFIRE_APP_KEY_SETTINGS_BLOCK_ID,
219  /* AppData hash-like unsorted array mapping file indices to their labeled numbers */
220  DESFIRE_APP_FILE_NUMBER_ARRAY_MAP_BLOCK_ID,
221  /* AppData communication settings (crypto transfer protocols) per file */
222  DESFIRE_APP_FILE_COMM_SETTINGS_BLOCK_ID,
223  /* AppData file access rights */
224  DESFIRE_APP_FILE_ACCESS_RIGHTS_BLOCK_ID,
225  /* AppData keep track of newer EVx revisions key versioning schemes */
226  DESFIRE_APP_KEY_VERSIONS_ARRAY_BLOCK_ID,
227  /* AppData keep track of the key types (and hence, byte sizes) by crypto method */
228  DESFIRE_APP_KEY_TYPES_ARRAY_BLOCK_ID,
229  /* AppData keeping track of apps file index blocks */
230  DESFIRE_APP_FILES_PTR_BLOCK_ID,
231  /* AppData keeping track of apps key locations */
232  DESFIRE_APP_KEYS_PTR_BLOCK_ID,
233 } DesfireCardLayout;
234 
235 SIZET PrettyPrintPICCHeaderData(BYTE *outputBuffer, SIZET maxLength, BYTE verbose);
236 SIZET PrettyPrintFileContentsData(BYTE *outputBuffer, SIZET maxLength, BYTE fileNumber);
237 SIZET PrettyPrintPICCFile(SelectedAppCacheType *appData, uint8_t fileIndex,
238  BYTE *outputBuffer, SIZET maxLength, BYTE verbose);
239 SIZET PrettyPrintPICCFilesFull(SelectedAppCacheType *appData, BYTE *outputBuffer, SIZET maxLength, BYTE verbose);
240 SIZET PrettyPrintPICCKey(SelectedAppCacheType *appData, uint8_t keyIndex,
241  BYTE *outputBuffer, SIZET maxLength, BYTE verbose);
242 SIZET PrettyPrintPICCKeysFull(SelectedAppCacheType *appData, BYTE *outputBuffer, SIZET maxLength, BYTE verbose);
243 SIZET PrettyPrintPICCAppDir(uint8_t appIndex,
244  BYTE *outputBuffer, SIZET maxLength, BYTE verbose);
245 SIZET PrettyPrintPICCAppDirsFull(BYTE *outputBuffer, SIZET maxLength, BYTE verbose);
246 SIZET PrettyPrintPICCImageData(BYTE *outputBuffer, SIZET maxLength, BYTE verbose);
247 
248 #endif
diff --git a/Doc/Doxygen/html/_d_e_s_fire_status_codes_8h_source.html b/Doc/Doxygen/html/_d_e_s_fire_status_codes_8h_source.html index 22fae412..6afc1b9c 100644 --- a/Doc/Doxygen/html/_d_e_s_fire_status_codes_8h_source.html +++ b/Doc/Doxygen/html/_d_e_s_fire_status_codes_8h_source.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: DESFireStatusCodes.h Source File @@ -11,9 +12,6 @@ - @@ -31,40 +29,19 @@ - + - - + + + +
DESFireStatusCodes.h
-
1 /*
2 The DESFire stack portion of this firmware source
3 is free software written by Maxie Dion Schmidt (@maxieds):
4 You can redistribute it and/or modify
5 it under the terms of this license.
6 
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 
11 The complete source distribution of
12 this firmware is available at the following link:
13 https://github.com/maxieds/ChameleonMiniFirmwareDESFireStack.
14 
15 Based in part on the original DESFire code created by
16 @dev-zzo (GitHub handle) [Dmitry Janushkevich] available at
17 https://github.com/dev-zzo/ChameleonMini/tree/desfire.
18 
19 This notice must be retained at the top of all source files where indicated.
20 */
21 
22 /*
23  * DESFireStatusCodes.h
24  * Maxie D. Schmidt (github.com/maxieds)
25  */
26 
27 #ifndef __DESFIRE_STATUS_CODES_H__
28 #define __DESFIRE_STATUS_CODES_H__
29 
30 #include "DESFireFirmwareSettings.h"
31 
32 extern BYTE FRAME_CONTINUE[];
33 extern BYTE OPERATION_OK[];
34 extern BYTE OK[];
35 extern BYTE INIT[];
36 
37 #define DESFIRE_STATUS_RESPONSE_SIZE 1
38 
39 // NOTE: See p. 72 of the datasheet for descriptions of these response codes:
40 typedef enum DESFIRE_FIRMWARE_ENUM_PACKING {
41  STATUS_OPERATION_OK = 0x00,
42  STATUS_NO_CHANGES = 0x0C,
43  STATUS_OUT_OF_EEPROM_ERROR = 0x0E,
44  STATUS_ILLEGAL_COMMAND_CODE = 0x1C,
45  STATUS_INTEGRITY_ERROR = 0x1E,
46  STATUS_NO_SUCH_KEY = 0x40,
47  STATUS_LENGTH_ERROR = 0x7E,
48  STATUS_PERMISSION_DENIED = 0x9D,
49  STATUS_PARAMETER_ERROR = 0x9E,
50  STATUS_APP_NOT_FOUND = 0xA0,
51  STATUS_APP_INTEGRITY_ERROR = 0xA1,
52  STATUS_AUTHENTICATION_ERROR = 0xAE,
53  STATUS_ADDITIONAL_FRAME = 0xAF,
54  STATUS_BOUNDARY_ERROR = 0xBE,
55  STATUS_COMMAND_ABORTED = 0xCA,
56  STATUS_APP_COUNT_ERROR = 0xCE,
57  STATUS_DUPLICATE_ERROR = 0xDE,
58  STATUS_EEPROM_ERROR = 0xEE,
59  STATUS_FILE_NOT_FOUND = 0xF0,
60  STATUS_PICC_INTEGRITY_ERROR = 0xC1,
61  STATUS_WRONG_VALUE_ERROR = 0x6E,
62 } DesfireStatusCodeType;
63 
64 #define SW_NO_ERROR ((uint16_t) 0x9000)
65 #define SW_BYTES_REMAINING_00 ((uint16_t) 0x6100)
66 #define SW_WRONG_LENGTH ((uint16_t) 0x6700)
67 #define SW_SECURITY_STATUS_NOT_SATISFIED ((uint16_t) 0x6982)
68 #define SW_FILE_INVALID ((uint16_t) 0x6983)
69 #define SW_DATA_INVALID ((uint16_t) 0x6984;
70 #define SW_CONDITIONS_NOT_SATISFIED ((uint16_t) 0x6985)
71 #define SW_COMMAND_NOT_ALLOWED ((uint16_t) 0x6986)
72 #define SW_APPLET_SELECT_FAILED ((uint16_t) 0x6999)
73 #define SW_WRONG_DATA ((uint16_t) 0x6a80)
74 #define SW_FUNC_NOT_SUPPORTED ((uint16_t) 0x6a81)
75 #define SW_FILE_NOT_FOUND ((uint16_t) 0x6a82)
76 #define SW_RECORD_NOT_FOUND ((uint16_t) 0x6a83)
77 #define SW_INCORRECT_P1P2 ((uint16_t) 0x6a86)
78 #define SW_WRONG_P1P2 ((uint16_t) 0x6b00)
79 #define SW_CORRECT_LENGTH_00 ((uint16_t) 0x6c00)
80 #define SW_INS_NOT_SUPPORTED ((uint16_t) 0x6d00)
81 #define SW_CLA_NOT_SUPPORTED ((uint16_t) 0x6e00)
82 #define SW_UNKNOWN ((uint16_t) 0x6f00)
83 #define SW_FILE_FULL ((uint16_t) 0x6a84)
84 #define SW_LOGICAL_CHANNEL_NOT_SUPPORTED ((uint16_t) 0x6881)
85 #define SW_SECURE_MESSAGING_NOT_SUPPORTED ((uint16_t) 0x6882)
86 #define SW_WARNING_STATE_UNCHANGED ((uint16_t) 0x6200)
87 #define SW_REFERENCE_DATA_NOT_FOUND ((uint16_t) 0x6a88)
88 #define SW_INTERNAL_ERROR ((uint16_t) 0x6d66)
89 
90 #endif
+
1 /*
2 The DESFire stack portion of this firmware source
3 is free software written by Maxie Dion Schmidt (@maxieds):
4 You can redistribute it and/or modify
5 it under the terms of this license.
6 
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 
11 The complete source distribution of
12 this firmware is available at the following link:
13 https://github.com/maxieds/ChameleonMiniFirmwareDESFireStack.
14 
15 Based in part on the original DESFire code created by
16 @dev-zzo (GitHub handle) [Dmitry Janushkevich] available at
17 https://github.com/dev-zzo/ChameleonMini/tree/desfire.
18 
19 This notice must be retained at the top of all source files where indicated.
20 */
21 
22 /*
23  * DESFireStatusCodes.h
24  * Maxie D. Schmidt (github.com/maxieds)
25  */
26 
27 #ifndef __DESFIRE_STATUS_CODES_H__
28 #define __DESFIRE_STATUS_CODES_H__
29 
30 #include "DESFireFirmwareSettings.h"
31 
32 extern BYTE FRAME_CONTINUE[];
33 extern BYTE OPERATION_OK[];
34 extern BYTE OK[];
35 extern BYTE INIT[];
36 
37 #define DESFIRE_STATUS_RESPONSE_SIZE 1
38 
39 // NOTE: See p. 72 of the datasheet for descriptions of these response codes:
40 typedef enum DESFIRE_FIRMWARE_ENUM_PACKING {
41  STATUS_OPERATION_OK = 0x00,
42  STATUS_NO_CHANGES = 0x0C,
43  STATUS_OUT_OF_EEPROM_ERROR = 0x0E,
44  STATUS_ILLEGAL_COMMAND_CODE = 0x1C,
45  STATUS_INTEGRITY_ERROR = 0x1E,
46  STATUS_NO_SUCH_KEY = 0x40,
47  STATUS_LENGTH_ERROR = 0x7E,
48  STATUS_PERMISSION_DENIED = 0x9D,
49  STATUS_PARAMETER_ERROR = 0x9E,
50  STATUS_APP_NOT_FOUND = 0xA0,
51  STATUS_APP_INTEGRITY_ERROR = 0xA1,
52  STATUS_AUTHENTICATION_ERROR = 0xAE,
53  STATUS_ADDITIONAL_FRAME = 0xAF,
54  STATUS_BOUNDARY_ERROR = 0xBE,
55  STATUS_COMMAND_ABORTED = 0xCA,
56  STATUS_APP_COUNT_ERROR = 0xCE,
57  STATUS_DUPLICATE_ERROR = 0xDE,
58  STATUS_EEPROM_ERROR = 0xEE,
59  STATUS_FILE_NOT_FOUND = 0xF0,
60  STATUS_PICC_INTEGRITY_ERROR = 0xC1,
61  STATUS_WRONG_VALUE_ERROR = 0x6E,
62 } DesfireStatusCodeType;
63 
64 #define SW_NO_ERROR ((uint16_t) 0x9000)
65 #define SW_BYTES_REMAINING_00 ((uint16_t) 0x6100)
66 #define SW_WRONG_LENGTH ((uint16_t) 0x6700)
67 #define SW_SECURITY_STATUS_NOT_SATISFIED ((uint16_t) 0x6982)
68 #define SW_FILE_INVALID ((uint16_t) 0x6983)
69 #define SW_DATA_INVALID ((uint16_t) 0x6984;
70 #define SW_CONDITIONS_NOT_SATISFIED ((uint16_t) 0x6985)
71 #define SW_COMMAND_NOT_ALLOWED ((uint16_t) 0x6986)
72 #define SW_APPLET_SELECT_FAILED ((uint16_t) 0x6999)
73 #define SW_WRONG_DATA ((uint16_t) 0x6a80)
74 #define SW_FUNC_NOT_SUPPORTED ((uint16_t) 0x6a81)
75 #define SW_FILE_NOT_FOUND ((uint16_t) 0x6a82)
76 #define SW_RECORD_NOT_FOUND ((uint16_t) 0x6a83)
77 #define SW_INCORRECT_P1P2 ((uint16_t) 0x6a86)
78 #define SW_WRONG_P1P2 ((uint16_t) 0x6b00)
79 #define SW_CORRECT_LENGTH_00 ((uint16_t) 0x6c00)
80 #define SW_INS_NOT_SUPPORTED ((uint16_t) 0x6d00)
81 #define SW_CLA_NOT_SUPPORTED ((uint16_t) 0x6e00)
82 #define SW_UNKNOWN ((uint16_t) 0x6f00)
83 #define SW_FILE_FULL ((uint16_t) 0x6a84)
84 #define SW_LOGICAL_CHANNEL_NOT_SUPPORTED ((uint16_t) 0x6881)
85 #define SW_SECURE_MESSAGING_NOT_SUPPORTED ((uint16_t) 0x6882)
86 #define SW_WARNING_STATE_UNCHANGED ((uint16_t) 0x6200)
87 #define SW_REFERENCE_DATA_NOT_FOUND ((uint16_t) 0x6a88)
88 #define SW_INTERNAL_ERROR ((uint16_t) 0x6d66)
89 
90 #endif
diff --git a/Doc/Doxygen/html/_d_e_s_fire_utils_8h_source.html b/Doc/Doxygen/html/_d_e_s_fire_utils_8h_source.html index 52cd8868..c38b878c 100644 --- a/Doc/Doxygen/html/_d_e_s_fire_utils_8h_source.html +++ b/Doc/Doxygen/html/_d_e_s_fire_utils_8h_source.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: DESFireUtils.h Source File @@ -11,9 +12,6 @@ - @@ -31,40 +29,19 @@ - + - - + + + +
DESFireUtils.h
-
1 /*
2 The DESFire stack portion of this firmware source
3 is free software written by Maxie Dion Schmidt (@maxieds):
4 You can redistribute it and/or modify
5 it under the terms of this license.
6 
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 
11 The complete source distribution of
12 this firmware is available at the following link:
13 https://github.com/maxieds/ChameleonMiniFirmwareDESFireStack.
14 
15 Based in part on the original DESFire code created by
16 @dev-zzo (GitHub handle) [Dmitry Janushkevich] available at
17 https://github.com/dev-zzo/ChameleonMini/tree/desfire.
18 
19 This notice must be retained at the top of all source files where indicated.
20 */
21 
22 /*
23  * DESFireUtils.h
24  * Maxie D. Schmidt (github.com/maxieds)
25  */
26 
27 #ifndef __DESFIRE_UTILS_H__
28 #define __DESFIRE_UTILS_H__
29 
30 #include <stdarg.h>
31 
32 #include "DESFireFirmwareSettings.h"
33 
34 #define UnsignedTypeToUINT(typeValue) \
35  ((UINT) typeValue)
36 #define ExtractLSBLE(ui) \
37  ((BYTE) (((UnsignedTypeToUINT(ui) & 0xff000000) >> 24) & 0x000000ff))
38 #define ExtractLSBBE(ui) \
39  ((BYTE) (UnsignedTypeToUINT(ui) & 0x000000ff))
40 
41 void RotateArrayRight(BYTE *srcBuf, BYTE *destBuf, SIZET bufSize);
42 void RotateArrayLeft(BYTE *srcBuf, BYTE *destBuf, SIZET bufSize);
43 void ConcatByteArrays(BYTE *arrA, SIZET arrASize, BYTE *arrB, SIZET arrBSize, BYTE *destArr);
44 
45 void Int32ToByteBuffer(uint8_t *byteBuffer, int32_t int32Value);
46 void Int24ToByteBuffer(uint8_t *byteBuffer, uint32_t int24Value);
47 int32_t Int32FromByteBuffer(uint8_t *byteBuffer);
48 
49 SIZET RoundBlockSize(SIZET byteSize, SIZET blockSize);
50 
51 /* Copied from the READER configuration sources: */
52 uint16_t DesfireAddParityBits(uint8_t * Buffer, uint16_t bits);
53 uint16_t DesfireRemoveParityBits(uint8_t * Buffer, uint16_t BitCount);
54 bool DesfireCheckParityBits(uint8_t * Buffer, uint16_t BitCount);
55 
56 #endif
+
1 /*
2 The DESFire stack portion of this firmware source
3 is free software written by Maxie Dion Schmidt (@maxieds):
4 You can redistribute it and/or modify
5 it under the terms of this license.
6 
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 
11 The complete source distribution of
12 this firmware is available at the following link:
13 https://github.com/maxieds/ChameleonMiniFirmwareDESFireStack.
14 
15 Based in part on the original DESFire code created by
16 @dev-zzo (GitHub handle) [Dmitry Janushkevich] available at
17 https://github.com/dev-zzo/ChameleonMini/tree/desfire.
18 
19 This notice must be retained at the top of all source files where indicated.
20 */
21 
22 /*
23  * DESFireUtils.h
24  * Maxie D. Schmidt (github.com/maxieds)
25  */
26 
27 #ifndef __DESFIRE_UTILS_H__
28 #define __DESFIRE_UTILS_H__
29 
30 #include <stdarg.h>
31 
32 #include "DESFireFirmwareSettings.h"
33 
34 #define UnsignedTypeToUINT(typeValue) \
35  ((UINT) typeValue)
36 #define ExtractLSBLE(ui) \
37  ((BYTE) (((UnsignedTypeToUINT(ui) & 0xff000000) >> 24) & 0x000000ff))
38 #define ExtractLSBBE(ui) \
39  ((BYTE) (UnsignedTypeToUINT(ui) & 0x000000ff))
40 
41 void RotateArrayRight(BYTE *srcBuf, BYTE *destBuf, SIZET bufSize);
42 void RotateArrayLeft(BYTE *srcBuf, BYTE *destBuf, SIZET bufSize);
43 void ConcatByteArrays(BYTE *arrA, SIZET arrASize, BYTE *arrB, SIZET arrBSize, BYTE *destArr);
44 
45 void Int32ToByteBuffer(uint8_t *byteBuffer, int32_t int32Value);
46 void Int24ToByteBuffer(uint8_t *byteBuffer, uint32_t int24Value);
47 int32_t Int32FromByteBuffer(uint8_t *byteBuffer);
48 
49 SIZET RoundBlockSize(SIZET byteSize, SIZET blockSize);
50 
51 /* Copied from the READER configuration sources: */
52 uint16_t DesfireAddParityBits(uint8_t *Buffer, uint16_t bits);
53 uint16_t DesfireRemoveParityBits(uint8_t *Buffer, uint16_t BitCount);
54 bool DesfireCheckParityBits(uint8_t *Buffer, uint16_t BitCount);
55 
56 #endif
diff --git a/Doc/Doxygen/html/_e_m4233_8h_source.html b/Doc/Doxygen/html/_e_m4233_8h_source.html index 5865aabf..19c6e8db 100644 --- a/Doc/Doxygen/html/_e_m4233_8h_source.html +++ b/Doc/Doxygen/html/_e_m4233_8h_source.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: EM4233.h Source File @@ -11,9 +12,6 @@ - @@ -31,40 +29,19 @@ - + - - + + + +
1 /*
2  * EM4233.h
3  *
4  * Created on: 04.12.2018
5  * Author: ceres-c & MrMoDDoM
6  */
7 
8 #ifndef EM4233_H_
9 #define EM4233_H_
10 
11 #include "Application.h"
12 
13 #define EM4233_STD_UID_SIZE ISO15693_GENERIC_UID_SIZE
14 #define EM4233_STD_MEM_SIZE 0xD0 // Bytes
15 #define EM4233_BYTES_PER_BLCK 0x04
16 #define EM4233_BLCKS_PER_PAGE 0x04
17 #define EM4233_NUMBER_OF_BLCKS ( EM4233_STD_MEM_SIZE / EM4233_BYTES_PER_BLCK )
18 #define EM4233_NUMBER_OF_PAGES ( EM4233_STD_MEM_SIZE / (EM4233_BYTES_PER_BLCK * EM4233_BLCKS_PER_PAGE) )
19 
20 #define EM4233_IC_REFERENCE 0x02 // From EM4233SLIC datasheet and checked against real tags
21 
22 #define EM4233_MEM_UID_ADDRESS 0xD0 // From 0x0100 to 0x0107 - UID
23 #define EM4233_MEM_AFI_ADDRESS 0xD8 // AFI byte address
24 #define EM4233_MEM_DSFID_ADDRESS 0xD9 // DSFID byte adress
25 #define EM4233_MEM_INF_ADDRESS 0xDC // Some status bits
26 
27 #define EM4233_MEM_LSM_ADDRESS 0xE0 // From 0xE0 to 0x0113 - Lock status masks
28 #define EM4233_MEM_PSW_ADDRESS 0x0114 // From 0x0114 to 0x0117 - 32 bit Password
29 #define EM4233_MEM_KEY_ADDRESS 0x0118 // From 0x0118 to 0x0123 - 96 bit Encryption Key
30 
31 #define EM4233_SYSINFO_BYTE 0x0F // == DSFID - AFI - VICC mem size - IC ref are present
32 
33 /* Bit masks */
34 #define EM4233_MASK_READ_PROT ( 1 << 2 ) // For lock status byte
35 #define EM4233_MASK_WRITE_PROT ( 1 << 3 )
36 #define EM4233_MASK_AFI_STATUS ( 1 << 0 )
37 #define EM4233_MASK_DSFID_STATUS ( 1 << 1 )
38 
39 /* Custom command code */
40 #define EM4233_CMD_SET_EAS 0xA2
41 #define EM4233_CMD_RST_EAS 0xA3
42 #define EM4233_CMD_LCK_EAS 0xA4
43 #define EM4233_CMD_ACT_EAS 0xA5
44 #define EM4233_CMD_PRT_EAS 0xA6
45 #define EM4233_CMD_WRT_EAS_ID 0xA7
46 #define EM4233_CMD_WRT_EAS_CFG 0xA8
47 #define EM4233_CMD_WRT_PSW 0xB4
48 #define EM4233_CMD_WRT_MEM_PAG 0xB6
49 #define EM4233_CMD_GET_BLKS_PRT_STS 0xB8
50 #define EM4233_CMD_DESTROY 0xB9
51 #define EM4233_CMD_ENABLE_PRCY 0xBA
52 #define EM4233_CMD_DISBLE_PRCY 0xBB
53 #define EM4233_CMD_FST_READ_BLKS 0xC3
54 
55 /* Proprietary command code */
56 #define EM4233_CMD_AUTH1 0xE0
57 #define EM4233_CMD_AUTH2 0xE1
58 #define EM4233_CMD_GEN_READ 0xE2 // Implies some sort of singed CRC. Unknown at the moment
59 #define EM4233_CMD_GEN_WRITE 0xE3 // Same
60 #define EM4233_CMD_LOGIN 0xE4
61 
62 /* Compile time switch */
63 /* EM4233_LOGIN_YES_CARD has to be uncommented if you want your emulated card
64  * to accept any given password from the reader when a Login request (E4) is issued.
65  * It is expecially useful when analyzing an unknown system and you want to fool a reader
66  * into thiking you are using the original tag without actually knowing the password.
67  */
68 #define EM4233_LOGIN_YES_CARD
69 
70 void EM4233AppInit(void);
71 void EM4233AppReset(void);
72 void EM4233AppTask(void);
73 void EM4233AppTick(void);
74 uint16_t EM4233AppProcess(uint8_t *FrameBuf, uint16_t FrameBytes);
75 void EM4233GetUid(ConfigurationUidType Uid);
76 void EM4233SetUid(ConfigurationUidType Uid);
77 void EM4233FlipUid(ConfigurationUidType Uid);
78 
79 #endif /* EM4233_H_ */
diff --git a/Doc/Doxygen/html/_getting_started_8txt.html b/Doc/Doxygen/html/_getting_started_8txt.html index ca6bcd04..025c9a50 100644 --- a/Doc/Doxygen/html/_getting_started_8txt.html +++ b/Doc/Doxygen/html/_getting_started_8txt.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: GettingStarted.txt File Reference @@ -11,9 +12,6 @@ - @@ -31,40 +29,19 @@ - + - - + + + +
diff --git a/Doc/Doxygen/html/_i_s_o14443-2_a_8h_source.html b/Doc/Doxygen/html/_i_s_o14443-2_a_8h_source.html index 6f869714..d48edb2e 100644 --- a/Doc/Doxygen/html/_i_s_o14443-2_a_8h_source.html +++ b/Doc/Doxygen/html/_i_s_o14443-2_a_8h_source.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: ISO14443-2A.h Source File @@ -11,9 +12,6 @@ - @@ -31,40 +29,19 @@
- + - - + + + +
1 /*
2  * ISO14443-2A.h
3  *
4  * Created on: 18.02.2013
5  * Author: skuser
6  */
7 
8 #ifndef ISO14443_2A_H_
9 #define ISO14443_2A_H_
10 
11 #include "Codec.h"
12 
13 #define ISO14443A_APP_NO_RESPONSE 0x0000
14 #define ISO14443A_APP_CUSTOM_PARITY 0x1000
15 
16 #define ISO14443A_BUFFER_PARITY_OFFSET (CODEC_BUFFER_SIZE/2)
17 
18 /* Codec Interface */
19 void ISO14443ACodecInit(void);
20 void ISO14443ACodecDeInit(void);
21 void ISO14443ACodecTask(void);
22 
23 
24 
25 #endif
diff --git a/Doc/Doxygen/html/_i_s_o14443-3_a_8h_source.html b/Doc/Doxygen/html/_i_s_o14443-3_a_8h_source.html index 63d8e022..ff0e72e6 100644 --- a/Doc/Doxygen/html/_i_s_o14443-3_a_8h_source.html +++ b/Doc/Doxygen/html/_i_s_o14443-3_a_8h_source.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: ISO14443-3A.h Source File @@ -11,9 +12,6 @@ - @@ -31,40 +29,19 @@ - + - - + + + +
ISO14443-3A.h
-
1 /*
2  * ISO14443-2A.h
3  *
4  * Created on: 19.03.2013
5  * Author: skuser
6  */
7 
8 #ifndef ISO14443_3A_H_
9 #define ISO14443_3A_H_
10 
11 #include "../Common.h"
12 #include <string.h>
13 
14 #define ISO14443A_UID_SIZE_SINGLE 4 /* bytes */
15 #define ISO14443A_UID_SIZE_DOUBLE 7
16 #define ISO14443A_UID_SIZE_TRIPLE 10
17 
18 #define ISO14443A_CMD_REQA 0x26
19 #define ISO14443A_CMD_WUPA 0x52
20 #define ISO14443A_CMD_SELECT_CL1 0x93
21 #define ISO14443A_CMD_SELECT_CL2 0x95
22 #define ISO14443A_CMD_SELECT_CL3 0x97
23 #define ISO14443A_CMD_HLTA 0x50
24 
25 #define ISO14443A_NVB_AC_START 0x20
26 #define ISO14443A_NVB_AC_END 0x70
27 
28 #define ISO14443A_CL_UID_OFFSET 0
29 #define ISO14443A_CL_UID_SIZE 4
30 #define ISO14443A_CL_BCC_OFFSET 4
31 #define ISO14443A_CL_BCC_SIZE 1 /* Byte */
32 #define ISO14443A_CL_FRAME_SIZE ((ISO14443A_CL_UID_SIZE + ISO14443A_CL_BCC_SIZE) * 8) /* UID[N...N+3] || BCCN */
33 #define ISO14443A_SAK_INCOMPLETE 0x04
34 #define ISO14443A_SAK_COMPLETE_COMPLIANT 0x20
35 #define ISO14443A_SAK_COMPLETE_NOT_COMPLIANT 0x00
36 
37 #define ISO14443A_ATQA_FRAME_SIZE (2 * 8) /* Bit */
38 #define ISO14443A_SAK_FRAME_SIZE (3 * 8) /* Bit */
39 #define ISO14443A_HLTA_FRAME_SIZE (2 * 8) /* Bit */
40 
41 #define ISO14443A_UID0_RANDOM 0x08
42 #define ISO14443A_UID0_CT 0x88
43 
44 #define ISO14443A_CRCA_SIZE 2
45 
46 #define ISO14443A_CALC_BCC(ByteBuffer) \
47  ( ByteBuffer[0] ^ ByteBuffer[1] ^ ByteBuffer[2] ^ ByteBuffer[3] )
48 
49 void ISO14443AAppendCRCA(void *Buffer, uint16_t ByteCount);
50 bool ISO14443ACheckCRCA(const void *Buffer, uint16_t ByteCount);
51 
52 INLINE bool ISO14443ASelect(void *Buffer, uint16_t *BitCount, uint8_t *UidCL, uint8_t SAKValue);
53 INLINE bool ISO14443AWakeUp(void *Buffer, uint16_t *BitCount, uint16_t ATQAValue, bool FromHalt);
54 
55 INLINE
56 bool ISO14443ASelect(void *Buffer, uint16_t *BitCount, uint8_t *UidCL, uint8_t SAKValue) {
57  uint8_t *DataPtr = (uint8_t *) Buffer;
58  uint8_t NVB = DataPtr[1];
59  //uint8_t CollisionByteCount = (NVB >> 4) & 0x0F;
60  //uint8_t CollisionBitCount = (NVB >> 0) & 0x0F;
61 
62  switch (NVB) {
63  case ISO14443A_NVB_AC_START:
64  /* Start of anticollision procedure.
65  * Send whole UID CLn + BCC */
66  DataPtr[0] = UidCL[0];
67  DataPtr[1] = UidCL[1];
68  DataPtr[2] = UidCL[2];
69  DataPtr[3] = UidCL[3];
70  DataPtr[4] = ISO14443A_CALC_BCC(DataPtr);
71 
72  *BitCount = ISO14443A_CL_FRAME_SIZE;
73 
74  return false;
75 
76  case ISO14443A_NVB_AC_END:
77  /* End of anticollision procedure.
78  * Send SAK CLn if we are selected. */
79  if ((DataPtr[2] == UidCL[0]) &&
80  (DataPtr[3] == UidCL[1]) &&
81  (DataPtr[4] == UidCL[2]) &&
82  (DataPtr[5] == UidCL[3])) {
83 
84  DataPtr[0] = SAKValue;
85  ISO14443AAppendCRCA(Buffer, 1);
86 
87  *BitCount = ISO14443A_SAK_FRAME_SIZE;
88  return true;
89  } else {
90  /* We have not been selected. Don't send anything. */
91  *BitCount = 0;
92  return false;
93  }
94  default: {
95  uint8_t CollisionByteCount = ((NVB >> 4) & 0x0f) - 2;
96  uint8_t CollisionBitCount = (NVB >> 0) & 0x0f;
97  uint8_t mask = 0xFF >> (8 - CollisionBitCount);
98  // Since the UidCL does not contain the BCC, we have to distinguish here
99  if (
100  ((CollisionByteCount == 5 || (CollisionByteCount == 4 && CollisionBitCount > 0)) && memcmp(UidCL, &DataPtr[2], 4) == 0 && (ISO14443A_CALC_BCC(UidCL) & mask) == (DataPtr[6] & mask))
101  ||
102  (CollisionByteCount == 4 && CollisionBitCount == 0 && memcmp(UidCL, &DataPtr[2], 4) == 0)
103  ||
104  (CollisionByteCount < 4 && memcmp(UidCL, &DataPtr[2], CollisionByteCount) == 0 && (UidCL[CollisionByteCount] & mask) == (DataPtr[CollisionByteCount + 2] & mask))
105  ) {
106  DataPtr[0] = UidCL[0];
107  DataPtr[1] = UidCL[1];
108  DataPtr[2] = UidCL[2];
109  DataPtr[3] = UidCL[3];
110  DataPtr[4] = ISO14443A_CALC_BCC(DataPtr);
111 
112  *BitCount = ISO14443A_CL_FRAME_SIZE;
113  } else {
114  *BitCount = 0;
115  }
116  return false;
117  }
118  /* TODO: No anticollision supported */
119  *BitCount = 0;
120  return false;
121  }
122 }
123 
124 #ifdef CONFIG_MF_DESFIRE_SUPPORT
125 extern uint8_t FirstUidCL[4];
126 
127 INLINE
128 bool ISO14443ASelectDesfire(void* Buffer, uint16_t* BitCount, uint8_t* UidCL, uint8_t SAKValue)
129 {
130  uint8_t* DataPtr = (uint8_t*) Buffer;
131  uint8_t NVB = DataPtr[1];
132 
133  switch (NVB) {
134  case ISO14443A_NVB_AC_START:
135  /* Start of anticollision procedure.
136  * Send whole UID CLn + BCC */
137  DataPtr[0] = UidCL[0];
138  DataPtr[1] = UidCL[1];
139  DataPtr[2] = UidCL[2];
140  DataPtr[3] = UidCL[3];
141  DataPtr[ISO14443A_CL_BCC_OFFSET] = ISO14443A_CALC_BCC(DataPtr);
142  memcpy(FirstUidCL, UidCL, ISO14443A_CL_UID_SIZE);
143  *BitCount = ISO14443A_CL_FRAME_SIZE;
144  return false;
145 
146  case ISO14443A_NVB_AC_END:
147  /* End of anticollision procedure.
148  * Send SAK CLn if we are selected. */
149  if ( (DataPtr[2] == UidCL[0]) &&
150  (DataPtr[3] == UidCL[1]) &&
151  (DataPtr[4] == UidCL[2]) &&
152  (DataPtr[5] == UidCL[3]) ) {
153  DataPtr[0] = SAKValue;
154  *BitCount = BITS_PER_BYTE;
155  return true;
156  }
157  else {
158  /* We have not been selected. Don't send anything. */
159  *BitCount = 0;
160  return false;
161  }
162  default:
163  {
164  uint8_t CollisionByteCount = ((NVB >> 4) & 0x0f) - 2;
165  uint8_t CollisionBitCount = (NVB >> 0) & 0x0f;
166  uint8_t mask = 0xFF >> (8 - CollisionBitCount);
167  // Since the UidCL does not contain the BCC, we have to distinguish here
168  if (
169  ((CollisionByteCount == 5 || (CollisionByteCount == 4 && CollisionBitCount > 0)) &&
170  memcmp(UidCL, &DataPtr[2], 4) == 0 && (ISO14443A_CALC_BCC(UidCL) & mask) == (DataPtr[6] & mask))
171  ||
172  (CollisionByteCount == 4 && CollisionBitCount == 0 && memcmp(UidCL, &DataPtr[2], 4) == 0)
173  ||
174  (CollisionByteCount < 4 && memcmp(UidCL, &DataPtr[2], CollisionByteCount) == 0 &&
175  (UidCL[CollisionByteCount] & mask) == (DataPtr[CollisionByteCount + 2] & mask))
176  )
177  {
178  DataPtr[0] = UidCL[0];
179  DataPtr[1] = UidCL[1];
180  DataPtr[2] = UidCL[2];
181  DataPtr[3] = UidCL[3];
182  DataPtr[4] = ISO14443A_CALC_BCC(DataPtr);
183 
184  *BitCount = ISO14443A_CL_FRAME_SIZE;
185  } else {
186  *BitCount = 0;
187  }
188  return false;
189  }
190  /* No anticollision supported */
191  *BitCount = 0;
192  return false;
193  }
194 }
195 
196 #endif
197 
198 INLINE
199 bool ISO14443AWakeUp(void *Buffer, uint16_t *BitCount, uint16_t ATQAValue, bool FromHalt) {
200  uint8_t *DataPtr = (uint8_t *) Buffer;
201 
202  if (((! FromHalt) && (DataPtr[0] == ISO14443A_CMD_REQA)) ||
203  (DataPtr[0] == ISO14443A_CMD_WUPA)) {
204  DataPtr[0] = (ATQAValue >> 0) & 0x00FF;
205  DataPtr[1] = (ATQAValue >> 8) & 0x00FF;
206 
207  *BitCount = ISO14443A_ATQA_FRAME_SIZE;
208 
209  return true;
210  } else {
211  *BitCount = 0;
212 
213  return false;
214  }
215 }
216 
217 #endif
+
1 /*
2  * ISO14443-2A.h
3  *
4  * Created on: 19.03.2013
5  * Author: skuser
6  */
7 
8 #ifndef ISO14443_3A_H_
9 #define ISO14443_3A_H_
10 
11 #include "../Common.h"
12 #include <string.h>
13 
14 #define ISO14443A_UID_SIZE_SINGLE 4 /* bytes */
15 #define ISO14443A_UID_SIZE_DOUBLE 7
16 #define ISO14443A_UID_SIZE_TRIPLE 10
17 
18 #define ISO14443A_CMD_REQA 0x26
19 #define ISO14443A_CMD_WUPA 0x52
20 #define ISO14443A_CMD_SELECT_CL1 0x93
21 #define ISO14443A_CMD_SELECT_CL2 0x95
22 #define ISO14443A_CMD_SELECT_CL3 0x97
23 #define ISO14443A_CMD_HLTA 0x50
24 
25 #define ISO14443A_NVB_AC_START 0x20
26 #define ISO14443A_NVB_AC_END 0x70
27 
28 #define IsSelectCmd(Buffer) ((Buffer[0] == ISO14443A_CMD_SELECT_CL1) || \
29  (Buffer[0] == ISO14443A_CMD_SELECT_CL2) || \
30  (Buffer[0] == ISO14443A_CMD_SELECT_CL3))
31 #define IsCmdSelectRound1(Buffer) (IsSelectCmd(Buffer) && (Buffer[1] == ISO14443A_NVB_AC_START))
32 #define IsCmdSelectRound2(Buffer) (IsSelectCmd(Buffer) && (Buffer[1] == ISO14443A_NVB_AC_END))
33 
34 #define ISO14443A_CL_UID_OFFSET 0
35 #define ISO14443A_CL_UID_SIZE 4
36 #define ISO14443A_CL_BCC_OFFSET 4
37 #define ISO14443A_CL_BCC_SIZE 1 /* Byte */
38 #define ISO14443A_CL_FRAME_SIZE ((ISO14443A_CL_UID_SIZE + ISO14443A_CL_BCC_SIZE) * 8) /* UID[N...N+3] || BCCN */
39 #define ISO14443A_SAK_INCOMPLETE 0x24 // 0x04
40 #define ISO14443A_SAK_COMPLETE_COMPLIANT 0x20
41 #define ISO14443A_SAK_COMPLETE_NOT_COMPLIANT 0x00
42 
43 #define ISO14443A_ATQA_FRAME_SIZE_BYTES (2) /* in Bytes */
44 #define ISO14443A_ATQA_FRAME_SIZE (2 * BITS_PER_BYTE) /* in Bits */
45 #define ISO14443A_SAK_FRAME_SIZE (3 * BITS_PER_BYTE) /* in Bits */
46 #define ISO14443A_HLTA_FRAME_SIZE (2 * BITS_PER_BYTE) /* in Bits */
47 
48 #define ISO14443A_UID0_RANDOM 0x08
49 #define ISO14443A_UID0_CT 0x88
50 
51 #define ISO14443A_CRCA_SIZE 2
52 
53 #define ISO14443A_CALC_BCC(ByteBuffer) \
54  ( ByteBuffer[0] ^ ByteBuffer[1] ^ ByteBuffer[2] ^ ByteBuffer[3] )
55 
56 void ISO14443AAppendCRCA(void *Buffer, uint16_t ByteCount);
57 bool ISO14443ACheckCRCA(const void *Buffer, uint16_t ByteCount);
58 
59 INLINE bool ISO14443ASelect(void *Buffer, uint16_t *BitCount, uint8_t *UidCL, uint8_t SAKValue);
60 INLINE bool ISO14443AWakeUp(void *Buffer, uint16_t *BitCount, uint16_t ATQAValue, bool FromHalt);
61 
62 INLINE
63 bool ISO14443ASelect(void *Buffer, uint16_t *BitCount, uint8_t *UidCL, uint8_t SAKValue) {
64  uint8_t *DataPtr = (uint8_t *) Buffer;
65  uint8_t NVB = DataPtr[1];
66 
67  switch (NVB) {
68  case ISO14443A_NVB_AC_START:
69  /* Start of anticollision procedure.
70  * Send whole UID CLn + BCC */
71  DataPtr[0] = UidCL[0];
72  DataPtr[1] = UidCL[1];
73  DataPtr[2] = UidCL[2];
74  DataPtr[3] = UidCL[3];
75  DataPtr[4] = ISO14443A_CALC_BCC(DataPtr);
76  *BitCount = ISO14443A_CL_FRAME_SIZE;
77  return false;
78 
79  case ISO14443A_NVB_AC_END:
80  /* End of anticollision procedure.
81  * Send SAK CLn if we are selected. */
82  if ((DataPtr[2] == UidCL[0]) &&
83  (DataPtr[3] == UidCL[1]) &&
84  (DataPtr[4] == UidCL[2]) &&
85  (DataPtr[5] == UidCL[3])) {
86  DataPtr[0] = SAKValue;
87  ISO14443AAppendCRCA(Buffer, 1);
88  *BitCount = ISO14443A_SAK_FRAME_SIZE;
89  return true;
90  } else {
91  /* We have not been selected. Don't send anything. */
92  *BitCount = 0;
93  return false;
94  }
95  default: {
96  uint8_t CollisionByteCount = ((NVB >> 4) & 0x0f) - 2;
97  uint8_t CollisionBitCount = (NVB >> 0) & 0x0f;
98  uint8_t mask = 0xFF >> (8 - CollisionBitCount);
99  // Since the UidCL does not contain the BCC, we have to distinguish here
100  if (
101  ((CollisionByteCount == 5 || (CollisionByteCount == 4 && CollisionBitCount > 0)) && memcmp(UidCL, &DataPtr[2], 4) == 0 && (ISO14443A_CALC_BCC(UidCL) & mask) == (DataPtr[6] & mask))
102  ||
103  (CollisionByteCount == 4 && CollisionBitCount == 0 && memcmp(UidCL, &DataPtr[2], 4) == 0)
104  ||
105  (CollisionByteCount < 4 && memcmp(UidCL, &DataPtr[2], CollisionByteCount) == 0 && (UidCL[CollisionByteCount] & mask) == (DataPtr[CollisionByteCount + 2] & mask))
106  ) {
107  DataPtr[0] = UidCL[0];
108  DataPtr[1] = UidCL[1];
109  DataPtr[2] = UidCL[2];
110  DataPtr[3] = UidCL[3];
111  DataPtr[4] = ISO14443A_CALC_BCC(DataPtr);
112 
113  *BitCount = ISO14443A_CL_FRAME_SIZE;
114  } else {
115  *BitCount = 0;
116  }
117  return false;
118  }
119  /* TODO: No anticollision supported */
120  *BitCount = 0;
121  return false;
122  }
123 }
124 
125 #ifdef CONFIG_MF_DESFIRE_SUPPORT
126 bool ISO14443ASelectDesfire(void *Buffer, uint16_t *BitCount, uint8_t *UidCL, uint8_t SAKValue);
127 #endif
128 
129 INLINE
130 bool ISO14443AWakeUp(void *Buffer, uint16_t *BitCount, uint16_t ATQAValue, bool FromHalt) {
131  uint8_t *DataPtr = (uint8_t *) Buffer;
132 
133  if (((! FromHalt) && (DataPtr[0] == ISO14443A_CMD_REQA)) ||
134  (DataPtr[0] == ISO14443A_CMD_WUPA)) {
135  DataPtr[0] = (ATQAValue >> 0) & 0x00FF;
136  DataPtr[1] = (ATQAValue >> 8) & 0x00FF;
137 
138  *BitCount = ISO14443A_ATQA_FRAME_SIZE;
139 
140  return true;
141  } else {
142  *BitCount = 0;
143 
144  return false;
145  }
146 }
147 
148 #endif
diff --git a/Doc/Doxygen/html/_i_s_o15693-_a_8h_source.html b/Doc/Doxygen/html/_i_s_o15693-_a_8h_source.html index 6422b3fc..9a018e51 100644 --- a/Doc/Doxygen/html/_i_s_o15693-_a_8h_source.html +++ b/Doc/Doxygen/html/_i_s_o15693-_a_8h_source.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: ISO15693-A.h Source File @@ -11,9 +12,6 @@ - @@ -31,40 +29,19 @@ - + - - + + + +
1 /*
2  * ISO15693-3.h
3  *
4  * Created on: 24.08.2013
5  * Author: skuser
6  */
7 
8 #ifndef ISO15693_3_H_
9 #define ISO15693_3_H_
10 
11 #include "../Common.h"
12 
13 /* request and response fields addresses */
14 #define ISO15693_ADDR_FLAGS 0x00
15 #define ISO15693_REQ_ADDR_CMD 0x01
16 #define ISO15693_REQ_ADDR_PARAM 0x02
17 
18 #define ISO15693_RES_ADDR_PARAM 0x01
19 
20 /* command codes */
21 #define ISO15693_CMD_INVENTORY 0x01
22 #define ISO15693_CMD_STAY_QUIET 0x02
23 #define ISO15693_CMD_READ_SINGLE 0x20
24 #define ISO15693_CMD_WRITE_SINGLE 0x21
25 #define ISO15693_CMD_LOCK_BLOCK 0x22
26 #define ISO15693_CMD_READ_MULTIPLE 0x23
27 #define ISO15693_CMD_WRITE_MULTIPLE 0x24
28 #define ISO15693_CMD_SELECT 0x25
29 #define ISO15693_CMD_RESET_TO_READY 0x26
30 #define ISO15693_CMD_WRITE_AFI 0x27
31 #define ISO15693_CMD_LOCK_AFI 0x28
32 #define ISO15693_CMD_WRITE_DSFID 0x29
33 #define ISO15693_CMD_LOCK_DSFID 0x2A
34 #define ISO15693_CMD_GET_SYS_INFO 0x2B
35 #define ISO15693_CMD_GET_BLOCK_SEC 0x2C
36 
37 #define ISO15693_REQ_FLAG_SUBCARRIER 0x01
38 #define ISO15693_REQ_FLAG_DATARATE 0x02
39 #define ISO15693_REQ_FLAG_INVENTORY 0x04
40 #define ISO15693_REQ_FLAG_PROT_EXT 0x08
41 #define ISO15693_REQ_FLAG_OPTION 0x40
42 #define ISO15693_REQ_FLAG_RFU 0x80
43 /* When INVENTORY flag is not set: */
44 #define ISO15693_REQ_FLAG_SELECT 0x10
45 #define ISO15693_REQ_FLAG_ADDRESS 0x20
46 /* When INVENTORY flag is set: */
47 #define ISO15693_REQ_FLAG_AFI 0x10
48 #define ISO15693_REQ_FLAG_NB_SLOTS 0x20
49 
50 #define ISO15693_RES_FLAG_NO_ERROR 0x00
51 #define ISO15693_RES_FLAG_ERROR 0x01
52 #define ISO15693_RES_FLAG_PROT_EXT 0x08
53 
54 #define ISO15693_RES_ERR_NOT_SUPP 0x01
55 #define ISO15693_RES_ERR_NOT_REC 0x02
56 #define ISO15693_RES_ERR_OPT_NOT_SUPP 0x03
57 #define ISO15693_RES_ERR_GENERIC 0x0F
58 #define ISO15693_RES_ERR_BLK_NOT_AVL 0x10
59 #define ISO15693_RES_ERR_BLK_ALRD_LKD 0x11
60 #define ISO15693_RES_ERR_BLK_CHG_LKD 0x12
61 #define ISO15693_RES_ERR_BLK_NOT_PRGR 0x13
62 #define ISO15693_RES_ERR_BLK_NOT_LKD 0x14
63 
64 #define ISO15693_RES_INVENTORY_DSFID 0x00
65 
66 #define ISO15693_MIN_FRAME_SIZE 0x04
67 
68 #define ISO15693_GENERIC_UID_SIZE 0x08
69 #define ISO15693_GENERIC_MEM_SIZE 8192
70 
71 #define ISO15693_CRC16_SIZE 0x2 /* Bytes */
72 #define ISO15693_CRC16_POLYNORMAL 0x8408
73 #define ISO15693_CRC16_PRESET 0xFFFF
74 
75 /* The lock status byte has bits assigned as follow */
76 #define ISO15693_MASK_UNLOCKED ( 0 << 0 )
77 #define ISO15693_MASK_USER_LOCK ( 1 << 0 )
78 #define ISO15693_MASK_FACTORY_LOCK ( 1 << 1 )
79 
80 typedef struct {
81  uint8_t *Flags;
82  uint8_t *Command;
83  uint8_t *Parameters;
84  uint8_t ParamLen;
85  bool Addressed;
86  bool Selected;
87 } CurrentFrame;
88 extern CurrentFrame FrameInfo; /* Holds current frame information */
89 extern uint8_t Uid[];
90 extern uint8_t MyAFI; /* Holds current tag's AFI, used during inventory */
91 extern uint16_t ResponseByteCount; /* Length of response, used when building response frames */
92 
93 void ISO15693AppendCRC(uint8_t *FrameBuf, uint16_t FrameBufSize);
94 bool ISO15693CheckCRC(void *FrameBuf, uint16_t FrameBufSize);
95 bool ISO15693PrepareFrame(uint8_t *FrameBuf, uint16_t FrameBytes, CurrentFrame *FrameStruct, uint8_t IsSelected, uint8_t *MyUid, uint8_t MyAFI);
96 bool ISO15693AntiColl(uint8_t *FrameBuf, uint16_t FrameBytes, CurrentFrame *FrameStruct, uint8_t *MyUid);
97 
98 INLINE
99 bool ISO15693CompareUid(uint8_t *Uid1, uint8_t *Uid2) {
100  if ((Uid1[0] == Uid2[7])
101  && (Uid1[1] == Uid2[6])
102  && (Uid1[2] == Uid2[5])
103  && (Uid1[3] == Uid2[4])
104  && (Uid1[4] == Uid2[3])
105  && (Uid1[5] == Uid2[2])
106  && (Uid1[6] == Uid2[1])
107  && (Uid1[7] == Uid2[0])) {
108  return true;
109  } else {
110  return false;
111  }
112 }
113 
114 INLINE
115 void ISO15693CopyUid(uint8_t *DstUid, uint8_t *SrcUid) {
116  DstUid[0] = SrcUid[7];
117  DstUid[1] = SrcUid[6];
118  DstUid[2] = SrcUid[5];
119  DstUid[3] = SrcUid[4];
120  DstUid[4] = SrcUid[3];
121  DstUid[5] = SrcUid[2];
122  DstUid[6] = SrcUid[1];
123  DstUid[7] = SrcUid[0];
124 }
125 
126 INLINE
127 bool ISO15693Addressed(uint8_t *Buffer) {
128  return (Buffer[ISO15693_ADDR_FLAGS] & ISO15693_REQ_FLAG_ADDRESS); /* if the flag is set, the command is addressed */
129 }
130 
131 
132 INLINE
133 bool ISO15693AddressedLegacy(uint8_t *Buffer, uint8_t *MyUid) {
134  if (Buffer[0] & ISO15693_REQ_FLAG_ADDRESS) {
135  /* Addressed mode */
136  if (ISO15693CompareUid(&Buffer[2], MyUid)) {
137  /* Our UID addressed */
138  return true;
139  } else {
140  /* Our UID not addressed */
141  return false;
142  }
143  } else {
144  /* Non-Addressed mode */
145  return true;
146  }
147 }
148 
149 #endif /* ISO15693_3_H_ */
diff --git a/Doc/Doxygen/html/_i_s_o15693_8h_source.html b/Doc/Doxygen/html/_i_s_o15693_8h_source.html index 0a430861..8e14a1e2 100644 --- a/Doc/Doxygen/html/_i_s_o15693_8h_source.html +++ b/Doc/Doxygen/html/_i_s_o15693_8h_source.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: ISO15693.h Source File @@ -11,9 +12,6 @@ - @@ -31,40 +29,19 @@ - + - - + + + +
1 /*
2  * ISO15693.h
3  *
4  * Created on: 25.01.2017
5  * Author: Phillip Nash
6  */
7 
8 #ifndef ISO15693_H_
9 #define ISO15693_H_
10 
11 #define ISO15693_APP_NO_RESPONSE 0x0000
12 
13 /* Codec Interface */
14 void ISO15693CodecInit(void);
15 void ISO15693CodecDeInit(void);
16 void ISO15693CodecTask(void);
17 
18 /* Application Interface */
19 void ISO15693CodecStart(void);
20 void ISO15693CodecReset(void);
21 
22 #endif /* ISO15693_H_ */
diff --git a/Doc/Doxygen/html/_l_e_d_8h_source.html b/Doc/Doxygen/html/_l_e_d_8h_source.html index 830633b0..a43f7c92 100644 --- a/Doc/Doxygen/html/_l_e_d_8h_source.html +++ b/Doc/Doxygen/html/_l_e_d_8h_source.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: LED.h Source File @@ -11,9 +12,6 @@ - @@ -31,40 +29,19 @@ - + - - + + + +
1 /*
2  * LED.h
3  *
4  * Created on: 10.02.2013
5  * Author: skuser
6  */
7 
8 #ifndef LED_H
9 #define LED_H
10 
11 #include <avr/io.h>
12 #include "Common.h"
13 
14 #define LED_PORT PORTA
15 #define LED_GREEN PIN4_bm
16 #define LED_RED PIN3_bm
17 #define LED_MASK (LED_GREEN | LED_RED)
18 
19 typedef enum LEDFunctionEnum {
20  LED_NO_FUNC = 0, /* Don't light up the LED */
21  LED_POWERED, /* Light up the LED whenever the Chameleon is powered */
22 
23  LED_TERMINAL_CONN, /* A Terminal/USB connection has been established */
24  LED_TERMINAL_RXTX, /* There is traffic on the terminal */
25 
26  LED_SETTING_CHANGE, /* Outputs a blink code that shows the current setting */
27 
28  LED_MEMORY_STORED, /* Blink once when memory has been stored to flash */
29  LED_MEMORY_CHANGED, /* Switch LED on when card memory has changed compared to flash */
30 
31  LED_FIELD_DETECTED, /* Shows LED while a reader field is being detected or turned on by the chameleon itself */
32 
33  LED_CODEC_RX, /* Blink LED when receiving codec data */
34  LED_CODEC_TX, /* Blink LED when transmitting codec data */
35 
36  LED_LOG_MEM_FULL, /* Light up if log memory is full. */
37 
38  //TODO: LED_APP_SELECTED, /* Show LED while the correct UID has been selected and the application is active */
39  /* Has to be last element */
40  LED_FUNC_COUNT
41 } LEDHookEnum;
42 
43 typedef enum LEDActionEnum {
44  LED_NO_ACTION = 0x00,
45  LED_OFF = 0x10,
46  LED_ON = 0x11,
47  LED_TOGGLE = 0x12,
48  LED_PULSE = 0x13,
49  LED_BLINK = 0x20,
50  LED_BLINK_1X = 0x20,
51  LED_BLINK_2X, /* Have to be sequentially ordered */
52  LED_BLINK_3X,
53  LED_BLINK_4X,
54  LED_BLINK_5X,
55  LED_BLINK_6X,
56  LED_BLINK_7X,
57  LED_BLINK_8X,
58 } LEDActionEnum;
59 
60 
61 
62 void LEDInit(void);
63 void LEDTick(void);
64 
65 void LEDGetFuncList(char *List, uint16_t BufferSize);
66 void LEDSetFuncById(uint8_t Mask, LEDHookEnum Func);
67 void LEDGetFuncByName(uint8_t Mask, char *Function, uint16_t BufferSize);
68 bool LEDSetFuncByName(uint8_t Mask, const char *Function);
69 
70 #endif /* LED_H */
diff --git a/Doc/Doxygen/html/_l_e_d_8txt.html b/Doc/Doxygen/html/_l_e_d_8txt.html index 952055d3..eddf8199 100644 --- a/Doc/Doxygen/html/_l_e_d_8txt.html +++ b/Doc/Doxygen/html/_l_e_d_8txt.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: LED.txt File Reference @@ -11,9 +12,6 @@ - @@ -31,40 +29,19 @@ - + - - + + + +
diff --git a/Doc/Doxygen/html/_l_e_d_hook_8h_source.html b/Doc/Doxygen/html/_l_e_d_hook_8h_source.html index aeae93a1..dbf2e294 100644 --- a/Doc/Doxygen/html/_l_e_d_hook_8h_source.html +++ b/Doc/Doxygen/html/_l_e_d_hook_8h_source.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: LEDHook.h Source File @@ -11,9 +12,6 @@ - @@ -31,40 +29,19 @@
- + - - + + + +
diff --git a/Doc/Doxygen/html/_l_e_ds_8txt.html b/Doc/Doxygen/html/_l_e_ds_8txt.html index c49e87d5..1a04f5c2 100644 --- a/Doc/Doxygen/html/_l_e_ds_8txt.html +++ b/Doc/Doxygen/html/_l_e_ds_8txt.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: LEDs.txt File Reference @@ -11,9 +12,6 @@ - @@ -31,40 +29,19 @@ - + - - + + + +
diff --git a/Doc/Doxygen/html/_l_u_f_a_config_8h.html b/Doc/Doxygen/html/_l_u_f_a_config_8h.html index f977ec3b..4a93c712 100644 --- a/Doc/Doxygen/html/_l_u_f_a_config_8h.html +++ b/Doc/Doxygen/html/_l_u_f_a_config_8h.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: LUFAConfig.h File Reference @@ -11,9 +12,6 @@ - @@ -31,40 +29,19 @@
- + - - + + + +
diff --git a/Doc/Doxygen/html/_l_u_f_a_config_8h_source.html b/Doc/Doxygen/html/_l_u_f_a_config_8h_source.html index 156d1761..1c1e35cd 100644 --- a/Doc/Doxygen/html/_l_u_f_a_config_8h_source.html +++ b/Doc/Doxygen/html/_l_u_f_a_config_8h_source.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: LUFAConfig.h Source File @@ -11,9 +12,6 @@ - @@ -31,40 +29,19 @@ - + - - + + + +
Go to the documentation of this file.
1 /*
2  LUFA Library
3  Copyright (C) Dean Camera, 2012.
4 
5  dean [at] fourwalledcubicle [dot] com
6  www.lufa-lib.org
7 */
8 
9 /*
10  Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com)
11 
12  Permission to use, copy, modify, distribute, and sell this
13  software and its documentation for any purpose is hereby granted
14  without fee, provided that the above copyright notice appear in
15  all copies and that both that the copyright notice and this
16  permission notice and warranty disclaimer appear in supporting
17  documentation, and that the name of the author not be used in
18  advertising or publicity pertaining to distribution of the
19  software without specific, written prior permission.
20 
21  The author disclaim all warranties with regard to this
22  software, including all implied warranties of merchantability
23  and fitness. In no event shall the author be liable for any
24  special, indirect or consequential damages or any damages
25  whatsoever resulting from loss of use, data or profits, whether
26  in an action of contract, negligence or other tortious action,
27  arising out of or in connection with the use or performance of
28  this software.
29 */
30 
42 #ifndef _LUFA_CONFIG_H_
43 #define _LUFA_CONFIG_H_
44 
45 /* Non-USB Related Configuration Tokens: */
46 // #define DISABLE_TERMINAL_CODES
47 
48 /* USB Class Driver Related Tokens: */
49 // #define HID_HOST_BOOT_PROTOCOL_ONLY
50 // #define HID_STATETABLE_STACK_DEPTH {Insert Value Here}
51 // #define HID_USAGE_STACK_DEPTH {Insert Value Here}
52 // #define HID_MAX_COLLECTIONS {Insert Value Here}
53 // #define HID_MAX_REPORTITEMS {Insert Value Here}
54 // #define HID_MAX_REPORT_IDS {Insert Value Here}
55 // #define NO_CLASS_DRIVER_AUTOFLUSH
56 
57 /* General USB Driver Related Tokens: */
58 #define USE_STATIC_OPTIONS \
59  (USB_OPT_BUSEVENT_PRIMED | USB_DEVICE_OPT_FULLSPEED | /*USB_OPT_PLLCLKSRC*/ USB_OPT_RC32MCLKSRC)
60 #define USB_DEVICE_ONLY
61 // #define USB_STREAM_TIMEOUT_MS {Insert Value Here}
62 // #define NO_LIMITED_CONTROLLER_CONNECT
63 // #define NO_SOF_EVENTS
64 
65 /* USB Device Mode Driver Related Tokens: */
66 // #define USE_RAM_DESCRIPTORS
67 #define USE_FLASH_DESCRIPTORS
68 // #define USE_EEPROM_DESCRIPTORS
69 #define NO_INTERNAL_SERIAL
70 //#undef NO_INTERNAL_SERIAL
71 #define FIXED_CONTROL_ENDPOINT_SIZE 8
72 // #define DEVICE_STATE_AS_GPIOR {Insert Value Here}
73 #define FIXED_NUM_CONFIGURATIONS 1
74 // #define CONTROL_ONLY_DEVICE
75 #ifndef MAX_ENDPOINT_INDEX
76 #define MAX_ENDPOINT_INDEX 4 // 5
77 #endif
78 // #define NO_DEVICE_REMOTE_WAKEUP
79 // #define NO_DEVICE_SELF_POWER
80 #undef NO_DEVICE_SELF_POWER
81 
82 #endif
diff --git a/Doc/Doxygen/html/_l_u_f_a_descriptors_8c.html b/Doc/Doxygen/html/_l_u_f_a_descriptors_8c.html index 0e77a215..d00b2593 100644 --- a/Doc/Doxygen/html/_l_u_f_a_descriptors_8c.html +++ b/Doc/Doxygen/html/_l_u_f_a_descriptors_8c.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: LUFADescriptors.c File Reference @@ -11,9 +12,6 @@ - @@ -31,40 +29,19 @@ - + - - + + + +

Detailed Description

USB Device Descriptors, for library use when in USB device mode. Descriptors are special computer-readable structures which the host requests upon device enumeration, to determine the device's capabilities and functions.

Function Documentation

- + +

◆ CALLBACK_USB_GetDescriptor()

+
@@ -150,7 +129,9 @@

Variable Documentation

- + +

◆ DeviceDescriptor

+
@@ -163,7 +144,9 @@

Variable Documentation

- + +

◆ ConfigurationDescriptor

+
@@ -176,7 +159,9 @@

Variable Documentation

- + +

◆ LanguageString

+
@@ -189,7 +174,9 @@

Variable Documentation

- + +

◆ ManufacturerString

+
@@ -202,7 +189,9 @@

Variable Documentation

- + +

◆ ProductString

+
@@ -218,9 +207,9 @@

Variable Documentation

diff --git a/Doc/Doxygen/html/_l_u_f_a_descriptors_8h.html b/Doc/Doxygen/html/_l_u_f_a_descriptors_8h.html index 77395d0f..6d0a067e 100644 --- a/Doc/Doxygen/html/_l_u_f_a_descriptors_8h.html +++ b/Doc/Doxygen/html/_l_u_f_a_descriptors_8h.html @@ -3,7 +3,8 @@ - + +Chameleon-Mini: LUFADescriptors.h File Reference @@ -11,9 +12,6 @@ - @@ -31,40 +29,19 @@
- + - - + + + +

Detailed Description

Header file for Descriptors.c.

Macro Definition Documentation

- + +

◆ CDC_NOTIFICATION_EPADDR

+
@@ -137,7 +116,9 @@ - + +

◆ CDC_TX_EPADDR

+
@@ -150,7 +131,9 @@ - + +

◆ CDC_RX_EPADDR

+
@@ -163,7 +146,9 @@ - + +

◆ CDC_NOTIFICATION_EPSIZE

+
@@ -176,7 +161,9 @@ - + +

◆ CDC_TXRX_EPSIZE

+
@@ -190,7 +177,9 @@

Function Documentation

- + +

◆ CALLBACK_USB_GetDescriptor()

+
@@ -226,9 +215,9 @@

Function Documentation

diff --git a/Doc/Doxygen/html/_l_u_f_a_descriptors_8h_source.html b/Doc/Doxygen/html/_l_u_f_a_descriptors_8h_source.html index 1f7b6172..793deb0b 100644 --- a/Doc/Doxygen/html/_l_u_f_a_descriptors_8h_source.html +++ b/Doc/Doxygen/html/_l_u_f_a_descriptors_8h_source.html @@ -3,7 +3,8 @@ - + +Chameleon-Mini: LUFADescriptors.h Source File @@ -11,9 +12,6 @@ - @@ -31,40 +29,19 @@
- + - - + + + +
diff --git a/Doc/Doxygen/html/_live_log_tick_8h_source.html b/Doc/Doxygen/html/_live_log_tick_8h_source.html index 6f052b6b..bcda8874 100644 --- a/Doc/Doxygen/html/_live_log_tick_8h_source.html +++ b/Doc/Doxygen/html/_live_log_tick_8h_source.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: LiveLogTick.h Source File @@ -11,9 +12,6 @@ - @@ -31,40 +29,19 @@
- + - - + + + +
LiveLogTick.h
-
1 /* LiveLogTick.h : Handle flushing of live logging buffers out through USB
2  * by an atomic code block with interrupts disabled.
3  * If there are many logs being generated at once, this will maintain
4  * consistency in the returned buffers and prevent the contents of
5  * USB serial data from getting jumbled or concatenated.
6  */
7 
8 #ifndef __LIVE_LOG_TICK_H__
9 #define __LIVE_LOG_TICK_H__
10 
11 #include <inttypes.h>
12 #include <stdlib.h>
13 #include <avr/interrupt.h>
14 #include <avr/io.h>
15 #include <util/atomic.h>
16 
17 #include "LUFADescriptors.h"
18 
19 #include "Log.h"
20 #include "Terminal/Terminal.h"
21 
22 #define cli_memory() __asm volatile( "cli" ::: "memory" )
23 #define sei_memory() __asm volatile( "sei" ::: "memory" )
24 
25 #ifndef FLUSH_LOGS_ON_SPACE_ERROR
26 #define FLUSH_LOGS_ON_SPACE_ERROR (1)
27 #endif
28 typedef struct LogBlockListNode {
29  uint8_t *logBlockDataStart;
30  uint8_t logBlockDataSize;
31  struct LogBlockListNode *nextBlock;
32 } LogBlockListNode;
33 
34 #define LOG_BLOCK_LIST_NODE_SIZE (sizeof(LogBlockListNode) + 4 - (uint8_t) (sizeof(LogBlockListNode) % 4))
35 extern LogBlockListNode *LogBlockListBegin;
36 extern LogBlockListNode *LogBlockListEnd;
37 extern uint8_t LogBlockListElementCount;
38 
39 #define LIVE_LOGGER_POST_TICKS (3)
40 extern uint8_t LiveLogModePostTickCount;
41 
42 INLINE bool AtomicAppendLogBlock(LogEntryEnum logCode, uint16_t sysTickTime, const uint8_t *logData, uint8_t logDataSize);
43 INLINE void FreeLogBlocks(void);
44 INLINE bool AtomicLiveLogTick(void);
45 INLINE bool LiveLogTick(void);
46 
47 INLINE bool
48 AtomicAppendLogBlock(LogEntryEnum logCode, uint16_t sysTickTime, const uint8_t *logData, uint8_t logDataSize) {
49  bool status = true;
50  if((logDataSize + 4 + 3 + LOG_BLOCK_LIST_NODE_SIZE > LogMemLeft) && (LogMemPtr != LogMem)) {
51  if(FLUSH_LOGS_ON_SPACE_ERROR) {
52  LiveLogTick();
53  FreeLogBlocks();
54  }
55  status = false;
56  }
57  else if(logDataSize + 4 + 3 + LOG_BLOCK_LIST_NODE_SIZE <= LogMemLeft) {
58  uint8_t alignOffset = 4 - (uint8_t) (((uint16_t) LogMemPtr) % 4);
59  uint8_t *logBlockStart = LogMemPtr + alignOffset;
60  LogBlockListNode logBlock;
61  LogMemPtr += LOG_BLOCK_LIST_NODE_SIZE + alignOffset;
62  LogMemLeft -= LOG_BLOCK_LIST_NODE_SIZE + alignOffset;
63  logBlock.logBlockDataStart = LogMemPtr;
64  logBlock.logBlockDataSize = logDataSize + 4;
65  logBlock.nextBlock = 0;
66  *(LogMemPtr++) = (uint8_t) logCode;
67  *(LogMemPtr++) = logDataSize;
68  *(LogMemPtr++) = (uint8_t) (sysTickTime >> 8);
69  *(LogMemPtr++) = (uint8_t) (sysTickTime >> 0);
70  memcpy(LogMemPtr, logData, logDataSize);
71  LogMemPtr += logDataSize;
72  LogMemLeft -= logDataSize + 4;
73  memcpy(logBlockStart, &logBlock, sizeof(LogBlockListNode));
74  if(LogBlockListBegin != NULL && LogBlockListEnd != NULL) {
75  LogBlockListEnd->nextBlock = (LogBlockListNode *) logBlockStart;
76  LogBlockListEnd = (LogBlockListNode *) logBlockStart;
77  }
78  else {
79  LogBlockListBegin = LogBlockListEnd = (LogBlockListNode *) logBlockStart;
80  }
81  ++LogBlockListElementCount;
82  }
83  else {
84  status = false;
85  }
86  return status;
87 }
88 
89 INLINE void
90 FreeLogBlocks(void) {
91  LogMemPtr = &LogMem[0];
92  LogMemLeft = LOG_SIZE;
93  LogBlockListBegin = LogBlockListEnd = NULL;
94  LogBlockListElementCount = 0;
95 }
96 
97 INLINE bool
98 AtomicLiveLogTick(void) {
99  return LiveLogTick();
100 }
101 
102 INLINE bool
103 LiveLogTick(void) {
104  LogBlockListNode logBlockCurrent, *tempBlockPtr = NULL;
105  memcpy(&logBlockCurrent, LogBlockListBegin, sizeof(LogBlockListNode));
106  while(LogBlockListElementCount > 0) {
107  TerminalFlushBuffer();
108  TerminalSendBlock(logBlockCurrent.logBlockDataStart, logBlockCurrent.logBlockDataSize);
109  TerminalFlushBuffer();
110  tempBlockPtr = logBlockCurrent.nextBlock;
111  if(tempBlockPtr != NULL) {
112  memcpy(&logBlockCurrent, tempBlockPtr, sizeof(LogBlockListNode));
113  }
114  else {
115  break;
116  }
117  --LogBlockListElementCount;
118  }
119  FreeLogBlocks();
120  LiveLogModePostTickCount = 0;
121  return true;
122 }
123 
124 #endif
LogEntryEnum
Definition: Log.h:16
+
1 /* LiveLogTick.h : Handle flushing of live logging buffers out through USB
2  * by an atomic code block with interrupts disabled.
3  * If there are many logs being generated at once, this will maintain
4  * consistency in the returned buffers and prevent the contents of
5  * USB serial data from getting jumbled or concatenated.
6  */
7 
8 #ifndef __LIVE_LOG_TICK_H__
9 #define __LIVE_LOG_TICK_H__
10 
11 #include <inttypes.h>
12 #include <stdlib.h>
13 #include <avr/interrupt.h>
14 #include <avr/io.h>
15 #include <util/atomic.h>
16 
17 #include "LUFADescriptors.h"
18 
19 #include "Log.h"
20 #include "Terminal/Terminal.h"
21 
22 #define cli_memory() __asm volatile( "cli" ::: "memory" )
23 #define sei_memory() __asm volatile( "sei" ::: "memory" )
24 
25 #ifndef FLUSH_LOGS_ON_SPACE_ERROR
26 #define FLUSH_LOGS_ON_SPACE_ERROR (1)
27 #endif
28 typedef struct LogBlockListNode {
29  uint8_t *logBlockDataStart;
30  uint8_t logBlockDataSize;
31  struct LogBlockListNode *nextBlock;
32 } LogBlockListNode;
33 
34 #define LOG_BLOCK_LIST_NODE_SIZE (sizeof(LogBlockListNode) + 4 - (uint8_t) (sizeof(LogBlockListNode) % 4))
35 extern LogBlockListNode *LogBlockListBegin;
36 extern LogBlockListNode *LogBlockListEnd;
37 extern uint8_t LogBlockListElementCount;
38 
39 #define LIVE_LOGGER_POST_TICKS (6)
40 extern uint8_t LiveLogModePostTickCount;
41 
42 INLINE bool AtomicAppendLogBlock(LogEntryEnum logCode, uint16_t sysTickTime, const uint8_t *logData, uint8_t logDataSize);
43 INLINE void FreeLogBlocks(void);
44 INLINE bool AtomicLiveLogTick(void);
45 INLINE bool LiveLogTick(void);
46 
47 INLINE bool
48 AtomicAppendLogBlock(LogEntryEnum logCode, uint16_t sysTickTime, const uint8_t *logData, uint8_t logDataSize) {
49  bool status = true;
50  if ((logDataSize + 4 + 3 + LOG_BLOCK_LIST_NODE_SIZE > LogMemLeft) && (LogMemPtr != LogMem)) {
51  if (FLUSH_LOGS_ON_SPACE_ERROR) {
52  LiveLogTick();
53  FreeLogBlocks();
54  }
55  status = false;
56  } else if (logDataSize + 4 + 3 + LOG_BLOCK_LIST_NODE_SIZE <= LogMemLeft) {
57  uint8_t alignOffset = 4 - (uint8_t)(((uint16_t) LogMemPtr) % 4);
58  uint8_t *logBlockStart = LogMemPtr + alignOffset;
59  LogBlockListNode logBlock;
60  LogMemPtr += LOG_BLOCK_LIST_NODE_SIZE + alignOffset;
61  LogMemLeft -= LOG_BLOCK_LIST_NODE_SIZE + alignOffset;
62  logBlock.logBlockDataStart = LogMemPtr;
63  logBlock.logBlockDataSize = logDataSize + 4;
64  logBlock.nextBlock = 0;
65  *(LogMemPtr++) = (uint8_t) logCode;
66  *(LogMemPtr++) = logDataSize;
67  *(LogMemPtr++) = (uint8_t)(sysTickTime >> 8);
68  *(LogMemPtr++) = (uint8_t)(sysTickTime >> 0);
69  memcpy(LogMemPtr, logData, logDataSize);
70  LogMemPtr += logDataSize;
71  LogMemLeft -= logDataSize + 4;
72  memcpy(logBlockStart, &logBlock, sizeof(LogBlockListNode));
73  if (LogBlockListBegin != NULL && LogBlockListEnd != NULL) {
74  LogBlockListEnd->nextBlock = (LogBlockListNode *) logBlockStart;
75  LogBlockListEnd = (LogBlockListNode *) logBlockStart;
76  } else {
77  LogBlockListBegin = LogBlockListEnd = (LogBlockListNode *) logBlockStart;
78  }
79  ++LogBlockListElementCount;
80  } else {
81  status = false;
82  }
83  return status;
84 }
85 
86 INLINE void
87 FreeLogBlocks(void) {
88  LogMemPtr = &LogMem[0];
89  LogMemLeft = LOG_SIZE;
90  LogBlockListBegin = LogBlockListEnd = NULL;
91  LogBlockListElementCount = 0;
92 }
93 
94 INLINE bool
95 AtomicLiveLogTick(void) {
96  return LiveLogTick();
97 }
98 
99 INLINE bool
100 LiveLogTick(void) {
101  LogBlockListNode logBlockCurrent, *tempBlockPtr = NULL;
102  memcpy(&logBlockCurrent, LogBlockListBegin, sizeof(LogBlockListNode));
103  while (LogBlockListElementCount > 0) {
104  TerminalFlushBuffer();
105  TerminalSendBlock(logBlockCurrent.logBlockDataStart, logBlockCurrent.logBlockDataSize);
106  TerminalFlushBuffer();
107  tempBlockPtr = logBlockCurrent.nextBlock;
108  if (tempBlockPtr != NULL) {
109  memcpy(&logBlockCurrent, tempBlockPtr, sizeof(LogBlockListNode));
110  } else {
111  break;
112  }
113  --LogBlockListElementCount;
114  }
115  FreeLogBlocks();
116  LiveLogModePostTickCount = 0;
117  return true;
118 }
119 
120 #endif
LogEntryEnum
Definition: Log.h:16
diff --git a/Doc/Doxygen/html/_log_8h.html b/Doc/Doxygen/html/_log_8h.html index 1e5846a8..ba8a23b1 100644 --- a/Doc/Doxygen/html/_log_8h.html +++ b/Doc/Doxygen/html/_log_8h.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: Log.h File Reference @@ -11,9 +12,6 @@ - @@ -31,40 +29,19 @@
- + - - + + + +

Enumerations

+enum  LogEntryEnum {
+  LOG_INFO_GENERIC = 0x10, +LOG_INFO_CONFIG_SET = 0x11, +LOG_INFO_SETTING_SET = 0x12, +LOG_INFO_UID_SET = 0x13, +
+  LOG_INFO_RESET_APP = 0x20, +LOG_INFO_CODEC_RX_DATA = 0x40, +LOG_INFO_CODEC_TX_DATA = 0x41, +LOG_INFO_CODEC_RX_DATA_W_PARITY = 0x42, +
+  LOG_INFO_CODEC_TX_DATA_W_PARITY = 0x43 +, LOG_INFO_CODEC_READER_FIELD_DETECTED = 0x48, +LOG_INFO_APP_CMD_READ = 0x80, +LOG_INFO_APP_CMD_WRITE = 0x81, +
+  LOG_INFO_APP_CMD_INC = 0x84, +LOG_INFO_APP_CMD_DEC = 0x85, +LOG_INFO_APP_CMD_TRANSFER = 0x86, +LOG_INFO_APP_CMD_RESTORE = 0x87, +
+  LOG_INFO_APP_CMD_AUTH = 0x90, +LOG_INFO_APP_CMD_HALT = 0x91, +LOG_INFO_APP_CMD_UNKNOWN = 0x92, +LOG_INFO_APP_AUTHING = 0xA0, +
+  LOG_INFO_APP_AUTHED = 0xA1, +LOG_ERR_APP_AUTH_FAIL = 0xC0, +LOG_ERR_APP_CHECKSUM_FAIL = 0xC1, +LOG_ERR_APP_NOT_AUTHED = 0xC2, +
+  LOG_INFO_SYSTEM_BOOT = 0xFF, +LOG_EMPTY = 0x00 +
+ } + 

Enumeration Type Documentation

- + +

◆ LogEntryEnum

+
@@ -110,83 +125,57 @@

Enumeration Type Documentation

Enum for log entry type.

Note
Every entry type has a specific integer value, which can be found in the source code.
- - - - - - - - - - - - - - - - - - - - - - - - - -
Enumerator
LOG_INFO_GENERIC  -

Unspecific log entry.

+
Enumerator
LOG_INFO_GENERIC 

Unspecific log entry.

LOG_INFO_CONFIG_SET  -

Configuration change.

+
LOG_INFO_CONFIG_SET 

Configuration change.

LOG_INFO_SETTING_SET  -

Setting change.

+
LOG_INFO_SETTING_SET 

Setting change.

LOG_INFO_UID_SET  -

UID change.

+
LOG_INFO_UID_SET 

UID change.

LOG_INFO_RESET_APP  -

Application reset.

+
LOG_INFO_RESET_APP 

Application reset.

LOG_INFO_CODEC_RX_DATA  -

Currently active codec received data.

+
LOG_INFO_CODEC_RX_DATA 

Currently active codec received data.

LOG_INFO_CODEC_TX_DATA  -

Currently active codec sent data.

+
LOG_INFO_CODEC_TX_DATA 

Currently active codec sent data.

LOG_INFO_CODEC_RX_DATA_W_PARITY  -

Currently active codec received data.

+
LOG_INFO_CODEC_RX_DATA_W_PARITY 

Currently active codec received data.

LOG_INFO_CODEC_TX_DATA_W_PARITY  -

Currently active codec sent data.

+
LOG_INFO_CODEC_TX_DATA_W_PARITY 

Currently active codec sent data.

LOG_INFO_CODEC_READER_FIELD_DETECTED  -

Add logging of the LEDHook case for FIELD_DETECTED.

+
LOG_INFO_CODEC_READER_FIELD_DETECTED 

Add logging of the LEDHook case for FIELD_DETECTED.

LOG_INFO_APP_CMD_READ  -

Application processed read command.

+
LOG_INFO_APP_CMD_READ 

Application processed read command.

LOG_INFO_APP_CMD_WRITE  -

Application processed write command.

+
LOG_INFO_APP_CMD_WRITE 

Application processed write command.

LOG_INFO_APP_CMD_INC  -

Application processed increment command.

+
LOG_INFO_APP_CMD_INC 

Application processed increment command.

LOG_INFO_APP_CMD_DEC  -

Application processed decrement command.

+
LOG_INFO_APP_CMD_DEC 

Application processed decrement command.

LOG_INFO_APP_CMD_TRANSFER  -

Application processed transfer command.

+
LOG_INFO_APP_CMD_TRANSFER 

Application processed transfer command.

LOG_INFO_APP_CMD_RESTORE  -

Application processed restore command.

+
LOG_INFO_APP_CMD_RESTORE 

Application processed restore command.

LOG_INFO_APP_CMD_AUTH  -

Application processed authentication command.

+
LOG_INFO_APP_CMD_AUTH 

Application processed authentication command.

LOG_INFO_APP_CMD_HALT  -

Application processed halt command.

+
LOG_INFO_APP_CMD_HALT 

Application processed halt command.

LOG_INFO_APP_CMD_UNKNOWN  -

Application processed an unknown command.

+
LOG_INFO_APP_CMD_UNKNOWN 

Application processed an unknown command.

LOG_INFO_APP_AUTHING  -

Application is in authing state.

+
LOG_INFO_APP_AUTHING 

Application is in authing state.

LOG_INFO_APP_AUTHED  -

Application is in auth state.

+
LOG_INFO_APP_AUTHED 

Application is in auth state.

LOG_ERR_APP_AUTH_FAIL  -

Application authentication failed.

+
LOG_ERR_APP_AUTH_FAIL 

Application authentication failed.

LOG_ERR_APP_CHECKSUM_FAIL  -

Application had a checksum fail.

+
LOG_ERR_APP_CHECKSUM_FAIL 

Application had a checksum fail.

LOG_ERR_APP_NOT_AUTHED  -

Application is not authenticated.

+
LOG_ERR_APP_NOT_AUTHED 

Application is not authenticated.

LOG_INFO_SYSTEM_BOOT  -

Chameleon boots.

+
LOG_INFO_SYSTEM_BOOT 

Chameleon boots.

LOG_EMPTY  -

nor the two systick bytes nor any data.

+
LOG_EMPTY 

nor the two systick bytes nor any data.

Empty Log Entry. This is not followed by a length byte

@@ -196,9 +185,9 @@

Enumeration Type Documentation

diff --git a/Doc/Doxygen/html/_log_8h_source.html b/Doc/Doxygen/html/_log_8h_source.html index 6193a8d0..35179eb3 100644 --- a/Doc/Doxygen/html/_log_8h_source.html +++ b/Doc/Doxygen/html/_log_8h_source.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: Log.h Source File @@ -11,9 +12,6 @@ - @@ -31,40 +29,19 @@
- + - - + + + +
Log.h
-Go to the documentation of this file.
1 #ifndef LOG_H_
2 #define LOG_H_
3 
4 #include "Common.h"
5 
6 #define LOG_SIZE 2048
7 #define FRAM_LOG_ADDR_ADDR 0x4000 // start of the second half of FRAM
8 #define FRAM_LOG_START_ADDR 0x4002 // directly after the address
9 #define FRAM_LOG_SIZE 0x3FFE // the whole second half (minus the 2 Bytes of Address)
10 
11 extern uint8_t LogMem[LOG_SIZE];
12 extern uint8_t *LogMemPtr;
13 extern uint16_t LogMemLeft;
14 
16 typedef enum {
17  /* Generic */
23 
24  /* Codec */
29  LOG_INFO_CODEC_SNI_READER_DATA = 0x44, //< Sniffing codec receive data from reader
30  LOG_INFO_CODEC_SNI_READER_DATA_W_PARITY = 0x45, //< Sniffing codec receive data from reader
31  LOG_INFO_CODEC_SNI_CARD_DATA = 0x46, //< Sniffing codec receive data from card
32  LOG_INFO_CODEC_SNI_CARD_DATA_W_PARITY = 0x47, //< Sniffing codec receive data from card
34 
35  /* App */
50 
51  /* DESFire emulation and development related logging messages (0xEx): */
52  #ifdef CONFIG_MF_DESFIRE_SUPPORT
53  #include "Application/DESFire/DESFireLoggingCodesInclude.c"
54  #endif
55 
57  LOG_EMPTY = 0x00
58 } LogEntryEnum;
60 
61 typedef enum {
62  LOG_MODE_OFF,
63  LOG_MODE_MEMORY,
64  LOG_MODE_LIVE
65 } LogModeEnum;
66 
67 typedef void (*LogFuncType)(LogEntryEnum Entry, const void *Data, uint8_t Length);
68 
69 extern LogFuncType CurrentLogFunc;
70 
71 void LogInit(void);
72 void LogTick(void);
73 void LogTask(void);
74 
75 void LogMemClear(void);
76 uint16_t LogMemFree(void);
77 /* XModem callback */
78 bool LogMemLoadBlock(void *Buffer, uint32_t BlockAddress, uint16_t ByteCount);
79 
80 void LogSetModeById(LogModeEnum Mode);
81 bool LogSetModeByName(const char *Mode);
82 void LogGetModeByName(char *Mode, uint16_t BufferSize);
83 void LogGetModeList(char *List, uint16_t BufferSize);
84 void LogSRAMToFRAM(void);
85 
86 /* Wrapper function to call current logging function */
87 INLINE void LogEntry(LogEntryEnum Entry, const void *Data, uint8_t Length) { CurrentLogFunc(Entry, Data, Length); }
88 
89 #endif /* LOG_H_ */
Application processed authentication command.
Definition: Log.h:42
+Go to the documentation of this file.
1 #ifndef LOG_H_
2 #define LOG_H_
3 
4 #include "Common.h"
5 
6 #define LOG_SIZE 2048
7 #define FRAM_LOG_ADDR_ADDR 0x4000 // start of the second half of FRAM
8 #define FRAM_LOG_START_ADDR 0x4002 // directly after the address
9 #define FRAM_LOG_SIZE 0x3FFE // the whole second half (minus the 2 Bytes of Address)
10 
11 extern uint8_t LogMem[LOG_SIZE];
12 extern uint8_t *LogMemPtr;
13 extern uint16_t LogMemLeft;
14 
16 typedef enum {
17  /* Generic */
23 
24  /* Codec */
29  LOG_INFO_CODEC_SNI_READER_DATA = 0x44, //< Sniffing codec receive data from reader
30  LOG_INFO_CODEC_SNI_READER_DATA_W_PARITY = 0x45, //< Sniffing codec receive data from reader
31  LOG_INFO_CODEC_SNI_CARD_DATA = 0x46, //< Sniffing codec receive data from card
32  LOG_INFO_CODEC_SNI_CARD_DATA_W_PARITY = 0x47, //< Sniffing codec receive data from card
34 
35  /* App */
50 
51  /* DESFire emulation and development related logging messages (0xEx): */
52 #ifdef CONFIG_MF_DESFIRE_SUPPORT
53 #include "Application/DESFire/DESFireLoggingCodesInclude.c"
54 #endif
55 
57  LOG_EMPTY = 0x00
58 } LogEntryEnum;
60 
61 typedef enum {
62  LOG_MODE_OFF,
63  LOG_MODE_MEMORY,
64  LOG_MODE_LIVE
65 } LogModeEnum;
66 
67 typedef void (*LogFuncType)(LogEntryEnum Entry, const void *Data, uint8_t Length);
68 
69 extern LogFuncType CurrentLogFunc;
70 
71 void LogInit(void);
72 void LogTick(void);
73 void LogTask(void);
74 
75 void LogMemClear(void);
76 uint16_t LogMemFree(void);
77 /* XModem callback */
78 bool LogMemLoadBlock(void *Buffer, uint32_t BlockAddress, uint16_t ByteCount);
79 
80 void LogSetModeById(LogModeEnum Mode);
81 bool LogSetModeByName(const char *Mode);
82 void LogGetModeByName(char *Mode, uint16_t BufferSize);
83 void LogGetModeList(char *List, uint16_t BufferSize);
84 void LogSRAMToFRAM(void);
85 
86 /* Wrapper function to call current logging function */
87 INLINE void LogEntry(LogEntryEnum Entry, const void *Data, uint8_t Length) { CurrentLogFunc(Entry, Data, Length); }
88 
89 #endif /* LOG_H_ */
Application processed authentication command.
Definition: Log.h:42
Chameleon boots.
Definition: Log.h:56
Application authentication failed.
Definition: Log.h:47
Application is in auth state.
Definition: Log.h:46
@@ -119,9 +96,9 @@
diff --git a/Doc/Doxygen/html/_log_8txt.html b/Doc/Doxygen/html/_log_8txt.html index 9c437041..1cf6cfe1 100644 --- a/Doc/Doxygen/html/_log_8txt.html +++ b/Doc/Doxygen/html/_log_8txt.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: Log.txt File Reference @@ -11,9 +12,6 @@ - @@ -31,40 +29,19 @@
- + - - + + + +
diff --git a/Doc/Doxygen/html/_main_page_8txt.html b/Doc/Doxygen/html/_main_page_8txt.html index 4b5a57f5..1ef69447 100644 --- a/Doc/Doxygen/html/_main_page_8txt.html +++ b/Doc/Doxygen/html/_main_page_8txt.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: MainPage.txt File Reference @@ -11,9 +12,6 @@ - @@ -31,40 +29,19 @@
- + - - + + + +
diff --git a/Doc/Doxygen/html/_map_8h_source.html b/Doc/Doxygen/html/_map_8h_source.html index b9b69aa4..bcef3f5e 100644 --- a/Doc/Doxygen/html/_map_8h_source.html +++ b/Doc/Doxygen/html/_map_8h_source.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: Map.h Source File @@ -11,9 +12,6 @@ - @@ -31,40 +29,19 @@
- + - - + + + +
1 /*
2  * Map.h
3  *
4  * Created on: 07.12.2014
5  * Author: sk
6  */
7 
8 #ifndef MAP_H_
9 #define MAP_H_
10 
11 #include <stdint.h>
12 #include <stdbool.h>
13 #include <avr/pgmspace.h>
14 
15 #define MAP_TEXT_BUF_SIZE 32
16 #define MAP_MAX_TEXT_SIZE (MAP_TEXT_BUF_SIZE - 1)
17 
18 typedef uint8_t MapIdType;
19 typedef const char *MapTextPtrType;
20 
21 const typedef struct {
22  MapIdType Id;
23  const char Text[MAP_TEXT_BUF_SIZE];
24 } MapEntryType;
25 
26 bool MapIdToText(const MapEntryType *MapPtr, uint8_t MapSize, MapIdType Id, char *Text, uint16_t MaxBufferSize);
27 bool MapTextToId(const MapEntryType *MapPtr, uint8_t MapSize, MapTextPtrType Text, MapIdType *IdPtr);
28 void MapToString(const MapEntryType *MapPtr, uint8_t MapSize, char *String, uint16_t MaxBufferSize);
29 
30 #endif /* MAP_H_ */
diff --git a/Doc/Doxygen/html/_memory_8h_source.html b/Doc/Doxygen/html/_memory_8h_source.html index cb6c7aee..8f0f700f 100644 --- a/Doc/Doxygen/html/_memory_8h_source.html +++ b/Doc/Doxygen/html/_memory_8h_source.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: Memory.h Source File @@ -11,9 +12,6 @@ - @@ -31,40 +29,19 @@ - + - - + + + +
Memory.h
-
1 /*
2  * Flash.h
3  *
4  * Created on: 20.03.2013
5  * Author: skuser
6  */
7 
8 #ifndef MEMORY_H_
9 #define MEMORY_H_
10 
11 #define MEMORY_SIZE (FLASH_DATA_SIZE) /* From makefile */
12 #define MEMORY_INIT_VALUE 0x00
13 #define MEMORY_SIZE_PER_SETTING 8192
14 
15 #ifndef __ASSEMBLER__
16 #include "Common.h"
17 
18 void MemoryInit(void);
19 void MemoryReadBlock(void* Buffer, uint16_t Address, uint16_t ByteCount);
20 void MemoryReadBlockInSetting(void* Buffer, uint16_t Address, uint16_t ByteCount);
21 void MemoryWriteBlock(const void* Buffer, uint16_t Address, uint16_t ByteCount);
22 void MemoryWriteBlockInSetting(const void* Buffer, uint16_t Address, uint16_t ByteCount);
23 void MemoryClear(void);
24 
25 void MemoryRecall(void);
26 void MemoryStore(void);
27 
28 /* For use with XModem */
29 bool MemoryUploadBlock(void *Buffer, uint32_t BlockAddress, uint16_t ByteCount);
30 bool MemoryDownloadBlock(void *Buffer, uint32_t BlockAddress, uint16_t ByteCount);
31 
32 /* EEPROM functions */
33 uint16_t WriteEEPBlock(uint16_t Address, const void *SrcPtr, uint16_t ByteCount);
34 uint16_t ReadEEPBlock(uint16_t Address, void *DestPtr, uint16_t ByteCount);
35 
36 #endif /* __ASSEMBLER__ */
37 
38 #endif /* MEMORY_H_ */
+
1 /*
2  * Flash.h
3  *
4  * Created on: 20.03.2013
5  * Author: skuser
6  */
7 
8 #ifndef MEMORY_H_
9 #define MEMORY_H_
10 
11 #define MEMORY_SIZE (FLASH_DATA_SIZE) /* From makefile */
12 #define MEMORY_INIT_VALUE 0x00
13 #define MEMORY_SIZE_PER_SETTING 8192
14 
15 #ifndef __ASSEMBLER__
16 #include "Common.h"
17 
18 void MemoryInit(void);
19 void MemoryReadBlock(void *Buffer, uint16_t Address, uint16_t ByteCount);
20 void MemoryReadBlockInSetting(void *Buffer, uint16_t Address, uint16_t ByteCount);
21 void MemoryWriteBlock(const void *Buffer, uint16_t Address, uint16_t ByteCount);
22 void MemoryWriteBlockInSetting(const void *Buffer, uint16_t Address, uint16_t ByteCount);
23 void MemoryClear(void);
24 
25 void MemoryRecall(void);
26 void MemoryStore(void);
27 
28 /* For use with XModem */
29 bool MemoryUploadBlock(void *Buffer, uint32_t BlockAddress, uint16_t ByteCount);
30 bool MemoryDownloadBlock(void *Buffer, uint32_t BlockAddress, uint16_t ByteCount);
31 
32 /* EEPROM functions */
33 uint16_t WriteEEPBlock(uint16_t Address, const void *SrcPtr, uint16_t ByteCount);
34 uint16_t ReadEEPBlock(uint16_t Address, void *DestPtr, uint16_t ByteCount);
35 
36 #endif /* __ASSEMBLER__ */
37 
38 #endif /* MEMORY_H_ */
diff --git a/Doc/Doxygen/html/_mifare_classic_8h_source.html b/Doc/Doxygen/html/_mifare_classic_8h_source.html index a65423dc..a5ed6633 100644 --- a/Doc/Doxygen/html/_mifare_classic_8h_source.html +++ b/Doc/Doxygen/html/_mifare_classic_8h_source.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: MifareClassic.h Source File @@ -11,9 +12,6 @@ - @@ -31,40 +29,19 @@ - + - - + + + +
1 /*
2  * MifareClassic.h
3  *
4  * Created on: 13.05.2013
5  * Author: skuser
6  */
7 
8 #ifndef MIFARECLASSIC_H_
9 #define MIFARECLASSIC_H_
10 
11 #include "Application.h"
12 #include "ISO14443-3A.h"
13 
14 #define MIFARE_CLASSIC_UID_SIZE ISO14443A_UID_SIZE_SINGLE
15 #define MIFARE_CLASSIC_MINI_MEM_SIZE 320
16 #define MIFARE_CLASSIC_1K_MEM_SIZE 1024
17 #define MIFARE_CLASSIC_4K_MEM_SIZE 4096
18 
19 void MifareClassicAppInitMini4B(void);
20 void MifareClassicAppInit1K(void);
21 void MifareClassicAppInit4K(void);
22 void MifareClassicAppInit1K7B(void);
23 void MifareClassicAppInit4K7B(void);
24 void MifareClassicAppReset(void);
25 void MifareClassicAppTask(void);
26 
27 uint16_t MifareClassicAppProcess(uint8_t *Buffer, uint16_t BitCount);
28 
29 void MifareClassicGetUid(ConfigurationUidType Uid);
30 void MifareClassicSetUid(ConfigurationUidType Uid);
31 
32 
33 #endif /* MIFARECLASSIC_H_ */
diff --git a/Doc/Doxygen/html/_mifare_d_e_s_fire_8h_source.html b/Doc/Doxygen/html/_mifare_d_e_s_fire_8h_source.html index cd2b6550..b70591e8 100644 --- a/Doc/Doxygen/html/_mifare_d_e_s_fire_8h_source.html +++ b/Doc/Doxygen/html/_mifare_d_e_s_fire_8h_source.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: MifareDESFire.h Source File @@ -11,9 +12,6 @@ - @@ -31,40 +29,19 @@ - + - - + + + +
MifareDESFire.h
-
1 /*
2 The DESFire stack portion of this firmware source
3 is free software written by Maxie Dion Schmidt (@maxieds):
4 You can redistribute it and/or modify
5 it under the terms of this license.
6 
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 
11 The complete source distribution of
12 this firmware is available at the following link:
13 https://github.com/maxieds/ChameleonMiniFirmwareDESFireStack.
14 
15 Based in part on the original DESFire code created by
16 @dev-zzo (GitHub handle) [Dmitry Janushkevich] available at
17 https://github.com/dev-zzo/ChameleonMini/tree/desfire.
18 
19 This notice must be retained at the top of all source files where indicated.
20 */
21 
22 /*
23  * MifareDesfire.h
24  * MIFARE DESFire frontend
25  *
26  * Created on: 14.10.2016
27  * Author: dev_zzo
28  */
29 
30 #ifndef MIFAREDESFIRE_H_
31 #define MIFAREDESFIRE_H_
32 
33 #include "Application.h"
34 #include "DESFire/DESFireFirmwareSettings.h"
35 #include "DESFire/DESFirePICCHeaderLayout.h"
36 #include "DESFire/DESFireISO14443Support.h"
37 #include "DESFire/DESFireISO7816Support.h"
38 #include "DESFire/DESFireInstructions.h"
39 
40 /* The core functions used outside of this implementation
41  * to describe the DESFire emulation to the Chameleon firmware:
42  */
43 void ResetLocalStructureData(void);
44 void MifareDesfireReset(void);
45 void MifareDesfireEV0AppInit(void);
46 void MifareDesfire2kEV1AppInit(void);
47 void MifareDesfire4kEV1AppInit(void);
48 void MifareDesfire8kEV1AppInit(void);
49 void MifareDesfireAppReset(void);
50 void MifareDesfireAppTick(void);
51 void MifareDesfireAppTask(void);
52 
53 uint16_t MifareDesfireProcessCommand(uint8_t *Buffer, uint16_t ByteCount);
54 uint16_t MifareDesfireProcess(uint8_t *Buffer, uint16_t ByteCount);
55 uint16_t MifareDesfireAppProcess(uint8_t* Buffer, uint16_t BitCount);
56 
57 void MifareDesfireGetUid(ConfigurationUidType Uid);
58 void MifareDesfireSetUid(ConfigurationUidType Uid);
59 
60 /* Helper function definitions since we need them
61  * elsewhere in the backend, and so we do not need to
62  * declare them as static in the source.
63  */
64 #define DesfireCLA(cmdCode) \
65  ((cmdCode == DESFIRE_NATIVE_CLA) || Iso7816CLA(cmdCode))
66 
67 typedef enum DESFIRE_FIRMWARE_ENUM_PACKING {
68  DESFIRE_HALT,
69  DESFIRE_IDLE,
70  DESFIRE_IDLE2,
71  DESFIRE_GET_VERSION2,
72  DESFIRE_GET_VERSION3,
73  DESFIRE_GET_APPLICATION_IDS2,
74  DESFIRE_LEGACY_AUTHENTICATE,
75  DESFIRE_LEGACY_AUTHENTICATE2,
76  DESFIRE_ISO_AUTHENTICATE,
77  DESFIRE_ISO_AUTHENTICATE2,
78  DESFIRE_AES_AUTHENTICATE,
79  DESFIRE_AES_AUTHENTICATE2,
80  DESFIRE_READ_DATA_FILE,
81  DESFIRE_WRITE_DATA_FILE,
82 } DesfireStateType;
83 
84 extern DesfireStateType DesfireState;
85 extern DesfireStateType DesfirePreviousState;
86 extern bool DesfireFromHalt;
87 extern BYTE DesfireCmdCLA;
88 
89 #endif /* MIFAREDESFIRE_H_ */
+
1 /*
2 The DESFire stack portion of this firmware source
3 is free software written by Maxie Dion Schmidt (@maxieds):
4 You can redistribute it and/or modify
5 it under the terms of this license.
6 
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 
11 The complete source distribution of
12 this firmware is available at the following link:
13 https://github.com/maxieds/ChameleonMiniFirmwareDESFireStack.
14 
15 Based in part on the original DESFire code created by
16 @dev-zzo (GitHub handle) [Dmitry Janushkevich] available at
17 https://github.com/dev-zzo/ChameleonMini/tree/desfire.
18 
19 This notice must be retained at the top of all source files where indicated.
20 */
21 
22 /*
23  * MifareDesfire.h
24  * MIFARE DESFire frontend
25  *
26  * Created on: 14.10.2016
27  * Author: dev_zzo
28  */
29 
30 #ifndef MIFAREDESFIRE_H_
31 #define MIFAREDESFIRE_H_
32 
33 #include "Application.h"
34 #include "DESFire/DESFireFirmwareSettings.h"
35 #include "DESFire/DESFirePICCHeaderLayout.h"
36 #include "DESFire/DESFireISO14443Support.h"
37 #include "DESFire/DESFireISO7816Support.h"
38 #include "DESFire/DESFireInstructions.h"
39 
40 /* The core functions used outside of this implementation
41  * to describe the DESFire emulation to the Chameleon firmware:
42  */
43 void ResetLocalStructureData(void);
44 void MifareDesfireReset(void);
45 void MifareDesfireEV0AppInit(void);
46 void MifareDesfire2kEV1AppInit(void);
47 void MifareDesfire4kEV1AppInit(void);
48 void MifareDesfire8kEV1AppInit(void);
49 void MifareDesfireAppReset(void);
50 void MifareDesfireAppTick(void);
51 void MifareDesfireAppTask(void);
52 
53 uint16_t MifareDesfireProcessCommand(uint8_t *Buffer, uint16_t ByteCount);
54 uint16_t MifareDesfireProcess(uint8_t *Buffer, uint16_t ByteCount);
55 uint16_t MifareDesfireAppProcess(uint8_t *Buffer, uint16_t BitCount);
56 
57 void MifareDesfireGetUid(ConfigurationUidType Uid);
58 void MifareDesfireSetUid(ConfigurationUidType Uid);
59 
60 /* Helper function definitions since we need them
61  * elsewhere in the backend, and so we do not need to
62  * declare them as static in the source.
63  */
64 #define DesfireCLA(cmdCode) \
65  ((cmdCode == DESFIRE_NATIVE_CLA) || Iso7816CLA(cmdCode))
66 
67 typedef enum DESFIRE_FIRMWARE_ENUM_PACKING {
68  DESFIRE_HALT,
69  DESFIRE_IDLE,
70  DESFIRE_IDLE2,
71  DESFIRE_GET_VERSION2,
72  DESFIRE_GET_VERSION3,
73  DESFIRE_GET_APPLICATION_IDS2,
74  DESFIRE_LEGACY_AUTHENTICATE,
75  DESFIRE_LEGACY_AUTHENTICATE2,
76  DESFIRE_ISO_AUTHENTICATE,
77  DESFIRE_ISO_AUTHENTICATE2,
78  DESFIRE_AES_AUTHENTICATE,
79  DESFIRE_AES_AUTHENTICATE2,
80  DESFIRE_READ_DATA_FILE,
81  DESFIRE_WRITE_DATA_FILE,
82 } DesfireStateType;
83 
84 extern DesfireStateType DesfireState;
85 extern DesfireStateType DesfirePreviousState;
86 extern bool DesfireFromHalt;
87 extern BYTE DesfireCmdCLA;
88 
89 #endif /* MIFAREDESFIRE_H_ */
diff --git a/Doc/Doxygen/html/_mifare_ultralight_8h_source.html b/Doc/Doxygen/html/_mifare_ultralight_8h_source.html index c7fe4e71..ff0ee8b9 100644 --- a/Doc/Doxygen/html/_mifare_ultralight_8h_source.html +++ b/Doc/Doxygen/html/_mifare_ultralight_8h_source.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: MifareUltralight.h Source File @@ -11,9 +12,6 @@ - @@ -31,40 +29,19 @@ - + - - + + + +
1 /*
2  * MifareUltralight.h
3  *
4  * Created on: 20.03.2013
5  * Author: skuser
6  */
7 
8 #ifndef MIFAREULTRALIGHT_H_
9 #define MIFAREULTRALIGHT_H_
10 
11 #include "Application.h"
12 #include "ISO14443-3A.h"
13 
14 #define MIFARE_ULTRALIGHTC_UID_SIZE ISO14443A_UID_SIZE_DOUBLE
15 #define MIFARE_ULTRALIGHTC_PAGE_SIZE 4
16 #define MIFARE_ULTRALIGHTC_PAGES 48
17 #define MIFARE_ULTRALIGHTC_MEM_SIZE (MIFARE_ULTRALIGHTC_PAGES * MIFARE_ULTRALIGHTC_PAGE_SIZE)
18 
19 #define MIFARE_ULTRALIGHT_UID_SIZE ISO14443A_UID_SIZE_DOUBLE
20 #define MIFARE_ULTRALIGHT_PAGE_SIZE 4
21 #define MIFARE_ULTRALIGHT_PAGES 16
22 #define MIFARE_ULTRALIGHT_EV11_PAGES 20
23 #define MIFARE_ULTRALIGHT_EV12_PAGES 41
24 #define MIFARE_ULTRALIGHT_MEM_SIZE (MIFARE_ULTRALIGHT_PAGES * MIFARE_ULTRALIGHT_PAGE_SIZE)
25 #define MIFARE_ULTRALIGHT_EV11_MEM_SIZE (MIFARE_ULTRALIGHT_EV11_PAGES * MIFARE_ULTRALIGHT_PAGE_SIZE)
26 #define MIFARE_ULTRALIGHT_EV12_MEM_SIZE (MIFARE_ULTRALIGHT_EV12_PAGES * MIFARE_ULTRALIGHT_PAGE_SIZE)
27 
28 void MifareUltralightAppInit(void);
29 void MifareUltralightEV11AppInit(void);
30 void MifareUltralightEV12AppInit(void);
31 void MifareUltralightAppReset(void);
32 void MifareUltralightAppTask(void);
33 
34 void MifareUltralightCAppInit(void);
35 void MifareUltralightCAppReset(void);
36 
37 uint16_t MifareUltralightAppProcess(uint8_t *Buffer, uint16_t BitCount);
38 
39 void MifareUltralightGetUid(ConfigurationUidType Uid);
40 void MifareUltralightSetUid(ConfigurationUidType Uid);
41 
42 
43 
44 #endif /* MIFAREULTRALIGHT_H_ */
diff --git a/Doc/Doxygen/html/_n_t_a_g215_8h_source.html b/Doc/Doxygen/html/_n_t_a_g215_8h_source.html index dac140a2..014fe05c 100644 --- a/Doc/Doxygen/html/_n_t_a_g215_8h_source.html +++ b/Doc/Doxygen/html/_n_t_a_g215_8h_source.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: NTAG215.h Source File @@ -11,9 +12,6 @@ - @@ -31,40 +29,19 @@ - + - - + + + +
1 /*
2  * NTAG215.h
3  *
4  * Created on: 20.02.2019
5  * Author: gcammisa
6  */
7 
8 #ifndef NTAG215_H_
9 #define NTAG215_H_
10 
11 #include "Application.h"
12 #include "ISO14443-3A.h"
13 
14 #define NTAG215_UID_SIZE ISO14443A_UID_SIZE_DOUBLE //7 bytes UID
15 #define NTAG215_PAGE_SIZE 4 //bytes per page
16 #define NTAG215_PAGES 135 //135 pages total, from 0 to 134
17 #define NTAG215_MEM_SIZE ( NTAG215_PAGE_SIZE * NTAG215_PAGES )
18 
19 void NTAG215AppInit(void);
20 void NTAG215AppReset(void);
21 void NTAG215AppTask(void);
22 
23 uint16_t NTAG215AppProcess(uint8_t *Buffer, uint16_t BitCount);
24 
25 void NTAG215GetUid(ConfigurationUidType Uid);
26 void NTAG215SetUid(ConfigurationUidType Uid);
27 #endif
diff --git a/Doc/Doxygen/html/_page_14443_a_reader.html b/Doc/Doxygen/html/_page_14443_a_reader.html index 53637d80..62cc331b 100644 --- a/Doc/Doxygen/html/_page_14443_a_reader.html +++ b/Doc/Doxygen/html/_page_14443_a_reader.html @@ -150,7 +150,7 @@

AUTOCALIBRATE

diff --git a/Doc/Doxygen/html/_page__buttons.html b/Doc/Doxygen/html/_page__buttons.html index d426e870..c35ad9b6 100644 --- a/Doc/Doxygen/html/_page__buttons.html +++ b/Doc/Doxygen/html/_page__buttons.html @@ -103,12 +103,14 @@

Supported Configurations

TOGGLE_FIELD Activates the reader field if it was deactivated, deactivates the reader field if it was activated. STORE_LOG Writes the current log from SRAM to FRAM and clears the SRAM log. Equivalent to the STORE_LOG command. + +CLONE_MFU Triggers the clone of a Mifare Ultralight card in range of the antenna to the selected slot and configures it to emulate it. Equivalent to the CLONE_MFU command.

Note the UID commands have no effect when the slot is configured as reader.

diff --git a/Doc/Doxygen/html/_page__command_line.html b/Doc/Doxygen/html/_page__command_line.html index f0560953..aa232145 100644 --- a/Doc/Doxygen/html/_page__command_line.html +++ b/Doc/Doxygen/html/_page__command_line.html @@ -233,6 +233,8 @@

Chameleon Command Set

DUMP_MFU Reads the whole content of a Mifare Ultralight card that is in the range of the antenna and returns it. This command is a Timeout command. +CLONE_MFU Clones a Mifare Ultralight card that is in the range of the antenna to the current slot, which is then accordingly configured to emulate it. This command is a Timeout command. + IDENTIFY Identifies the type of a card in the range of the antenna and returns it. This command is a Timeout command. THRESHOLD=? Returns the possible number range for the reader threshold. @@ -252,6 +254,8 @@

Timeout Commands

Warning
Any terminal input is completely ignored during the waiting period.
When setting the timeout to zero, there is no timeout and thus a process may continue forever. Such a process can only be terminated by changing the setting, if a button is configured accordingly, or by restarting the ChameleonMini (power off, power on).
+

Reader Example

+

To read cards, you must first choose a suitable threshold. An example workflow is listed below.

CONFIG=ISO14443A_READER
AUTOCALIBRATE
IDENTIFY

The THRESHOLD command can be used to show the threshold chosen by the Chameleon or one can set a threshold manually.

Note
A good alignment of the cards antenna and the antenna of the Chameleon improves the communication.

Accessing the command-line using a terminal software

In order to have quick access to the Chameleon's command-line without using any complicated software, we suggest using the TeraTerm terminal emulation software available for windows based operating systems.

Connecting and setting up

@@ -270,7 +274,7 @@

Uploading and Downloading dump files

diff --git a/Doc/Doxygen/html/_page__configurations.html b/Doc/Doxygen/html/_page__configurations.html index de77bb78..0aa89b97 100644 --- a/Doc/Doxygen/html/_page__configurations.html +++ b/Doc/Doxygen/html/_page__configurations.html @@ -104,7 +104,7 @@

Configuration Changing procedure diff --git a/Doc/Doxygen/html/_page__getting_started.html b/Doc/Doxygen/html/_page__getting_started.html index 1479b290..3ec5f7f0 100644 --- a/Doc/Doxygen/html/_page__getting_started.html +++ b/Doc/Doxygen/html/_page__getting_started.html @@ -74,7 +74,7 @@

Step 1: Trigger the USB Bootloader

In either way, the ChameleonMini now jumps to the bootloader and waits patiently for a firmware upgrade.

Step 2: Upgrade the Firmware

-

Once the ChameleonMini is in the bootloader, you can flash a new firmware, i.e., the files Chameleon-Mini.hex and the Chameleon-Mini.eep, into the microcontroller. The source code directory contains these files precompiled but you can of course also compile the code yourself. Create a new folder and copy the two files into it. The following depends on your operating system:

+

Once the ChameleonMini is in the bootloader, you can flash a new firmware, i.e., the files Chameleon-Mini.hex and the Chameleon-Mini.eep, into the microcontroller. The release page contains these files precompiled but you can of course also compile the code yourself. Create a new folder and copy the two files into it. The following depends on your operating system:

Upgrade Procedure for Linux Users

In order to upgrade the firmware under Linux you first have to install avrdude, e.g. under Ubuntu with the command sudo apt-get install avra avrdude. Then change to the directory where you have saved the hex and eep files and run sudo avrdude -c flip2 -p ATXMega128A4U -B 60 -P usb -U application:w:Chameleon-Mini.hex:i -U eeprom:w:Chameleon-Mini.eep:i.

You also can use sudo make program in the source code directory, which basically does the same.

@@ -96,7 +96,7 @@

Upgrade Procedure for Windows Users

diff --git a/Doc/Doxygen/html/_page__l_e_d.html b/Doc/Doxygen/html/_page__l_e_d.html index 1976aa11..b728b799 100644 --- a/Doc/Doxygen/html/_page__l_e_d.html +++ b/Doc/Doxygen/html/_page__l_e_d.html @@ -92,7 +92,7 @@ diff --git a/Doc/Doxygen/html/_page__l_e_ds.html b/Doc/Doxygen/html/_page__l_e_ds.html index 8313091a..489af78a 100644 --- a/Doc/Doxygen/html/_page__l_e_ds.html +++ b/Doc/Doxygen/html/_page__l_e_ds.html @@ -96,7 +96,7 @@ diff --git a/Doc/Doxygen/html/_page__log.html b/Doc/Doxygen/html/_page__log.html index 6d8ea574..cb012dcb 100644 --- a/Doc/Doxygen/html/_page__log.html +++ b/Doc/Doxygen/html/_page__log.html @@ -95,7 +95,7 @@

Related Commands, Button event and LED functions

diff --git a/Doc/Doxygen/html/_page__settings.html b/Doc/Doxygen/html/_page__settings.html index b8c8ccb1..693ab501 100644 --- a/Doc/Doxygen/html/_page__settings.html +++ b/Doc/Doxygen/html/_page__settings.html @@ -83,7 +83,7 @@

Slot Changing Procedure

diff --git a/Doc/Doxygen/html/_page__uploading_downloading.html b/Doc/Doxygen/html/_page__uploading_downloading.html index ed3122f0..de8306b9 100644 --- a/Doc/Doxygen/html/_page__uploading_downloading.html +++ b/Doc/Doxygen/html/_page__uploading_downloading.html @@ -74,7 +74,7 @@ diff --git a/Doc/Doxygen/html/_pin_8h_source.html b/Doc/Doxygen/html/_pin_8h_source.html index 504f7a3e..3b1b1571 100644 --- a/Doc/Doxygen/html/_pin_8h_source.html +++ b/Doc/Doxygen/html/_pin_8h_source.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: Pin.h Source File @@ -11,9 +12,6 @@ - @@ -31,40 +29,19 @@ - + - - + + + +
1 /*
2  * Pin.h
3  *
4  * Created on: 01.09.2020
5  * Author: endres
6  */
7 
8 #ifndef PIN_H
9 #define PIN_H
10 
11 #include <avr/io.h>
12 #include "Common.h"
13 
14 #define PIN_PORT PORTE
15 #define PIN_0 PIN0_bm
16 
17 typedef enum PinFunctionEnum {
18  PIN_NO_FUNC = 0, /* Pin is HI-Z */
19  PIN_ON, /* Pin is ON (3 V) */
20  PIN_OFF, /* Pin is OFF (0 V) */
21 
22  /* Have to be sequentially ordered */
23  PIN_1_TICK, /* Pin is ON for 1 Tick, afterwards OFF */
24  PIN_2_TICKS, /* Pin is ON for 2 Ticks, afterwards OFF */
25  PIN_3_TICKS, /* Pin is ON for 3 Ticks, afterwards OFF */
26  PIN_4_TICKS, /* Pin is ON for 4 Ticks, afterwards OFF */
27  PIN_5_TICKS, /* Pin is ON for 5 Ticks, afterwards OFF */
28 
29  /* Has to be last element */
30  PIN_FUNC_COUNT
31 } PinFunctionEnum;
32 
33 void PinInit(void);
34 void PinTick(void);
35 
36 void PinGetFuncList(char *List, uint16_t BufferSize);
37 void PinSetFuncById(PinFunctionEnum Func);
38 void PinGetFuncByName(char *Function, uint16_t BufferSize);
39 bool PinSetFuncByName(const char *Function);
40 
41 #endif /* PIN_H */
diff --git a/Doc/Doxygen/html/_random_8h_source.html b/Doc/Doxygen/html/_random_8h_source.html index 86852300..58544696 100644 --- a/Doc/Doxygen/html/_random_8h_source.html +++ b/Doc/Doxygen/html/_random_8h_source.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: Random.h Source File @@ -11,9 +12,6 @@ - @@ -31,40 +29,19 @@ - + - - + + + +
1 /*
2  * Random.h
3  *
4  * Created on: 22.03.2013
5  * Author: skuser
6  */
7 
8 #ifndef RANDOM_H_
9 #define RANDOM_H_
10 
11 #include "Common.h"
12 
13 void RandomInit(void);
14 uint8_t RandomGetByte(void);
15 void RandomGetBuffer(void *Buffer, uint8_t ByteCount);
16 void RandomTick(void);
17 
18 #endif /* RANDOM_H_ */
diff --git a/Doc/Doxygen/html/_reader14443-2_a_8h_source.html b/Doc/Doxygen/html/_reader14443-2_a_8h_source.html index ca4219a0..d2925db5 100644 --- a/Doc/Doxygen/html/_reader14443-2_a_8h_source.html +++ b/Doc/Doxygen/html/_reader14443-2_a_8h_source.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: Reader14443-2A.h Source File @@ -11,9 +12,6 @@ - @@ -31,40 +29,19 @@ - + - - + + + +
1 /*
2  * Reader14443-2A.h
3  *
4  * Created on: 26.08.2014
5  * Author: sk
6  */
7 
8 #ifndef READER14443_2A_H_
9 #define READER14443_2A_H_
10 
11 #include "Codec.h"
12 #include "Terminal/CommandLine.h"
13 
14 /* Codec Interface */
15 void Reader14443ACodecInit(void);
16 void Reader14443ACodecDeInit(void);
17 void Reader14443ACodecTask(void);
18 
19 /* Application Interface */
20 void Reader14443ACodecStart(void);
21 void Reader14443ACodecReset(void);
22 void Reader14443AMillerEOC(void);
23 
24 #endif /* READER14443_2A_H_ */
diff --git a/Doc/Doxygen/html/_reader14443_a_8h_source.html b/Doc/Doxygen/html/_reader14443_a_8h_source.html index 7876718e..10178c45 100644 --- a/Doc/Doxygen/html/_reader14443_a_8h_source.html +++ b/Doc/Doxygen/html/_reader14443_a_8h_source.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: Reader14443A.h Source File @@ -11,9 +12,6 @@ - @@ -31,40 +29,19 @@ - + - - + + + +
1 #ifndef READER14443A_H
2 #define READER14443A_H
3 
4 #include "Application.h"
5 #include "Codec/Codec.h"
6 
7 #define CRC_INIT 0x6363
8 
9 extern uint8_t ReaderSendBuffer[];
10 extern uint16_t ReaderSendBitCount;
11 
12 void Reader14443AAppInit(void);
13 void Reader14443AAppReset(void);
14 void Reader14443AAppTask(void);
15 void Reader14443AAppTick(void);
16 void Reader14443AAppTimeout(void);
17 
18 uint16_t Reader14443AAppProcess(uint8_t *Buffer, uint16_t BitCount);
19 
20 uint16_t addParityBits(uint8_t *Buffer, uint16_t bits);
21 uint16_t removeParityBits(uint8_t *Buffer, uint16_t BitCount);
22 bool checkParityBits(uint8_t *Buffer, uint16_t BitCount);
23 uint16_t ISO14443_CRCA(uint8_t *Buffer, uint8_t ByteCount);
24 
25 typedef enum {
26  Reader14443_Do_Nothing,
27  Reader14443_Send,
28  Reader14443_Send_Raw,
29  Reader14443_Get_UID,
30  Reader14443_Autocalibrate,
31  Reader14443_Read_MF_Ultralight,
32  Reader14443_Identify,
33  Reader14443_Identify_Clone,
34  Reader14443_Clone_MF_Ultralight
35 } Reader14443Command;
36 
37 
38 #endif //READER14443A_H
diff --git a/Doc/Doxygen/html/_reader_8txt.html b/Doc/Doxygen/html/_reader_8txt.html index 69bf37e2..29199e2e 100644 --- a/Doc/Doxygen/html/_reader_8txt.html +++ b/Doc/Doxygen/html/_reader_8txt.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: Reader.txt File Reference @@ -11,9 +12,6 @@ - @@ -31,40 +29,19 @@ - + - - + + + +
diff --git a/Doc/Doxygen/html/_settings_8h.html b/Doc/Doxygen/html/_settings_8h.html index 90dda927..1ab9d2d7 100644 --- a/Doc/Doxygen/html/_settings_8h.html +++ b/Doc/Doxygen/html/_settings_8h.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: Settings.h File Reference @@ -11,9 +12,6 @@ - @@ -31,40 +29,19 @@
- + - - + + + +
diff --git a/Doc/Doxygen/html/_settings_8h_source.html b/Doc/Doxygen/html/_settings_8h_source.html index 14993e99..94ccf3c2 100644 --- a/Doc/Doxygen/html/_settings_8h_source.html +++ b/Doc/Doxygen/html/_settings_8h_source.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: Settings.h Source File @@ -11,9 +12,6 @@ - @@ -31,40 +29,19 @@
- + - - + + + +
diff --git a/Doc/Doxygen/html/_settings_8txt.html b/Doc/Doxygen/html/_settings_8txt.html index cf00afa5..8c499e55 100644 --- a/Doc/Doxygen/html/_settings_8txt.html +++ b/Doc/Doxygen/html/_settings_8txt.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: Settings.txt File Reference @@ -11,9 +12,6 @@ - @@ -31,40 +29,19 @@ - + - - + + + +
diff --git a/Doc/Doxygen/html/_sl2s2002_8h_source.html b/Doc/Doxygen/html/_sl2s2002_8h_source.html index 9a747604..9dd1d439 100644 --- a/Doc/Doxygen/html/_sl2s2002_8h_source.html +++ b/Doc/Doxygen/html/_sl2s2002_8h_source.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: Sl2s2002.h Source File @@ -11,9 +12,6 @@ - @@ -31,40 +29,19 @@
- + - - + + + +
1 /*
2  * MifareClassic.h
3  *
4  * Created on: 01.03.2017
5  * Author: skuser
6  */
7 
8 #ifndef SL2S2002_H_
9 #define SL2S2002_H_
10 
11 #include "Application.h"
12 #include "ISO15693-A.h"
13 
14 void Sl2s2002AppInit(void);
15 void Sl2s2002AppReset(void);
16 void Sl2s2002AppTask(void);
17 void Sl2s2002AppTick(void);
18 uint16_t Sl2s2002AppProcess(uint8_t *FrameBuf, uint16_t FrameBytes);
19 void Sl2s2002GetUid(ConfigurationUidType Uid);
20 void Sl2s2002SetUid(ConfigurationUidType Uid);
21 
22 
23 
24 #endif /* VICINITY_H_ */
diff --git a/Doc/Doxygen/html/_sniff14443_a_8h_source.html b/Doc/Doxygen/html/_sniff14443_a_8h_source.html index 906826bb..50a44471 100644 --- a/Doc/Doxygen/html/_sniff14443_a_8h_source.html +++ b/Doc/Doxygen/html/_sniff14443_a_8h_source.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: Sniff14443A.h Source File @@ -11,9 +12,6 @@ - @@ -31,40 +29,19 @@ - + - - + + + +
1 //
2 // Created by Zitai Chen on 25/07/2018.
3 //
4 
5 #ifndef CHAMELEON_MINI_SNIFF14443A_H
6 #define CHAMELEON_MINI_SNIFF14443A_H
7 
8 #include <stdint.h>
9 
10 void Sniff14443AAppInit(void);
11 void Sniff14443AAppReset(void);
12 void Sniff14443AAppTask(void);
13 void Sniff14443AAppTick(void);
14 void Sniff14443AAppTimeout(void);
15 
16 uint16_t Sniff14443AAppProcess(uint8_t *Buffer, uint16_t BitCount);
17 
18 typedef enum {
19  Sniff14443_Do_Nothing,
20  Sniff14443_Autocalibrate,
21 } Sniff14443Command;
22 
23 #endif //CHAMELEON_MINI_SNIFF14443A_H
24 
diff --git a/Doc/Doxygen/html/_sniff15693_8h_source.html b/Doc/Doxygen/html/_sniff15693_8h_source.html new file mode 100644 index 00000000..4991504c --- /dev/null +++ b/Doc/Doxygen/html/_sniff15693_8h_source.html @@ -0,0 +1,77 @@ + + + + + + + +Chameleon-Mini: Sniff15693.h Source File + + + + + + + + + +
+
+ + + + + + +
+
Chameleon-Mini +
+
+
+ + + + + + + + +
+
+ + +
+ +
+ + +
+
+
+
Sniff15693.h
+
+
+
1 /*
2  * Sniff15693.h
3  *
4  * Created on: 05.11.2019
5  * Author: ceres-c
6  */
7 
8 #ifndef SNIFF_15693_H_
9 #define SNIFF_15693_H_
10 
11 #include "Application.h"
12 #include "ISO15693-A.h"
13 
14 void SniffISO15693AppInit(void);
15 void SniffISO15693AppReset(void);
16 void SniffISO15693AppTask(void);
17 void SniffISO15693AppTick(void);
18 uint16_t SniffISO15693AppProcess(uint8_t* FrameBuf, uint16_t FrameBytes);
19 void SniffISO15693AppTimeout(void);
20 
21 typedef enum {
22  Sniff15693_Do_Nothing,
23  Sniff15693_Autocalibrate,
24 } Sniff15693Command;
25 
26 extern Sniff15693Command Sniff15693CurrentCommand;
27 
28 #endif /* SNIFF_15693_H_ */
+ + + + diff --git a/Doc/Doxygen/html/_sniff_i_s_o14443-2_a_8h_source.html b/Doc/Doxygen/html/_sniff_i_s_o14443-2_a_8h_source.html index 16ddaa78..1c668fc6 100644 --- a/Doc/Doxygen/html/_sniff_i_s_o14443-2_a_8h_source.html +++ b/Doc/Doxygen/html/_sniff_i_s_o14443-2_a_8h_source.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: SniffISO14443-2A.h Source File @@ -11,9 +12,6 @@ - @@ -31,40 +29,19 @@ - + - - + + + +
SniffISO14443-2A.h
-
1 //
2 // Created by Zitai Chen on 05/07/2018.
3 //
4 
5 #ifndef CHAMELEON_MINI_SNIFFISO14443_2A_H
6 #define CHAMELEON_MINI_SNIFFISO14443_2A_H
7 
8 
9 #include "Codec.h"
10 #include "Terminal/CommandLine.h"
11 
12 extern enum RCTraffic {TRAFFIC_READER, TRAFFIC_CARD} TrafficSource;
13 /* Codec Interface */
14 void Sniff14443ACodecInit(void);
15 void Sniff14443ACodecDeInit(void);
16 void Sniff14443ACodecTask(void);
17 
18 
19 
20 #endif //CHAMELEON_MINI_SNIFFISO14443_2A_H
+
1 //
2 // Created by Zitai Chen on 05/07/2018.
3 //
4 
5 #ifndef CHAMELEON_MINI_SNIFFISO14443_2A_H
6 #define CHAMELEON_MINI_SNIFFISO14443_2A_H
7 
8 
9 #include "Codec.h"
10 #include "Terminal/CommandLine.h"
11 
12 /* Codec Interface */
13 void Sniff14443ACodecInit(void);
14 void Sniff14443ACodecDeInit(void);
15 void Sniff14443ACodecTask(void);
16 
17 
18 
19 #endif //CHAMELEON_MINI_SNIFFISO14443_2A_H
diff --git a/Doc/Doxygen/html/_sniff_i_s_o15693_8h_source.html b/Doc/Doxygen/html/_sniff_i_s_o15693_8h_source.html new file mode 100644 index 00000000..184a2c9a --- /dev/null +++ b/Doc/Doxygen/html/_sniff_i_s_o15693_8h_source.html @@ -0,0 +1,77 @@ + + + + + + + +Chameleon-Mini: SniffISO15693.h Source File + + + + + + + + + +
+
+ + + + + + +
+
Chameleon-Mini +
+
+
+ + + + + + + + +
+
+ + +
+ +
+ + +
+
+
+
SniffISO15693.h
+
+
+
1 /*
2  * SniffISO15693.h
3  *
4  * Created on: 05.11.2019
5  * Author: ceres-c
6  */
7 
8 #ifndef SNIFF_ISO15693_H_
9 #define SNIFF_ISO15693_H_
10 
11 #include "Terminal/CommandLine.h"
12 
13 #define ISO15693_APP_NO_RESPONSE 0x0000
14 
15 #define SUBCARRIER_1 32
16 #define SUBCARRIER_2 28
17 #define SUBCARRIER_OFF 0
18 #define SOF_PATTERN 0x1D
19 #define EOF_PATTERN 0xB8
20 
21 //Used when checking the request sent from the reader
22 #define ISO15693_REQ_SUBCARRIER_SINGLE 0x00
23 #define ISO15693_REQ_SUBCARRIER_DUAL 0x01
24 #define ISO15693_REQ_DATARATE_LOW 0x00
25 #define ISO15693_REQ_DATARATE_HIGH 0x02
26 
27 /* Codec Interface */
28 void SniffISO15693CodecInit(void);
29 void SniffISO15693CodecDeInit(void);
30 void SniffISO15693CodecTask(void);
31 
32 /* Application Interface */
33 void SniffISO15693CodecStart(void);
34 void SniffISO15693CodecReset(void);
35 /* Can be used by an application to disable */
36 /* The auto-threshold algorithm */
37 /* This is needed in corner cases - where the algo doesnt */
38 /* find a proper threshold */
39 /* In this case, the application can run an autocalibration session */
40 void SniffISO15693CtrlAutoThreshold(bool enable);
41 bool SniffISO15693GetAutoThreshold(void);
42 
43 /* Function is used to receive the measured FloorNoise */
44 /* This is used to narrow down the range, which is considered for */
45 /* Threshold */
46 uint16_t SniffISO15693GetFloorNoise(void);
47 
48 /* Internal functions */
49 INLINE void SNIFF_ISO15693_READER_EOC_VCD(void);
50 INLINE void CardSniffInit(void);
51 
52 
53 #endif /* SNIFF_ISO15693_H_ */
+ + + + diff --git a/Doc/Doxygen/html/_system_8h_source.html b/Doc/Doxygen/html/_system_8h_source.html index f13d9765..e0aefe08 100644 --- a/Doc/Doxygen/html/_system_8h_source.html +++ b/Doc/Doxygen/html/_system_8h_source.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: System.h Source File @@ -11,9 +12,6 @@ - @@ -31,40 +29,19 @@ - + - - + + + +
1 /*
2  * System.h
3  *
4  * Created on: 10.02.2013
5  * Author: skuser
6  */
7 
8 #ifndef SYSTEM_H
9 #define SYSTEM_H
10 
11 #include <avr/io.h>
12 #include <avr/pgmspace.h>
13 #include <avr/interrupt.h>
14 #include <stddef.h>
15 #include <stdbool.h>
16 #include "Common.h"
17 
18 #define F_RTC 1000
19 #define SYSTEM_MILLISECONDS_TO_RTC_CYCLES(x) \
20  ( (uint16_t) ( (double) F_RTC * x / 1E3 + 0.5) )
21 
22 #define SYSTEM_TICK_WIDTH 7 /* Bits */
23 #define SYSTEM_TICK_PERIOD (1<<7)
24 #define SYSTEM_TICK_MS (SYSTEM_TICK_PERIOD)
25 #define SYSTEM_TICK_FREQ (1000 / SYSTEM_TICK_PERIOD)
26 
27 #define SYSTEM_SMODE_PSAVE SLEEP_SMODE_PSAVE_gc
28 #define SYSTEM_SMODE_IDLE SLEEP_SMODE_IDLE_gc
29 
30 /* Use GPIORE and GPIORF as global tick register */
31 #define SYSTEM_TICK_REGISTER (*((volatile uint16_t*) &GPIORE))
32 
33 void SystemInit(void);
34 void SystemReset(void);
35 void SystemEnterBootloader(void);
36 void SystemStartUSBClock(void);
37 void SystemStopUSBClock(void);
38 void SystemInterruptInit(void);
39 INLINE bool SystemTick100ms(void);
40 
41 INLINE bool SystemTick100ms(void) {
42  if (RTC.INTFLAGS & RTC_COMPIF_bm) {
43  while (RTC.STATUS & RTC_SYNCBUSY_bm)
44  ;
45 
46  RTC.INTFLAGS = RTC_COMPIF_bm;
47  return true;
48  }
49 
50  return false;
51 }
52 
53 INLINE void SystemTickClearFlag(void) {
54  while (RTC.STATUS & RTC_SYNCBUSY_bm)
55  ;
56 
57  RTC.INTFLAGS = RTC_COMPIF_bm;
58 }
59 
60 INLINE uint16_t SystemGetSysTick(void) {
61  return SYSTEM_TICK_REGISTER | RTC.CNT;
62 }
63 
64 #endif /* SYSTEM_H */
diff --git a/Doc/Doxygen/html/_t_i_tagitplus_8h_source.html b/Doc/Doxygen/html/_t_i_tagitplus_8h_source.html new file mode 100644 index 00000000..fcc5e8bd --- /dev/null +++ b/Doc/Doxygen/html/_t_i_tagitplus_8h_source.html @@ -0,0 +1,77 @@ + + + + + + + +Chameleon-Mini: TITagitplus.h Source File + + + + + + + + + +
+
+ + + + + + +
+
Chameleon-Mini +
+
+
+ + + + + + + + +
+
+ + +
+ +
+ + +
+
+
+
TITagitplus.h
+
+
+
1 /*
2  * TITagitplus.h
3  *
4  * Created 20210409
5  * Author: leandre84
6  * Based on TI Tag-it Standard implementation
7  */
8 
9 #ifndef TITAGITPLUS_H_
10 #define TITAGITPLUS_H_
11 
12 #include "Application.h"
13 #include "ISO15693-A.h"
14 
15 #define TITAGIT_PLUS_UID_SIZE ISO15693_GENERIC_UID_SIZE //ISO15693_UID_SIZE
16 #define TITAGIT_PLUS_MEM_SIZE 0x110 //TAG-IT PLUS MAX MEM SIZE
17 #define TITAGIT_PLUS_BYTES_PER_PAGE 4
18 #define TITAGIT_PLUS_NUMBER_OF_SECTORS ( TITAGIT_PLUS_MEM_SIZE / TITAGIT_PLUS_BYTES_PER_PAGE )
19 #define TITAGIT_PLUS_NUMBER_OF_USER_SECTORS ( TITAGIT_PLUS_NUMBER_OF_SECTORS - 4 )
20 #define TITAGIT_PLUS_MEM_UID_ADDRESS 0x100 // UID byte address (two pages)
21 #define TITAGIT_PLUS_MEM_DSFID_ADDRESS 0x108 // DSFID byte address
22 #define TITAGIT_PLUS_MEM_AFI_ADDRESS 0x10C // AFI byte address
23 
24 void TITagitplusAppInit(void);
25 void TITagitplusAppReset(void);
26 void TITagitplusAppTask(void);
27 void TITagitplusAppTick(void);
28 uint16_t TITagitplusAppProcess(uint8_t *FrameBuf, uint16_t FrameBytes);
29 void TITagitplusGetUid(ConfigurationUidType Uid);
30 void TITagitplusSetUid(ConfigurationUidType Uid);
31 void TITagitplusFlipUid(ConfigurationUidType Uid);
32 
33 #endif /* TITAGITPLUS_H_ */
+ + + + diff --git a/Doc/Doxygen/html/_t_i_tagitstandard_8h_source.html b/Doc/Doxygen/html/_t_i_tagitstandard_8h_source.html index 5e60b9c2..4a69a368 100644 --- a/Doc/Doxygen/html/_t_i_tagitstandard_8h_source.html +++ b/Doc/Doxygen/html/_t_i_tagitstandard_8h_source.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: TITagitstandard.h Source File @@ -11,9 +12,6 @@ - @@ -31,40 +29,19 @@ - + - - + + + +
1 /*
2  * MifareClassic.h
3  *
4  * Created on: 01.03.2017
5  * Author: skuser
6  * modified by rickventura
7  */
8 
9 #ifndef TITAGITSTANDARD_H_
10 #define TITAGITSTANDARD_H_
11 
12 #include "Application.h"
13 
14 #define TITAGIT_STD_UID_SIZE ISO15693_GENERIC_UID_SIZE //ISO15693_UID_SIZE
15 #define TITAGIT_STD_MEM_SIZE 44 //TAG-IT STANDARD MAX MEM SIZE
16 #define TITAGIT_BYTES_PER_PAGE 4
17 #define TITAGIT_NUMBER_OF_SECTORS ( TITAGIT_STD_MEM_SIZE / TITAGIT_BYTES_PER_PAGE )
18 #define TITAGIT_MEM_UID_ADDRESS 0x20
19 #define TITAGIT_MEM_AFI_ADDRESS 0x28 // AFI byte address
20 
21 void TITagitstandardAppInit(void);
22 void TITagitstandardAppReset(void);
23 void TITagitstandardAppTask(void);
24 void TITagitstandardAppTick(void);
25 uint16_t TITagitstandardAppProcess(uint8_t *FrameBuf, uint16_t FrameBytes);
26 void TITagitstandardGetUid(ConfigurationUidType Uid);
27 void TITagitstandardSetUid(ConfigurationUidType Uid);
28 void TITagitstandardFlipUid(ConfigurationUidType Uid);
29 
30 #endif /* TITAGITSTANDARD_H_ */
diff --git a/Doc/Doxygen/html/_terminal_8h_source.html b/Doc/Doxygen/html/_terminal_8h_source.html index 0ad89e23..a4f45c47 100644 --- a/Doc/Doxygen/html/_terminal_8h_source.html +++ b/Doc/Doxygen/html/_terminal_8h_source.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: Terminal.h Source File @@ -11,9 +12,6 @@ - @@ -31,40 +29,19 @@ - + - - + + + +
1 /*
2  * CommandLine.h
3  *
4  * Created on: 10.02.2013
5  * Author: skuser
6  */
7 
8 #ifndef TERMINAL_H_
9 #define TERMINAL_H_
10 
11 #include "../Common.h"
12 #include "../LUFA/Drivers/USB/USB.h"
13 #include "XModem.h"
14 #include "CommandLine.h"
15 
16 #define TERMINAL_VBUS_PORT PORTD
17 #define TERMINAL_VBUS_MASK PIN5_bm
18 
19 #define TERMINAL_BUFFER_SIZE 512
20 
21 typedef enum {
22  TERMINAL_UNINITIALIZED,
23  TERMINAL_INITIALIZING,
24  TERMINAL_INITIALIZED,
25  TERMINAL_UNITIALIZING
26 } TerminalStateEnum;
27 
28 extern uint8_t TerminalBuffer[TERMINAL_BUFFER_SIZE];
29 extern uint16_t TerminalBufferIdx;
30 extern USB_ClassInfo_CDC_Device_t TerminalHandle;
31 extern TerminalStateEnum TerminalState;
32 
33 void TerminalInit(void);
34 void TerminalTask(void);
35 void TerminalTick(void);
36 
37 /*void TerminalSendHex(void* Buffer, uint16_t ByteCount);*/
38 INLINE void TerminalSendByte(uint8_t Byte);
39 INLINE void TerminalFlushBuffer(void);
40 void TerminalSendBlock(const void *Buffer, uint16_t ByteCount);
41 
42 INLINE void TerminalSendChar(char c);
43 void TerminalSendString(const char *s);
44 void TerminalSendStringP(const char *s);
45 
46 void EVENT_USB_Device_Connect(void);
47 void EVENT_USB_Device_Disconnect(void);
48 void EVENT_USB_Device_ConfigurationChanged(void);
49 void EVENT_USB_Device_ControlRequest(void);
50 
51 INLINE void TerminalSendChar(char c) { CDC_Device_SendByte(&TerminalHandle, c); }
52 INLINE void TerminalSendByte(uint8_t Byte) { CDC_Device_SendByte(&TerminalHandle, Byte); }
53 
54 INLINE void TerminalFlushBuffer(void) {
55  CDC_Device_Flush(&TerminalHandle);
56  TerminalBufferIdx = 0;
57  TerminalBuffer[TerminalBufferIdx] = '\0';
58 }
59 
60 #endif /* TERMINAL_H_ */
diff --git a/Doc/Doxygen/html/_uploading_downloading_8txt.html b/Doc/Doxygen/html/_uploading_downloading_8txt.html index 3b58392c..036bac7c 100644 --- a/Doc/Doxygen/html/_uploading_downloading_8txt.html +++ b/Doc/Doxygen/html/_uploading_downloading_8txt.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: UploadingDownloading.txt File Reference @@ -11,9 +12,6 @@ - @@ -31,40 +29,19 @@ - + - - + + + +
diff --git a/Doc/Doxygen/html/_vicinity_8h_source.html b/Doc/Doxygen/html/_vicinity_8h_source.html index f81d6f2c..fc81baf7 100644 --- a/Doc/Doxygen/html/_vicinity_8h_source.html +++ b/Doc/Doxygen/html/_vicinity_8h_source.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: Vicinity.h Source File @@ -11,9 +12,6 @@ - @@ -31,40 +29,19 @@
- + - - + + + +
1 /*
2  * MifareClassic.h
3  *
4  * Created on: 01.03.2017
5  * Author: skuser
6  */
7 
8 #ifndef VICINITY_H_
9 #define VICINITY_H_
10 
11 #include "Application.h"
12 #include "ISO15693-A.h"
13 
14 void VicinityAppInit(void);
15 void VicinityAppReset(void);
16 void VicinityAppTask(void);
17 void VicinityAppTick(void);
18 uint16_t VicinityAppProcess(uint8_t *FrameBuf, uint16_t FrameBytes);
19 void VicinityGetUid(ConfigurationUidType Uid);
20 void VicinitySetUid(ConfigurationUidType Uid);
21 
22 
23 
24 #endif /* VICINITY_H_ */
diff --git a/Doc/Doxygen/html/_x_modem_8h_source.html b/Doc/Doxygen/html/_x_modem_8h_source.html index 44ae7440..df7fd1c8 100644 --- a/Doc/Doxygen/html/_x_modem_8h_source.html +++ b/Doc/Doxygen/html/_x_modem_8h_source.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: XModem.h Source File @@ -11,9 +12,6 @@ - @@ -31,40 +29,19 @@ - + - - + + + +
1 /*
2  * TerminalXModem.h
3  *
4  * Created on: 22.03.2013
5  * Author: skuser
6  */
7 
8 #ifndef XMODEM_H_
9 #define XMODEM_H_
10 
11 #include "../Common.h"
12 
13 typedef bool (*XModemCallbackType)(void *ByteBuffer, uint32_t BlockAddress, uint16_t ByteCount);
14 
15 void XModemReceive(XModemCallbackType CallbackFunc);
16 void XModemSend(XModemCallbackType CallbackFunc);
17 
18 bool XModemProcessByte(uint8_t Byte);
19 void XModemTick(void);
20 
21 #endif /* TERMINALXMODEM_H_ */
diff --git a/Doc/Doxygen/html/annotated.html b/Doc/Doxygen/html/annotated.html index fc2c244e..8f535358 100644 --- a/Doc/Doxygen/html/annotated.html +++ b/Doc/Doxygen/html/annotated.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: Class List @@ -11,9 +12,6 @@ - @@ -31,41 +29,19 @@ - + - - + + + +
diff --git a/Doc/Doxygen/html/classes.html b/Doc/Doxygen/html/classes.html index 9a29c711..6a2e47bb 100644 --- a/Doc/Doxygen/html/classes.html +++ b/Doc/Doxygen/html/classes.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: Class Index @@ -11,9 +12,6 @@ - @@ -31,41 +29,19 @@
- + - - + + + +
Class Index
-
C | S | U
+
c | s | u
-
  C  
-
  S  
-
  U  
+
  c  
+
  s  
+
  u  
ConfigurationType   SettingsEntryType   USB_Descriptor_Configuration_t   
-
C | S | U
+
c | s | u
diff --git a/Doc/Doxygen/html/dir_5de29d499bb29a41092979d00d22c134.html b/Doc/Doxygen/html/dir_5de29d499bb29a41092979d00d22c134.html index 4ab81f83..2501d024 100644 --- a/Doc/Doxygen/html/dir_5de29d499bb29a41092979d00d22c134.html +++ b/Doc/Doxygen/html/dir_5de29d499bb29a41092979d00d22c134.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: Application Directory Reference @@ -11,9 +12,6 @@ - @@ -31,40 +29,19 @@ - + - - + + + +

Directories

- -

-Files

diff --git a/Doc/Doxygen/html/dir_74b6a3b63f61c160c0f14b7a283a4c9b.html b/Doc/Doxygen/html/dir_74b6a3b63f61c160c0f14b7a283a4c9b.html index 00eb2b6a..a664bd88 100644 --- a/Doc/Doxygen/html/dir_74b6a3b63f61c160c0f14b7a283a4c9b.html +++ b/Doc/Doxygen/html/dir_74b6a3b63f61c160c0f14b7a283a4c9b.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: Firmware Directory Reference @@ -11,9 +12,6 @@ - @@ -31,40 +29,19 @@ - + - - + + + +
diff --git a/Doc/Doxygen/html/dir_8465ec698d237f801ae9966d4551fcfa.html b/Doc/Doxygen/html/dir_8465ec698d237f801ae9966d4551fcfa.html index e6239d24..45d8a693 100644 --- a/Doc/Doxygen/html/dir_8465ec698d237f801ae9966d4551fcfa.html +++ b/Doc/Doxygen/html/dir_8465ec698d237f801ae9966d4551fcfa.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: Chameleon-Mini Directory Reference @@ -11,9 +12,6 @@ - @@ -31,40 +29,19 @@
- + - - + + + +
diff --git a/Doc/Doxygen/html/dir_ddeffaa734f77525428b0dd4068da9cb.html b/Doc/Doxygen/html/dir_ddeffaa734f77525428b0dd4068da9cb.html index 818fe7c1..cbd4332b 100644 --- a/Doc/Doxygen/html/dir_ddeffaa734f77525428b0dd4068da9cb.html +++ b/Doc/Doxygen/html/dir_ddeffaa734f77525428b0dd4068da9cb.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: Terminal Directory Reference @@ -11,9 +12,6 @@ - @@ -31,40 +29,19 @@
- + - - + + + +
Terminal Directory Reference
- - -

-Files

diff --git a/Doc/Doxygen/html/dir_ec47081b38449b83df6a52171dafd7a3.html b/Doc/Doxygen/html/dir_ec47081b38449b83df6a52171dafd7a3.html index 8ca235a4..05504d56 100644 --- a/Doc/Doxygen/html/dir_ec47081b38449b83df6a52171dafd7a3.html +++ b/Doc/Doxygen/html/dir_ec47081b38449b83df6a52171dafd7a3.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: Tests Directory Reference @@ -11,9 +12,6 @@ - @@ -31,40 +29,19 @@ - + - - + + + +
Tests Directory Reference
- - -

-Files

diff --git a/Doc/Doxygen/html/dir_f079829c5593b8ae9e7c3281d3851a5b.html b/Doc/Doxygen/html/dir_f079829c5593b8ae9e7c3281d3851a5b.html index a1452f55..ba2314fb 100644 --- a/Doc/Doxygen/html/dir_f079829c5593b8ae9e7c3281d3851a5b.html +++ b/Doc/Doxygen/html/dir_f079829c5593b8ae9e7c3281d3851a5b.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: DESFire Directory Reference @@ -11,9 +12,6 @@ - @@ -31,40 +29,19 @@ - + - - + + + +
DESFire Directory Reference
- - -

-Files

diff --git a/Doc/Doxygen/html/dir_f5aab302412c0352d69464400cc5ee44.html b/Doc/Doxygen/html/dir_f5aab302412c0352d69464400cc5ee44.html index 8268d8dd..ea3c9656 100644 --- a/Doc/Doxygen/html/dir_f5aab302412c0352d69464400cc5ee44.html +++ b/Doc/Doxygen/html/dir_f5aab302412c0352d69464400cc5ee44.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: Codec Directory Reference @@ -11,9 +12,6 @@ - @@ -31,40 +29,19 @@ - + - - + + + +
Codec Directory Reference
- - -

-Files

diff --git a/Doc/Doxygen/html/doxygen.css b/Doc/Doxygen/html/doxygen.css index 1425ec53..4f1ab919 100644 --- a/Doc/Doxygen/html/doxygen.css +++ b/Doc/Doxygen/html/doxygen.css @@ -1,9 +1,13 @@ -/* The standard CSS for doxygen 1.8.11 */ +/* The standard CSS for doxygen 1.8.13 */ body, table, div, p, dl { font: 400 14px/22px Roboto,sans-serif; } +p.reference, p.definition { + font: 400 14px/22px Roboto,sans-serif; +} + /* @group Heading Levels */ h1.groupheader { @@ -173,7 +177,7 @@ pre.fragment { } div.fragment { - padding: 4px 6px; + padding: 0px; margin: 4px 8px 4px 2px; background-color: #FBFCFD; border: 1px solid #C4CFE5; @@ -232,6 +236,15 @@ span.lineno a:hover { background-color: #C8C8C8; } +.lineno { + -webkit-touch-callout: none; + -webkit-user-select: none; + -khtml-user-select: none; + -moz-user-select: none; + -ms-user-select: none; + user-select: none; +} + div.ah, span.ah { background-color: black; font-weight: bold; @@ -501,6 +514,29 @@ table.memberdecls { /* Styles for detailed member documentation */ +.memtitle { + padding: 8px; + border-top: 1px solid #A8B8D9; + border-left: 1px solid #A8B8D9; + border-right: 1px solid #A8B8D9; + border-top-right-radius: 4px; + border-top-left-radius: 4px; + margin-bottom: -1px; + background-image: url('nav_f.png'); + background-repeat: repeat-x; + background-color: #E2E8F2; + line-height: 1.25; + font-weight: 300; + float:left; +} + +.permalink +{ + font-size: 65%; + display: inline-block; + vertical-align: middle; +} + .memtemplate { font-size: 80%; color: #4665A2; @@ -539,7 +575,7 @@ table.memberdecls { } .memname { - font-weight: bold; + font-weight: 400; margin-left: 6px; } @@ -555,24 +591,24 @@ table.memberdecls { color: #253555; font-weight: bold; text-shadow: 0px 1px 1px rgba(255, 255, 255, 0.9); - background-image:url('nav_f.png'); - background-repeat:repeat-x; - background-color: #E2E8F2; + background-color: #DFE5F1; /* opera specific markup */ box-shadow: 5px 5px 5px rgba(0, 0, 0, 0.15); border-top-right-radius: 4px; - border-top-left-radius: 4px; /* firefox specific markup */ -moz-box-shadow: rgba(0, 0, 0, 0.15) 5px 5px 5px; -moz-border-radius-topright: 4px; - -moz-border-radius-topleft: 4px; /* webkit specific markup */ -webkit-box-shadow: 5px 5px 5px rgba(0, 0, 0, 0.15); -webkit-border-top-right-radius: 4px; - -webkit-border-top-left-radius: 4px; } +.overload { + font-family: "courier new",courier,monospace; + font-size: 65%; +} + .memdoc, dl.reflist dd { border-bottom: 1px solid #A8B8D9; border-left: 1px solid #A8B8D9; @@ -914,6 +950,7 @@ table.fieldtable { padding-bottom: 4px; padding-top: 5px; text-align:left; + font-weight: 400; -moz-border-radius-topleft: 4px; -moz-border-radius-topright: 4px; -webkit-border-top-left-radius: 4px; @@ -1178,6 +1215,11 @@ dl.section dd { text-align: center; } +.plantumlgraph +{ + text-align: center; +} + .diagraph { text-align: center; @@ -1473,3 +1515,82 @@ tr.heading h2 { } } +/* @group Markdown */ + +/* +table.markdownTable { + border-collapse:collapse; + margin-top: 4px; + margin-bottom: 4px; +} + +table.markdownTable td, table.markdownTable th { + border: 1px solid #2D4068; + padding: 3px 7px 2px; +} + +table.markdownTableHead tr { +} + +table.markdownTableBodyLeft td, table.markdownTable th { + border: 1px solid #2D4068; + padding: 3px 7px 2px; +} + +th.markdownTableHeadLeft th.markdownTableHeadRight th.markdownTableHeadCenter th.markdownTableHeadNone { + background-color: #374F7F; + color: #FFFFFF; + font-size: 110%; + padding-bottom: 4px; + padding-top: 5px; +} + +th.markdownTableHeadLeft { + text-align: left +} + +th.markdownTableHeadRight { + text-align: right +} + +th.markdownTableHeadCenter { + text-align: center +} +*/ + +table.markdownTable { + border-collapse:collapse; + margin-top: 4px; + margin-bottom: 4px; +} + +table.markdownTable td, table.markdownTable th { + border: 1px solid #2D4068; + padding: 3px 7px 2px; +} + +table.markdownTable tr { +} + +th.markdownTableHeadLeft, th.markdownTableHeadRight, th.markdownTableHeadCenter, th.markdownTableHeadNone { + background-color: #374F7F; + color: #FFFFFF; + font-size: 110%; + padding-bottom: 4px; + padding-top: 5px; +} + +th.markdownTableHeadLeft, td.markdownTableBodyLeft { + text-align: left +} + +th.markdownTableHeadRight, td.markdownTableBodyRight { + text-align: right +} + +th.markdownTableHeadCenter, td.markdownTableBodyCenter { + text-align: center +} + + +/* @end */ diff --git a/Doc/Doxygen/html/files.html b/Doc/Doxygen/html/files.html index 6cc8726f..20d84d07 100644 --- a/Doc/Doxygen/html/files.html +++ b/Doc/Doxygen/html/files.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: File List @@ -11,9 +12,6 @@ - @@ -31,40 +29,19 @@ - + - - + + + +
 Settings.h  Sl2s2002.h  Sniff14443A.h - SniffISO14443-2A.h - System.h - Terminal.h - TITagitstandard.h - Vicinity.h - XModem.h + Sniff15693.h + SniffISO14443-2A.h + SniffISO15693.h + System.h + Terminal.h + TITagitplus.h + TITagitstandard.h + Vicinity.h + XModem.h
diff --git a/Doc/Doxygen/html/functions.html b/Doc/Doxygen/html/functions.html index 3050b0b2..f4526913 100644 --- a/Doc/Doxygen/html/functions.html +++ b/Doc/Doxygen/html/functions.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: Class Members @@ -11,9 +12,6 @@ - @@ -31,47 +29,19 @@ - + - - - + + + +
diff --git a/Doc/Doxygen/html/functions_vars.html b/Doc/Doxygen/html/functions_vars.html index 456b430b..2c8dd274 100644 --- a/Doc/Doxygen/html/functions_vars.html +++ b/Doc/Doxygen/html/functions_vars.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: Class Members - Variables @@ -11,9 +12,6 @@ - @@ -31,47 +29,19 @@
- + - - - + + + +
diff --git a/Doc/Doxygen/html/globals.html b/Doc/Doxygen/html/globals.html index 4a44800b..b1528f79 100644 --- a/Doc/Doxygen/html/globals.html +++ b/Doc/Doxygen/html/globals.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: File Members @@ -11,9 +12,6 @@ - @@ -31,60 +29,19 @@
- + - - - - + + + +
Here is a list of all documented file members with links to the documentation:
-

- c -

diff --git a/Doc/Doxygen/html/globals_defs.html b/Doc/Doxygen/html/globals_defs.html index afdf6d2c..1d43ebbf 100644 --- a/Doc/Doxygen/html/globals_defs.html +++ b/Doc/Doxygen/html/globals_defs.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: File Members @@ -11,9 +12,6 @@ - @@ -31,50 +29,19 @@ - + - - - + + + +
diff --git a/Doc/Doxygen/html/globals_enum.html b/Doc/Doxygen/html/globals_enum.html index 84c2cd9b..51dec0db 100644 --- a/Doc/Doxygen/html/globals_enum.html +++ b/Doc/Doxygen/html/globals_enum.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: File Members @@ -11,9 +12,6 @@ - @@ -31,50 +29,19 @@
- + - - - + + + +
diff --git a/Doc/Doxygen/html/globals_eval.html b/Doc/Doxygen/html/globals_eval.html index 47d4a934..4133479b 100644 --- a/Doc/Doxygen/html/globals_eval.html +++ b/Doc/Doxygen/html/globals_eval.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: File Members @@ -11,9 +12,6 @@ - @@ -31,50 +29,19 @@
- + - - - + + + +
diff --git a/Doc/Doxygen/html/globals_func.html b/Doc/Doxygen/html/globals_func.html index 53413da3..6e8ae42b 100644 --- a/Doc/Doxygen/html/globals_func.html +++ b/Doc/Doxygen/html/globals_func.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: File Members @@ -11,9 +12,6 @@ - @@ -31,50 +29,19 @@
- + - - - + + + +
diff --git a/Doc/Doxygen/html/globals_vars.html b/Doc/Doxygen/html/globals_vars.html index b46c696d..c06244e1 100644 --- a/Doc/Doxygen/html/globals_vars.html +++ b/Doc/Doxygen/html/globals_vars.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: File Members @@ -11,9 +12,6 @@ - @@ -31,50 +29,19 @@
- + - - - + + + +
diff --git a/Doc/Doxygen/html/index.html b/Doc/Doxygen/html/index.html index 75810ef9..e72e58dc 100644 --- a/Doc/Doxygen/html/index.html +++ b/Doc/Doxygen/html/index.html @@ -3,7 +3,8 @@ - + + Chameleon-Mini: Main Page @@ -11,9 +12,6 @@ - @@ -31,34 +29,19 @@
- + - + + + +
We appreciate all types of contributions (for example hardware mods, firmware upgrades, bug fixes, new supported card types, videos, pictures, example applications, reviews, instructions, documentation, translations, new findings, ANYTHING...) and are happy to upload the stuff for you into the github project. Please send your contribution to chame.nosp@m.leon.nosp@m.@kasp.nosp@m.er-o.nosp@m.swald.nosp@m..de and we will (if desired) give you credit in the github log of the upload. Likewise, we are looking forward to your feedback about bugs, problems, and desired future upgrades. Please use the issues button accordingly.

Pages:

diff --git a/Doc/Doxygen/html/jquery.js b/Doc/Doxygen/html/jquery.js index d52a1c77..f5343eda 100644 --- a/Doc/Doxygen/html/jquery.js +++ b/Doc/Doxygen/html/jquery.js @@ -1,4 +1,4 @@ -/* +/*! * jQuery JavaScript Library v1.7.1 * http://jquery.com/ * @@ -14,13 +14,13 @@ * Date: Mon Nov 21 21:11:03 2011 -0500 */ (function(bb,L){var av=bb.document,bu=bb.navigator,bl=bb.location;var b=(function(){var bF=function(b0,b1){return new bF.fn.init(b0,b1,bD)},bU=bb.jQuery,bH=bb.$,bD,bY=/^(?:[^#<]*(<[\w\W]+>)[^>]*$|#([\w\-]*)$)/,bM=/\S/,bI=/^\s+/,bE=/\s+$/,bA=/^<(\w+)\s*\/?>(?:<\/\1>)?$/,bN=/^[\],:{}\s]*$/,bW=/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,bP=/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,bJ=/(?:^|:|,)(?:\s*\[)+/g,by=/(webkit)[ \/]([\w.]+)/,bR=/(opera)(?:.*version)?[ \/]([\w.]+)/,bQ=/(msie) ([\w.]+)/,bS=/(mozilla)(?:.*? rv:([\w.]+))?/,bB=/-([a-z]|[0-9])/ig,bZ=/^-ms-/,bT=function(b0,b1){return(b1+"").toUpperCase()},bX=bu.userAgent,bV,bC,e,bL=Object.prototype.toString,bG=Object.prototype.hasOwnProperty,bz=Array.prototype.push,bK=Array.prototype.slice,bO=String.prototype.trim,bv=Array.prototype.indexOf,bx={};bF.fn=bF.prototype={constructor:bF,init:function(b0,b4,b3){var b2,b5,b1,b6;if(!b0){return this}if(b0.nodeType){this.context=this[0]=b0;this.length=1;return this}if(b0==="body"&&!b4&&av.body){this.context=av;this[0]=av.body;this.selector=b0;this.length=1;return this}if(typeof b0==="string"){if(b0.charAt(0)==="<"&&b0.charAt(b0.length-1)===">"&&b0.length>=3){b2=[null,b0,null]}else{b2=bY.exec(b0)}if(b2&&(b2[1]||!b4)){if(b2[1]){b4=b4 instanceof bF?b4[0]:b4;b6=(b4?b4.ownerDocument||b4:av);b1=bA.exec(b0);if(b1){if(bF.isPlainObject(b4)){b0=[av.createElement(b1[1])];bF.fn.attr.call(b0,b4,true)}else{b0=[b6.createElement(b1[1])]}}else{b1=bF.buildFragment([b2[1]],[b6]);b0=(b1.cacheable?bF.clone(b1.fragment):b1.fragment).childNodes}return bF.merge(this,b0)}else{b5=av.getElementById(b2[2]);if(b5&&b5.parentNode){if(b5.id!==b2[2]){return b3.find(b0)}this.length=1;this[0]=b5}this.context=av;this.selector=b0;return this}}else{if(!b4||b4.jquery){return(b4||b3).find(b0)}else{return this.constructor(b4).find(b0)}}}else{if(bF.isFunction(b0)){return b3.ready(b0)}}if(b0.selector!==L){this.selector=b0.selector;this.context=b0.context}return bF.makeArray(b0,this)},selector:"",jquery:"1.7.1",length:0,size:function(){return this.length},toArray:function(){return bK.call(this,0)},get:function(b0){return b0==null?this.toArray():(b0<0?this[this.length+b0]:this[b0])},pushStack:function(b1,b3,b0){var b2=this.constructor();if(bF.isArray(b1)){bz.apply(b2,b1)}else{bF.merge(b2,b1)}b2.prevObject=this;b2.context=this.context;if(b3==="find"){b2.selector=this.selector+(this.selector?" ":"")+b0}else{if(b3){b2.selector=this.selector+"."+b3+"("+b0+")"}}return b2},each:function(b1,b0){return bF.each(this,b1,b0)},ready:function(b0){bF.bindReady();bC.add(b0);return this},eq:function(b0){b0=+b0;return b0===-1?this.slice(b0):this.slice(b0,b0+1)},first:function(){return this.eq(0)},last:function(){return this.eq(-1)},slice:function(){return this.pushStack(bK.apply(this,arguments),"slice",bK.call(arguments).join(","))},map:function(b0){return this.pushStack(bF.map(this,function(b2,b1){return b0.call(b2,b1,b2)}))},end:function(){return this.prevObject||this.constructor(null)},push:bz,sort:[].sort,splice:[].splice};bF.fn.init.prototype=bF.fn;bF.extend=bF.fn.extend=function(){var b9,b2,b0,b1,b6,b7,b5=arguments[0]||{},b4=1,b3=arguments.length,b8=false;if(typeof b5==="boolean"){b8=b5;b5=arguments[1]||{};b4=2}if(typeof b5!=="object"&&!bF.isFunction(b5)){b5={}}if(b3===b4){b5=this;--b4}for(;b40){return}bC.fireWith(av,[bF]);if(bF.fn.trigger){bF(av).trigger("ready").off("ready")}}},bindReady:function(){if(bC){return}bC=bF.Callbacks("once memory");if(av.readyState==="complete"){return setTimeout(bF.ready,1)}if(av.addEventListener){av.addEventListener("DOMContentLoaded",e,false);bb.addEventListener("load",bF.ready,false)}else{if(av.attachEvent){av.attachEvent("onreadystatechange",e);bb.attachEvent("onload",bF.ready);var b0=false;try{b0=bb.frameElement==null}catch(b1){}if(av.documentElement.doScroll&&b0){bw()}}}},isFunction:function(b0){return bF.type(b0)==="function"},isArray:Array.isArray||function(b0){return bF.type(b0)==="array"},isWindow:function(b0){return b0&&typeof b0==="object"&&"setInterval" in b0},isNumeric:function(b0){return !isNaN(parseFloat(b0))&&isFinite(b0)},type:function(b0){return b0==null?String(b0):bx[bL.call(b0)]||"object"},isPlainObject:function(b2){if(!b2||bF.type(b2)!=="object"||b2.nodeType||bF.isWindow(b2)){return false}try{if(b2.constructor&&!bG.call(b2,"constructor")&&!bG.call(b2.constructor.prototype,"isPrototypeOf")){return false}}catch(b1){return false}var b0;for(b0 in b2){}return b0===L||bG.call(b2,b0)},isEmptyObject:function(b1){for(var b0 in b1){return false}return true},error:function(b0){throw new Error(b0)},parseJSON:function(b0){if(typeof b0!=="string"||!b0){return null}b0=bF.trim(b0);if(bb.JSON&&bb.JSON.parse){return bb.JSON.parse(b0)}if(bN.test(b0.replace(bW,"@").replace(bP,"]").replace(bJ,""))){return(new Function("return "+b0))()}bF.error("Invalid JSON: "+b0)},parseXML:function(b2){var b0,b1;try{if(bb.DOMParser){b1=new DOMParser();b0=b1.parseFromString(b2,"text/xml")}else{b0=new ActiveXObject("Microsoft.XMLDOM");b0.async="false";b0.loadXML(b2)}}catch(b3){b0=L}if(!b0||!b0.documentElement||b0.getElementsByTagName("parsererror").length){bF.error("Invalid XML: "+b2)}return b0},noop:function(){},globalEval:function(b0){if(b0&&bM.test(b0)){(bb.execScript||function(b1){bb["eval"].call(bb,b1)})(b0)}},camelCase:function(b0){return b0.replace(bZ,"ms-").replace(bB,bT)},nodeName:function(b1,b0){return b1.nodeName&&b1.nodeName.toUpperCase()===b0.toUpperCase()},each:function(b3,b6,b2){var b1,b4=0,b5=b3.length,b0=b5===L||bF.isFunction(b3);if(b2){if(b0){for(b1 in b3){if(b6.apply(b3[b1],b2)===false){break}}}else{for(;b40&&b0[0]&&b0[b1-1])||b1===0||bF.isArray(b0));if(b3){for(;b21?aJ.call(arguments,0):bG;if(!(--bw)){bC.resolveWith(bC,bx)}}}function bz(bF){return function(bG){bB[bF]=arguments.length>1?aJ.call(arguments,0):bG;bC.notifyWith(bE,bB)}}if(e>1){for(;bv
a";bI=bv.getElementsByTagName("*");bF=bv.getElementsByTagName("a")[0];if(!bI||!bI.length||!bF){return{}}bG=av.createElement("select");bx=bG.appendChild(av.createElement("option"));bE=bv.getElementsByTagName("input")[0];bJ={leadingWhitespace:(bv.firstChild.nodeType===3),tbody:!bv.getElementsByTagName("tbody").length,htmlSerialize:!!bv.getElementsByTagName("link").length,style:/top/.test(bF.getAttribute("style")),hrefNormalized:(bF.getAttribute("href")==="/a"),opacity:/^0.55/.test(bF.style.opacity),cssFloat:!!bF.style.cssFloat,checkOn:(bE.value==="on"),optSelected:bx.selected,getSetAttribute:bv.className!=="t",enctype:!!av.createElement("form").enctype,html5Clone:av.createElement("nav").cloneNode(true).outerHTML!=="<:nav>",submitBubbles:true,changeBubbles:true,focusinBubbles:false,deleteExpando:true,noCloneEvent:true,inlineBlockNeedsLayout:false,shrinkWrapBlocks:false,reliableMarginRight:true};bE.checked=true;bJ.noCloneChecked=bE.cloneNode(true).checked;bG.disabled=true;bJ.optDisabled=!bx.disabled;try{delete bv.test}catch(bC){bJ.deleteExpando=false}if(!bv.addEventListener&&bv.attachEvent&&bv.fireEvent){bv.attachEvent("onclick",function(){bJ.noCloneEvent=false});bv.cloneNode(true).fireEvent("onclick")}bE=av.createElement("input");bE.value="t";bE.setAttribute("type","radio");bJ.radioValue=bE.value==="t";bE.setAttribute("checked","checked");bv.appendChild(bE);bD=av.createDocumentFragment();bD.appendChild(bv.lastChild);bJ.checkClone=bD.cloneNode(true).cloneNode(true).lastChild.checked;bJ.appendChecked=bE.checked;bD.removeChild(bE);bD.appendChild(bv);bv.innerHTML="";if(bb.getComputedStyle){bA=av.createElement("div");bA.style.width="0";bA.style.marginRight="0";bv.style.width="2px";bv.appendChild(bA);bJ.reliableMarginRight=(parseInt((bb.getComputedStyle(bA,null)||{marginRight:0}).marginRight,10)||0)===0}if(bv.attachEvent){for(by in {submit:1,change:1,focusin:1}){bB="on"+by;bw=(bB in bv);if(!bw){bv.setAttribute(bB,"return;");bw=(typeof bv[bB]==="function")}bJ[by+"Bubbles"]=bw}}bD.removeChild(bv);bD=bG=bx=bA=bv=bE=null;b(function(){var bM,bU,bV,bT,bN,bO,bL,bS,bR,e,bP,bQ=av.getElementsByTagName("body")[0];if(!bQ){return}bL=1;bS="position:absolute;top:0;left:0;width:1px;height:1px;margin:0;";bR="visibility:hidden;border:0;";e="style='"+bS+"border:5px solid #000;padding:0;'";bP="
";bM=av.createElement("div");bM.style.cssText=bR+"width:0;height:0;position:static;top:0;margin-top:"+bL+"px";bQ.insertBefore(bM,bQ.firstChild);bv=av.createElement("div");bM.appendChild(bv);bv.innerHTML="
t
";bz=bv.getElementsByTagName("td");bw=(bz[0].offsetHeight===0);bz[0].style.display="";bz[1].style.display="none";bJ.reliableHiddenOffsets=bw&&(bz[0].offsetHeight===0);bv.innerHTML="";bv.style.width=bv.style.paddingLeft="1px";b.boxModel=bJ.boxModel=bv.offsetWidth===2;if(typeof bv.style.zoom!=="undefined"){bv.style.display="inline";bv.style.zoom=1;bJ.inlineBlockNeedsLayout=(bv.offsetWidth===2);bv.style.display="";bv.innerHTML="
";bJ.shrinkWrapBlocks=(bv.offsetWidth!==2)}bv.style.cssText=bS+bR;bv.innerHTML=bP;bU=bv.firstChild;bV=bU.firstChild;bN=bU.nextSibling.firstChild.firstChild;bO={doesNotAddBorder:(bV.offsetTop!==5),doesAddBorderForTableAndCells:(bN.offsetTop===5)};bV.style.position="fixed";bV.style.top="20px";bO.fixedPosition=(bV.offsetTop===20||bV.offsetTop===15);bV.style.position=bV.style.top="";bU.style.overflow="hidden";bU.style.position="relative";bO.subtractsBorderForOverflowNotVisible=(bV.offsetTop===-5);bO.doesNotIncludeMarginInBodyOffset=(bQ.offsetTop!==bL);bQ.removeChild(bM);bv=bM=null;b.extend(bJ,bO)});return bJ})();var aS=/^(?:\{.*\}|\[.*\])$/,aA=/([A-Z])/g;b.extend({cache:{},uuid:0,expando:"jQuery"+(b.fn.jquery+Math.random()).replace(/\D/g,""),noData:{embed:true,object:"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000",applet:true},hasData:function(e){e=e.nodeType?b.cache[e[b.expando]]:e[b.expando];return !!e&&!S(e)},data:function(bx,bv,bz,by){if(!b.acceptData(bx)){return}var bG,bA,bD,bE=b.expando,bC=typeof bv==="string",bF=bx.nodeType,e=bF?b.cache:bx,bw=bF?bx[bE]:bx[bE]&&bE,bB=bv==="events";if((!bw||!e[bw]||(!bB&&!by&&!e[bw].data))&&bC&&bz===L){return}if(!bw){if(bF){bx[bE]=bw=++b.uuid}else{bw=bE}}if(!e[bw]){e[bw]={};if(!bF){e[bw].toJSON=b.noop}}if(typeof bv==="object"||typeof bv==="function"){if(by){e[bw]=b.extend(e[bw],bv)}else{e[bw].data=b.extend(e[bw].data,bv)}}bG=bA=e[bw];if(!by){if(!bA.data){bA.data={}}bA=bA.data}if(bz!==L){bA[b.camelCase(bv)]=bz}if(bB&&!bA[bv]){return bG.events}if(bC){bD=bA[bv];if(bD==null){bD=bA[b.camelCase(bv)]}}else{bD=bA}return bD},removeData:function(bx,bv,by){if(!b.acceptData(bx)){return}var bB,bA,bz,bC=b.expando,bD=bx.nodeType,e=bD?b.cache:bx,bw=bD?bx[bC]:bC;if(!e[bw]){return}if(bv){bB=by?e[bw]:e[bw].data;if(bB){if(!b.isArray(bv)){if(bv in bB){bv=[bv]}else{bv=b.camelCase(bv);if(bv in bB){bv=[bv]}else{bv=bv.split(" ")}}}for(bA=0,bz=bv.length;bA-1){return true}}return false},val:function(bx){var e,bv,by,bw=this[0];if(!arguments.length){if(bw){e=b.valHooks[bw.nodeName.toLowerCase()]||b.valHooks[bw.type];if(e&&"get" in e&&(bv=e.get(bw,"value"))!==L){return bv}bv=bw.value;return typeof bv==="string"?bv.replace(aU,""):bv==null?"":bv}return}by=b.isFunction(bx);return this.each(function(bA){var bz=b(this),bB;if(this.nodeType!==1){return}if(by){bB=bx.call(this,bA,bz.val())}else{bB=bx}if(bB==null){bB=""}else{if(typeof bB==="number"){bB+=""}else{if(b.isArray(bB)){bB=b.map(bB,function(bC){return bC==null?"":bC+""})}}}e=b.valHooks[this.nodeName.toLowerCase()]||b.valHooks[this.type];if(!e||!("set" in e)||e.set(this,bB,"value")===L){this.value=bB}})}});b.extend({valHooks:{option:{get:function(e){var bv=e.attributes.value;return !bv||bv.specified?e.value:e.text}},select:{get:function(e){var bA,bv,bz,bx,by=e.selectedIndex,bB=[],bC=e.options,bw=e.type==="select-one";if(by<0){return null}bv=bw?by:0;bz=bw?by+1:bC.length;for(;bv=0});if(!e.length){bv.selectedIndex=-1}return e}}},attrFn:{val:true,css:true,html:true,text:true,data:true,width:true,height:true,offset:true},attr:function(bA,bx,bB,bz){var bw,e,by,bv=bA.nodeType;if(!bA||bv===3||bv===8||bv===2){return}if(bz&&bx in b.attrFn){return b(bA)[bx](bB)}if(typeof bA.getAttribute==="undefined"){return b.prop(bA,bx,bB)}by=bv!==1||!b.isXMLDoc(bA);if(by){bx=bx.toLowerCase();e=b.attrHooks[bx]||(ao.test(bx)?aY:be)}if(bB!==L){if(bB===null){b.removeAttr(bA,bx);return}else{if(e&&"set" in e&&by&&(bw=e.set(bA,bB,bx))!==L){return bw}else{bA.setAttribute(bx,""+bB);return bB}}}else{if(e&&"get" in e&&by&&(bw=e.get(bA,bx))!==null){return bw}else{bw=bA.getAttribute(bx);return bw===null?L:bw}}},removeAttr:function(bx,bz){var by,bA,bv,e,bw=0;if(bz&&bx.nodeType===1){bA=bz.toLowerCase().split(af);e=bA.length;for(;bw=0)}}})});var bd=/^(?:textarea|input|select)$/i,n=/^([^\.]*)?(?:\.(.+))?$/,J=/\bhover(\.\S+)?\b/,aO=/^key/,bf=/^(?:mouse|contextmenu)|click/,T=/^(?:focusinfocus|focusoutblur)$/,U=/^(\w*)(?:#([\w\-]+))?(?:\.([\w\-]+))?$/,Y=function(e){var bv=U.exec(e);if(bv){bv[1]=(bv[1]||"").toLowerCase();bv[3]=bv[3]&&new RegExp("(?:^|\\s)"+bv[3]+"(?:\\s|$)")}return bv},j=function(bw,e){var bv=bw.attributes||{};return((!e[1]||bw.nodeName.toLowerCase()===e[1])&&(!e[2]||(bv.id||{}).value===e[2])&&(!e[3]||e[3].test((bv["class"]||{}).value)))},bt=function(e){return b.event.special.hover?e:e.replace(J,"mouseenter$1 mouseleave$1")};b.event={add:function(bx,bC,bJ,bA,by){var bD,bB,bK,bI,bH,bF,e,bG,bv,bz,bw,bE;if(bx.nodeType===3||bx.nodeType===8||!bC||!bJ||!(bD=b._data(bx))){return}if(bJ.handler){bv=bJ;bJ=bv.handler}if(!bJ.guid){bJ.guid=b.guid++}bK=bD.events;if(!bK){bD.events=bK={}}bB=bD.handle;if(!bB){bD.handle=bB=function(bL){return typeof b!=="undefined"&&(!bL||b.event.triggered!==bL.type)?b.event.dispatch.apply(bB.elem,arguments):L};bB.elem=bx}bC=b.trim(bt(bC)).split(" ");for(bI=0;bI=0){bG=bG.slice(0,-1);bw=true}if(bG.indexOf(".")>=0){bx=bG.split(".");bG=bx.shift();bx.sort()}if((!bA||b.event.customEvent[bG])&&!b.event.global[bG]){return}bv=typeof bv==="object"?bv[b.expando]?bv:new b.Event(bG,bv):new b.Event(bG);bv.type=bG;bv.isTrigger=true;bv.exclusive=bw;bv.namespace=bx.join(".");bv.namespace_re=bv.namespace?new RegExp("(^|\\.)"+bx.join("\\.(?:.*\\.)?")+"(\\.|$)"):null;by=bG.indexOf(":")<0?"on"+bG:"";if(!bA){e=b.cache;for(bC in e){if(e[bC].events&&e[bC].events[bG]){b.event.trigger(bv,bD,e[bC].handle.elem,true)}}return}bv.result=L;if(!bv.target){bv.target=bA}bD=bD!=null?b.makeArray(bD):[];bD.unshift(bv);bF=b.event.special[bG]||{};if(bF.trigger&&bF.trigger.apply(bA,bD)===false){return}bB=[[bA,bF.bindType||bG]];if(!bJ&&!bF.noBubble&&!b.isWindow(bA)){bI=bF.delegateType||bG;bH=T.test(bI+bG)?bA:bA.parentNode;bz=null;for(;bH;bH=bH.parentNode){bB.push([bH,bI]);bz=bH}if(bz&&bz===bA.ownerDocument){bB.push([bz.defaultView||bz.parentWindow||bb,bI])}}for(bC=0;bCbA){bH.push({elem:this,matches:bz.slice(bA)})}for(bC=0;bC0?this.on(e,null,bx,bw):this.trigger(e)};if(b.attrFn){b.attrFn[e]=true}if(aO.test(e)){b.event.fixHooks[e]=b.event.keyHooks}if(bf.test(e)){b.event.fixHooks[e]=b.event.mouseHooks}}); -/* +/*! * Sizzle CSS Selector Engine * Copyright 2011, The Dojo Foundation * Released under the MIT, BSD, and GPL Licenses. * More information: http://sizzlejs.com/ */ -(function(){var bH=/((?:\((?:\([^()]+\)|[^()]+)+\)|\[(?:\[[^\[\]]*\]|['"][^'"]*['"]|[^\[\]'"]+)+\]|\\.|[^ >+~,(\[\\]+)+|[>+~])(\s*,\s*)?((?:.|\r|\n)*)/g,bC="sizcache"+(Math.random()+"").replace(".",""),bI=0,bL=Object.prototype.toString,bB=false,bA=true,bK=/\\/g,bO=/\r\n/g,bQ=/\W/;[0,0].sort(function(){bA=false;return 0});var by=function(bV,e,bY,bZ){bY=bY||[];e=e||av;var b1=e;if(e.nodeType!==1&&e.nodeType!==9){return[]}if(!bV||typeof bV!=="string"){return bY}var bS,b3,b6,bR,b2,b5,b4,bX,bU=true,bT=by.isXML(e),bW=[],b0=bV;do{bH.exec("");bS=bH.exec(b0);if(bS){b0=bS[3];bW.push(bS[1]);if(bS[2]){bR=bS[3];break}}}while(bS);if(bW.length>1&&bD.exec(bV)){if(bW.length===2&&bE.relative[bW[0]]){b3=bM(bW[0]+bW[1],e,bZ)}else{b3=bE.relative[bW[0]]?[e]:by(bW.shift(),e);while(bW.length){bV=bW.shift();if(bE.relative[bV]){bV+=bW.shift()}b3=bM(bV,b3,bZ)}}}else{if(!bZ&&bW.length>1&&e.nodeType===9&&!bT&&bE.match.ID.test(bW[0])&&!bE.match.ID.test(bW[bW.length-1])){b2=by.find(bW.shift(),e,bT);e=b2.expr?by.filter(b2.expr,b2.set)[0]:b2.set[0]}if(e){b2=bZ?{expr:bW.pop(),set:bF(bZ)}:by.find(bW.pop(),bW.length===1&&(bW[0]==="~"||bW[0]==="+")&&e.parentNode?e.parentNode:e,bT);b3=b2.expr?by.filter(b2.expr,b2.set):b2.set;if(bW.length>0){b6=bF(b3)}else{bU=false}while(bW.length){b5=bW.pop();b4=b5;if(!bE.relative[b5]){b5=""}else{b4=bW.pop()}if(b4==null){b4=e}bE.relative[b5](b6,b4,bT)}}else{b6=bW=[]}}if(!b6){b6=b3}if(!b6){by.error(b5||bV)}if(bL.call(b6)==="[object Array]"){if(!bU){bY.push.apply(bY,b6)}else{if(e&&e.nodeType===1){for(bX=0;b6[bX]!=null;bX++){if(b6[bX]&&(b6[bX]===true||b6[bX].nodeType===1&&by.contains(e,b6[bX]))){bY.push(b3[bX])}}}else{for(bX=0;b6[bX]!=null;bX++){if(b6[bX]&&b6[bX].nodeType===1){bY.push(b3[bX])}}}}}else{bF(b6,bY)}if(bR){by(bR,b1,bY,bZ);by.uniqueSort(bY)}return bY};by.uniqueSort=function(bR){if(bJ){bB=bA;bR.sort(bJ);if(bB){for(var e=1;e0};by.find=function(bX,e,bY){var bW,bS,bU,bT,bV,bR;if(!bX){return[]}for(bS=0,bU=bE.order.length;bS":function(bW,bR){var bV,bU=typeof bR==="string",bS=0,e=bW.length;if(bU&&!bQ.test(bR)){bR=bR.toLowerCase();for(;bS=0)){if(!bS){e.push(bV)}}else{if(bS){bR[bU]=false}}}}return false},ID:function(e){return e[1].replace(bK,"")},TAG:function(bR,e){return bR[1].replace(bK,"").toLowerCase()},CHILD:function(e){if(e[1]==="nth"){if(!e[2]){by.error(e[0])}e[2]=e[2].replace(/^\+|\s*/g,"");var bR=/(-?)(\d*)(?:n([+\-]?\d*))?/.exec(e[2]==="even"&&"2n"||e[2]==="odd"&&"2n+1"||!/\D/.test(e[2])&&"0n+"+e[2]||e[2]);e[2]=(bR[1]+(bR[2]||1))-0;e[3]=bR[3]-0}else{if(e[2]){by.error(e[0])}}e[0]=bI++;return e},ATTR:function(bU,bR,bS,e,bV,bW){var bT=bU[1]=bU[1].replace(bK,"");if(!bW&&bE.attrMap[bT]){bU[1]=bE.attrMap[bT]}bU[4]=(bU[4]||bU[5]||"").replace(bK,"");if(bU[2]==="~="){bU[4]=" "+bU[4]+" "}return bU},PSEUDO:function(bU,bR,bS,e,bV){if(bU[1]==="not"){if((bH.exec(bU[3])||"").length>1||/^\w/.test(bU[3])){bU[3]=by(bU[3],null,null,bR)}else{var bT=by.filter(bU[3],bR,bS,true^bV);if(!bS){e.push.apply(e,bT)}return false}}else{if(bE.match.POS.test(bU[0])||bE.match.CHILD.test(bU[0])){return true}}return bU},POS:function(e){e.unshift(true);return e}},filters:{enabled:function(e){return e.disabled===false&&e.type!=="hidden"},disabled:function(e){return e.disabled===true},checked:function(e){return e.checked===true},selected:function(e){if(e.parentNode){e.parentNode.selectedIndex}return e.selected===true},parent:function(e){return !!e.firstChild},empty:function(e){return !e.firstChild},has:function(bS,bR,e){return !!by(e[3],bS).length},header:function(e){return(/h\d/i).test(e.nodeName)},text:function(bS){var e=bS.getAttribute("type"),bR=bS.type;return bS.nodeName.toLowerCase()==="input"&&"text"===bR&&(e===bR||e===null)},radio:function(e){return e.nodeName.toLowerCase()==="input"&&"radio"===e.type},checkbox:function(e){return e.nodeName.toLowerCase()==="input"&&"checkbox"===e.type},file:function(e){return e.nodeName.toLowerCase()==="input"&&"file"===e.type},password:function(e){return e.nodeName.toLowerCase()==="input"&&"password"===e.type},submit:function(bR){var e=bR.nodeName.toLowerCase();return(e==="input"||e==="button")&&"submit"===bR.type},image:function(e){return e.nodeName.toLowerCase()==="input"&&"image"===e.type},reset:function(bR){var e=bR.nodeName.toLowerCase();return(e==="input"||e==="button")&&"reset"===bR.type},button:function(bR){var e=bR.nodeName.toLowerCase();return e==="input"&&"button"===bR.type||e==="button"},input:function(e){return(/input|select|textarea|button/i).test(e.nodeName)},focus:function(e){return e===e.ownerDocument.activeElement}},setFilters:{first:function(bR,e){return e===0},last:function(bS,bR,e,bT){return bR===bT.length-1},even:function(bR,e){return e%2===0},odd:function(bR,e){return e%2===1},lt:function(bS,bR,e){return bRe[3]-0},nth:function(bS,bR,e){return e[3]-0===bR},eq:function(bS,bR,e){return e[3]-0===bR}},filter:{PSEUDO:function(bS,bX,bW,bY){var e=bX[1],bR=bE.filters[e];if(bR){return bR(bS,bW,bX,bY)}else{if(e==="contains"){return(bS.textContent||bS.innerText||bw([bS])||"").indexOf(bX[3])>=0}else{if(e==="not"){var bT=bX[3];for(var bV=0,bU=bT.length;bV=0)}}},ID:function(bR,e){return bR.nodeType===1&&bR.getAttribute("id")===e},TAG:function(bR,e){return(e==="*"&&bR.nodeType===1)||!!bR.nodeName&&bR.nodeName.toLowerCase()===e},CLASS:function(bR,e){return(" "+(bR.className||bR.getAttribute("class"))+" ").indexOf(e)>-1},ATTR:function(bV,bT){var bS=bT[1],e=by.attr?by.attr(bV,bS):bE.attrHandle[bS]?bE.attrHandle[bS](bV):bV[bS]!=null?bV[bS]:bV.getAttribute(bS),bW=e+"",bU=bT[2],bR=bT[4];return e==null?bU==="!=":!bU&&by.attr?e!=null:bU==="="?bW===bR:bU==="*="?bW.indexOf(bR)>=0:bU==="~="?(" "+bW+" ").indexOf(bR)>=0:!bR?bW&&e!==false:bU==="!="?bW!==bR:bU==="^="?bW.indexOf(bR)===0:bU==="$="?bW.substr(bW.length-bR.length)===bR:bU==="|="?bW===bR||bW.substr(0,bR.length+1)===bR+"-":false},POS:function(bU,bR,bS,bV){var e=bR[2],bT=bE.setFilters[e];if(bT){return bT(bU,bS,bR,bV)}}}};var bD=bE.match.POS,bx=function(bR,e){return"\\"+(e-0+1)};for(var bz in bE.match){bE.match[bz]=new RegExp(bE.match[bz].source+(/(?![^\[]*\])(?![^\(]*\))/.source));bE.leftMatch[bz]=new RegExp(/(^(?:.|\r|\n)*?)/.source+bE.match[bz].source.replace(/\\(\d+)/g,bx))}var bF=function(bR,e){bR=Array.prototype.slice.call(bR,0);if(e){e.push.apply(e,bR);return e}return bR};try{Array.prototype.slice.call(av.documentElement.childNodes,0)[0].nodeType}catch(bP){bF=function(bU,bT){var bS=0,bR=bT||[];if(bL.call(bU)==="[object Array]"){Array.prototype.push.apply(bR,bU)}else{if(typeof bU.length==="number"){for(var e=bU.length;bS";e.insertBefore(bR,e.firstChild);if(av.getElementById(bS)){bE.find.ID=function(bU,bV,bW){if(typeof bV.getElementById!=="undefined"&&!bW){var bT=bV.getElementById(bU[1]);return bT?bT.id===bU[1]||typeof bT.getAttributeNode!=="undefined"&&bT.getAttributeNode("id").nodeValue===bU[1]?[bT]:L:[]}};bE.filter.ID=function(bV,bT){var bU=typeof bV.getAttributeNode!=="undefined"&&bV.getAttributeNode("id");return bV.nodeType===1&&bU&&bU.nodeValue===bT}}e.removeChild(bR);e=bR=null})();(function(){var e=av.createElement("div");e.appendChild(av.createComment(""));if(e.getElementsByTagName("*").length>0){bE.find.TAG=function(bR,bV){var bU=bV.getElementsByTagName(bR[1]);if(bR[1]==="*"){var bT=[];for(var bS=0;bU[bS];bS++){if(bU[bS].nodeType===1){bT.push(bU[bS])}}bU=bT}return bU}}e.innerHTML="";if(e.firstChild&&typeof e.firstChild.getAttribute!=="undefined"&&e.firstChild.getAttribute("href")!=="#"){bE.attrHandle.href=function(bR){return bR.getAttribute("href",2)}}e=null})();if(av.querySelectorAll){(function(){var e=by,bT=av.createElement("div"),bS="__sizzle__";bT.innerHTML="

";if(bT.querySelectorAll&&bT.querySelectorAll(".TEST").length===0){return}by=function(b4,bV,bZ,b3){bV=bV||av;if(!b3&&!by.isXML(bV)){var b2=/^(\w+$)|^\.([\w\-]+$)|^#([\w\-]+$)/.exec(b4);if(b2&&(bV.nodeType===1||bV.nodeType===9)){if(b2[1]){return bF(bV.getElementsByTagName(b4),bZ)}else{if(b2[2]&&bE.find.CLASS&&bV.getElementsByClassName){return bF(bV.getElementsByClassName(b2[2]),bZ)}}}if(bV.nodeType===9){if(b4==="body"&&bV.body){return bF([bV.body],bZ)}else{if(b2&&b2[3]){var bY=bV.getElementById(b2[3]);if(bY&&bY.parentNode){if(bY.id===b2[3]){return bF([bY],bZ)}}else{return bF([],bZ)}}}try{return bF(bV.querySelectorAll(b4),bZ)}catch(b0){}}else{if(bV.nodeType===1&&bV.nodeName.toLowerCase()!=="object"){var bW=bV,bX=bV.getAttribute("id"),bU=bX||bS,b6=bV.parentNode,b5=/^\s*[+~]/.test(b4);if(!bX){bV.setAttribute("id",bU)}else{bU=bU.replace(/'/g,"\\$&")}if(b5&&b6){bV=bV.parentNode}try{if(!b5||b6){return bF(bV.querySelectorAll("[id='"+bU+"'] "+b4),bZ)}}catch(b1){}finally{if(!bX){bW.removeAttribute("id")}}}}}return e(b4,bV,bZ,b3)};for(var bR in e){by[bR]=e[bR]}bT=null})()}(function(){var e=av.documentElement,bS=e.matchesSelector||e.mozMatchesSelector||e.webkitMatchesSelector||e.msMatchesSelector;if(bS){var bU=!bS.call(av.createElement("div"),"div"),bR=false;try{bS.call(av.documentElement,"[test!='']:sizzle")}catch(bT){bR=true}by.matchesSelector=function(bW,bY){bY=bY.replace(/\=\s*([^'"\]]*)\s*\]/g,"='$1']");if(!by.isXML(bW)){try{if(bR||!bE.match.PSEUDO.test(bY)&&!/!=/.test(bY)){var bV=bS.call(bW,bY);if(bV||!bU||bW.document&&bW.document.nodeType!==11){return bV}}}catch(bX){}}return by(bY,null,null,[bW]).length>0}}})();(function(){var e=av.createElement("div");e.innerHTML="
";if(!e.getElementsByClassName||e.getElementsByClassName("e").length===0){return}e.lastChild.className="e";if(e.getElementsByClassName("e").length===1){return}bE.order.splice(1,0,"CLASS");bE.find.CLASS=function(bR,bS,bT){if(typeof bS.getElementsByClassName!=="undefined"&&!bT){return bS.getElementsByClassName(bR[1])}};e=null})();function bv(bR,bW,bV,bZ,bX,bY){for(var bT=0,bS=bZ.length;bT0){bU=e;break}}}e=e[bR]}bZ[bT]=bU}}}if(av.documentElement.contains){by.contains=function(bR,e){return bR!==e&&(bR.contains?bR.contains(e):true)}}else{if(av.documentElement.compareDocumentPosition){by.contains=function(bR,e){return !!(bR.compareDocumentPosition(e)&16)}}else{by.contains=function(){return false}}}by.isXML=function(e){var bR=(e?e.ownerDocument||e:0).documentElement;return bR?bR.nodeName!=="HTML":false};var bM=function(bS,e,bW){var bV,bX=[],bU="",bY=e.nodeType?[e]:e;while((bV=bE.match.PSEUDO.exec(bS))){bU+=bV[0];bS=bS.replace(bE.match.PSEUDO,"")}bS=bE.relative[bS]?bS+"*":bS;for(var bT=0,bR=bY.length;bT0){for(bB=bA;bB=0:b.filter(e,this).length>0:this.filter(e).length>0)},closest:function(by,bx){var bv=[],bw,e,bz=this[0];if(b.isArray(by)){var bB=1;while(bz&&bz.ownerDocument&&bz!==bx){for(bw=0;bw-1:b.find.matchesSelector(bz,by)){bv.push(bz);break}else{bz=bz.parentNode;if(!bz||!bz.ownerDocument||bz===bx||bz.nodeType===11){break}}}}bv=bv.length>1?b.unique(bv):bv;return this.pushStack(bv,"closest",by)},index:function(e){if(!e){return(this[0]&&this[0].parentNode)?this.prevAll().length:-1}if(typeof e==="string"){return b.inArray(this[0],b(e))}return b.inArray(e.jquery?e[0]:e,this)},add:function(e,bv){var bx=typeof e==="string"?b(e,bv):b.makeArray(e&&e.nodeType?[e]:e),bw=b.merge(this.get(),bx);return this.pushStack(C(bx[0])||C(bw[0])?bw:b.unique(bw))},andSelf:function(){return this.add(this.prevObject)}});function C(e){return !e||!e.parentNode||e.parentNode.nodeType===11}b.each({parent:function(bv){var e=bv.parentNode;return e&&e.nodeType!==11?e:null},parents:function(e){return b.dir(e,"parentNode")},parentsUntil:function(bv,e,bw){return b.dir(bv,"parentNode",bw)},next:function(e){return b.nth(e,2,"nextSibling")},prev:function(e){return b.nth(e,2,"previousSibling")},nextAll:function(e){return b.dir(e,"nextSibling")},prevAll:function(e){return b.dir(e,"previousSibling")},nextUntil:function(bv,e,bw){return b.dir(bv,"nextSibling",bw)},prevUntil:function(bv,e,bw){return b.dir(bv,"previousSibling",bw)},siblings:function(e){return b.sibling(e.parentNode.firstChild,e)},children:function(e){return b.sibling(e.firstChild)},contents:function(e){return b.nodeName(e,"iframe")?e.contentDocument||e.contentWindow.document:b.makeArray(e.childNodes)}},function(e,bv){b.fn[e]=function(by,bw){var bx=b.map(this,bv,by);if(!ab.test(e)){bw=by}if(bw&&typeof bw==="string"){bx=b.filter(bw,bx)}bx=this.length>1&&!ay[e]?b.unique(bx):bx;if((this.length>1||a9.test(bw))&&aq.test(e)){bx=bx.reverse()}return this.pushStack(bx,e,P.call(arguments).join(","))}});b.extend({filter:function(bw,e,bv){if(bv){bw=":not("+bw+")"}return e.length===1?b.find.matchesSelector(e[0],bw)?[e[0]]:[]:b.find.matches(bw,e)},dir:function(bw,bv,by){var e=[],bx=bw[bv];while(bx&&bx.nodeType!==9&&(by===L||bx.nodeType!==1||!b(bx).is(by))){if(bx.nodeType===1){e.push(bx)}bx=bx[bv]}return e},nth:function(by,e,bw,bx){e=e||1;var bv=0;for(;by;by=by[bw]){if(by.nodeType===1&&++bv===e){break}}return by},sibling:function(bw,bv){var e=[];for(;bw;bw=bw.nextSibling){if(bw.nodeType===1&&bw!==bv){e.push(bw)}}return e}});function aG(bx,bw,e){bw=bw||0;if(b.isFunction(bw)){return b.grep(bx,function(bz,by){var bA=!!bw.call(bz,by,bz);return bA===e})}else{if(bw.nodeType){return b.grep(bx,function(bz,by){return(bz===bw)===e})}else{if(typeof bw==="string"){var bv=b.grep(bx,function(by){return by.nodeType===1});if(bp.test(bw)){return b.filter(bw,bv,!e)}else{bw=b.filter(bw,bv)}}}}return b.grep(bx,function(bz,by){return(b.inArray(bz,bw)>=0)===e})}function a(e){var bw=aR.split("|"),bv=e.createDocumentFragment();if(bv.createElement){while(bw.length){bv.createElement(bw.pop())}}return bv}var aR="abbr|article|aside|audio|canvas|datalist|details|figcaption|figure|footer|header|hgroup|mark|meter|nav|output|progress|section|summary|time|video",ag=/ jQuery\d+="(?:\d+|null)"/g,ar=/^\s+/,R=/<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/ig,d=/<([\w:]+)/,w=/",""],legend:[1,"
","
"],thead:[1,"","
"],tr:[2,"","
"],td:[3,"","
"],col:[2,"","
"],area:[1,"",""],_default:[0,"",""]},ac=a(av);ax.optgroup=ax.option;ax.tbody=ax.tfoot=ax.colgroup=ax.caption=ax.thead;ax.th=ax.td;if(!b.support.htmlSerialize){ax._default=[1,"div
","
"]}b.fn.extend({text:function(e){if(b.isFunction(e)){return this.each(function(bw){var bv=b(this);bv.text(e.call(this,bw,bv.text()))})}if(typeof e!=="object"&&e!==L){return this.empty().append((this[0]&&this[0].ownerDocument||av).createTextNode(e))}return b.text(this)},wrapAll:function(e){if(b.isFunction(e)){return this.each(function(bw){b(this).wrapAll(e.call(this,bw))})}if(this[0]){var bv=b(e,this[0].ownerDocument).eq(0).clone(true);if(this[0].parentNode){bv.insertBefore(this[0])}bv.map(function(){var bw=this;while(bw.firstChild&&bw.firstChild.nodeType===1){bw=bw.firstChild}return bw}).append(this)}return this},wrapInner:function(e){if(b.isFunction(e)){return this.each(function(bv){b(this).wrapInner(e.call(this,bv))})}return this.each(function(){var bv=b(this),bw=bv.contents();if(bw.length){bw.wrapAll(e)}else{bv.append(e)}})},wrap:function(e){var bv=b.isFunction(e);return this.each(function(bw){b(this).wrapAll(bv?e.call(this,bw):e)})},unwrap:function(){return this.parent().each(function(){if(!b.nodeName(this,"body")){b(this).replaceWith(this.childNodes)}}).end()},append:function(){return this.domManip(arguments,true,function(e){if(this.nodeType===1){this.appendChild(e)}})},prepend:function(){return this.domManip(arguments,true,function(e){if(this.nodeType===1){this.insertBefore(e,this.firstChild)}})},before:function(){if(this[0]&&this[0].parentNode){return this.domManip(arguments,false,function(bv){this.parentNode.insertBefore(bv,this)})}else{if(arguments.length){var e=b.clean(arguments);e.push.apply(e,this.toArray());return this.pushStack(e,"before",arguments)}}},after:function(){if(this[0]&&this[0].parentNode){return this.domManip(arguments,false,function(bv){this.parentNode.insertBefore(bv,this.nextSibling)})}else{if(arguments.length){var e=this.pushStack(this,"after",arguments);e.push.apply(e,b.clean(arguments));return e}}},remove:function(e,bx){for(var bv=0,bw;(bw=this[bv])!=null;bv++){if(!e||b.filter(e,[bw]).length){if(!bx&&bw.nodeType===1){b.cleanData(bw.getElementsByTagName("*"));b.cleanData([bw])}if(bw.parentNode){bw.parentNode.removeChild(bw)}}}return this},empty:function(){for(var e=0,bv;(bv=this[e])!=null;e++){if(bv.nodeType===1){b.cleanData(bv.getElementsByTagName("*"))}while(bv.firstChild){bv.removeChild(bv.firstChild)}}return this},clone:function(bv,e){bv=bv==null?false:bv;e=e==null?bv:e;return this.map(function(){return b.clone(this,bv,e)})},html:function(bx){if(bx===L){return this[0]&&this[0].nodeType===1?this[0].innerHTML.replace(ag,""):null}else{if(typeof bx==="string"&&!ae.test(bx)&&(b.support.leadingWhitespace||!ar.test(bx))&&!ax[(d.exec(bx)||["",""])[1].toLowerCase()]){bx=bx.replace(R,"<$1>");try{for(var bw=0,bv=this.length;bw1&&bw0?this.clone(true):this).get();b(bC[bA])[bv](by);bz=bz.concat(by)}return this.pushStack(bz,e,bC.selector)}}});function bg(e){if(typeof e.getElementsByTagName!=="undefined"){return e.getElementsByTagName("*")}else{if(typeof e.querySelectorAll!=="undefined"){return e.querySelectorAll("*")}else{return[]}}}function az(e){if(e.type==="checkbox"||e.type==="radio"){e.defaultChecked=e.checked}}function E(e){var bv=(e.nodeName||"").toLowerCase();if(bv==="input"){az(e)}else{if(bv!=="script"&&typeof e.getElementsByTagName!=="undefined"){b.grep(e.getElementsByTagName("input"),az)}}}function al(e){var bv=av.createElement("div");ac.appendChild(bv);bv.innerHTML=e.outerHTML;return bv.firstChild}b.extend({clone:function(by,bA,bw){var e,bv,bx,bz=b.support.html5Clone||!ah.test("<"+by.nodeName)?by.cloneNode(true):al(by);if((!b.support.noCloneEvent||!b.support.noCloneChecked)&&(by.nodeType===1||by.nodeType===11)&&!b.isXMLDoc(by)){ai(by,bz);e=bg(by);bv=bg(bz);for(bx=0;e[bx];++bx){if(bv[bx]){ai(e[bx],bv[bx])}}}if(bA){t(by,bz);if(bw){e=bg(by);bv=bg(bz);for(bx=0;e[bx];++bx){t(e[bx],bv[bx])}}}e=bv=null;return bz},clean:function(bw,by,bH,bA){var bF;by=by||av;if(typeof by.createElement==="undefined"){by=by.ownerDocument||by[0]&&by[0].ownerDocument||av}var bI=[],bB;for(var bE=0,bz;(bz=bw[bE])!=null;bE++){if(typeof bz==="number"){bz+=""}if(!bz){continue}if(typeof bz==="string"){if(!W.test(bz)){bz=by.createTextNode(bz)}else{bz=bz.replace(R,"<$1>");var bK=(d.exec(bz)||["",""])[1].toLowerCase(),bx=ax[bK]||ax._default,bD=bx[0],bv=by.createElement("div");if(by===av){ac.appendChild(bv)}else{a(by).appendChild(bv)}bv.innerHTML=bx[1]+bz+bx[2];while(bD--){bv=bv.lastChild}if(!b.support.tbody){var e=w.test(bz),bC=bK==="table"&&!e?bv.firstChild&&bv.firstChild.childNodes:bx[1]===""&&!e?bv.childNodes:[];for(bB=bC.length-1;bB>=0;--bB){if(b.nodeName(bC[bB],"tbody")&&!bC[bB].childNodes.length){bC[bB].parentNode.removeChild(bC[bB])}}}if(!b.support.leadingWhitespace&&ar.test(bz)){bv.insertBefore(by.createTextNode(ar.exec(bz)[0]),bv.firstChild)}bz=bv.childNodes}}var bG;if(!b.support.appendChecked){if(bz[0]&&typeof(bG=bz.length)==="number"){for(bB=0;bB=0){return bx+"px"}}else{return bx}}}});if(!b.support.opacity){b.cssHooks.opacity={get:function(bv,e){return au.test((e&&bv.currentStyle?bv.currentStyle.filter:bv.style.filter)||"")?(parseFloat(RegExp.$1)/100)+"":e?"1":""},set:function(by,bz){var bx=by.style,bv=by.currentStyle,e=b.isNumeric(bz)?"alpha(opacity="+bz*100+")":"",bw=bv&&bv.filter||bx.filter||"";bx.zoom=1;if(bz>=1&&b.trim(bw.replace(ak,""))===""){bx.removeAttribute("filter");if(bv&&!bv.filter){return}}bx.filter=ak.test(bw)?bw.replace(ak,e):bw+" "+e}}}b(function(){if(!b.support.reliableMarginRight){b.cssHooks.marginRight={get:function(bw,bv){var e;b.swap(bw,{display:"inline-block"},function(){if(bv){e=Z(bw,"margin-right","marginRight")}else{e=bw.style.marginRight}});return e}}}});if(av.defaultView&&av.defaultView.getComputedStyle){aI=function(by,bw){var bv,bx,e;bw=bw.replace(z,"-$1").toLowerCase();if((bx=by.ownerDocument.defaultView)&&(e=bx.getComputedStyle(by,null))){bv=e.getPropertyValue(bw);if(bv===""&&!b.contains(by.ownerDocument.documentElement,by)){bv=b.style(by,bw)}}return bv}}if(av.documentElement.currentStyle){aX=function(bz,bw){var bA,e,by,bv=bz.currentStyle&&bz.currentStyle[bw],bx=bz.style;if(bv===null&&bx&&(by=bx[bw])){bv=by}if(!bc.test(bv)&&bn.test(bv)){bA=bx.left;e=bz.runtimeStyle&&bz.runtimeStyle.left;if(e){bz.runtimeStyle.left=bz.currentStyle.left}bx.left=bw==="fontSize"?"1em":(bv||0);bv=bx.pixelLeft+"px";bx.left=bA;if(e){bz.runtimeStyle.left=e}}return bv===""?"auto":bv}}Z=aI||aX;function p(by,bw,bv){var bA=bw==="width"?by.offsetWidth:by.offsetHeight,bz=bw==="width"?an:a1,bx=0,e=bz.length;if(bA>0){if(bv!=="border"){for(;bx)<[^<]*)*<\/script>/gi,q=/^(?:select|textarea)/i,h=/\s+/,br=/([?&])_=[^&]*/,K=/^([\w\+\.\-]+:)(?:\/\/([^\/?#:]*)(?::(\d+))?)?/,A=b.fn.load,aa={},r={},aE,s,aV=["*/"]+["*"];try{aE=bl.href}catch(aw){aE=av.createElement("a");aE.href="";aE=aE.href}s=K.exec(aE.toLowerCase())||[];function f(e){return function(by,bA){if(typeof by!=="string"){bA=by;by="*"}if(b.isFunction(bA)){var bx=by.toLowerCase().split(h),bw=0,bz=bx.length,bv,bB,bC;for(;bw=0){var e=bw.slice(by,bw.length);bw=bw.slice(0,by)}var bx="GET";if(bz){if(b.isFunction(bz)){bA=bz;bz=L}else{if(typeof bz==="object"){bz=b.param(bz,b.ajaxSettings.traditional);bx="POST"}}}var bv=this;b.ajax({url:bw,type:bx,dataType:"html",data:bz,complete:function(bC,bB,bD){bD=bC.responseText;if(bC.isResolved()){bC.done(function(bE){bD=bE});bv.html(e?b("
").append(bD.replace(a6,"")).find(e):bD)}if(bA){bv.each(bA,[bD,bB,bC])}}});return this},serialize:function(){return b.param(this.serializeArray())},serializeArray:function(){return this.map(function(){return this.elements?b.makeArray(this.elements):this}).filter(function(){return this.name&&!this.disabled&&(this.checked||q.test(this.nodeName)||aZ.test(this.type))}).map(function(e,bv){var bw=b(this).val();return bw==null?null:b.isArray(bw)?b.map(bw,function(by,bx){return{name:bv.name,value:by.replace(bs,"\r\n")}}):{name:bv.name,value:bw.replace(bs,"\r\n")}}).get()}});b.each("ajaxStart ajaxStop ajaxComplete ajaxError ajaxSuccess ajaxSend".split(" "),function(e,bv){b.fn[bv]=function(bw){return this.on(bv,bw)}});b.each(["get","post"],function(e,bv){b[bv]=function(bw,by,bz,bx){if(b.isFunction(by)){bx=bx||bz;bz=by;by=L}return b.ajax({type:bv,url:bw,data:by,success:bz,dataType:bx})}});b.extend({getScript:function(e,bv){return b.get(e,L,bv,"script")},getJSON:function(e,bv,bw){return b.get(e,bv,bw,"json")},ajaxSetup:function(bv,e){if(e){am(bv,b.ajaxSettings)}else{e=bv;bv=b.ajaxSettings}am(bv,e);return bv},ajaxSettings:{url:aE,isLocal:aM.test(s[1]),global:true,type:"GET",contentType:"application/x-www-form-urlencoded",processData:true,async:true,accepts:{xml:"application/xml, text/xml",html:"text/html",text:"text/plain",json:"application/json, text/javascript","*":aV},contents:{xml:/xml/,html:/html/,json:/json/},responseFields:{xml:"responseXML",text:"responseText"},converters:{"* text":bb.String,"text html":true,"text json":b.parseJSON,"text xml":b.parseXML},flatOptions:{context:true,url:true}},ajaxPrefilter:f(aa),ajaxTransport:f(r),ajax:function(bz,bx){if(typeof bz==="object"){bx=bz;bz=L}bx=bx||{};var bD=b.ajaxSetup({},bx),bS=bD.context||bD,bG=bS!==bD&&(bS.nodeType||bS instanceof b)?b(bS):b.event,bR=b.Deferred(),bN=b.Callbacks("once memory"),bB=bD.statusCode||{},bC,bH={},bO={},bQ,by,bL,bE,bI,bA=0,bw,bK,bJ={readyState:0,setRequestHeader:function(bT,bU){if(!bA){var e=bT.toLowerCase();bT=bO[e]=bO[e]||bT;bH[bT]=bU}return this},getAllResponseHeaders:function(){return bA===2?bQ:null},getResponseHeader:function(bT){var e;if(bA===2){if(!by){by={};while((e=aD.exec(bQ))){by[e[1].toLowerCase()]=e[2]}}e=by[bT.toLowerCase()]}return e===L?null:e},overrideMimeType:function(e){if(!bA){bD.mimeType=e}return this},abort:function(e){e=e||"abort";if(bL){bL.abort(e)}bF(0,e);return this}};function bF(bZ,bU,b0,bW){if(bA===2){return}bA=2;if(bE){clearTimeout(bE)}bL=L;bQ=bW||"";bJ.readyState=bZ>0?4:0;var bT,b4,b3,bX=bU,bY=b0?bj(bD,bJ,b0):L,bV,b2;if(bZ>=200&&bZ<300||bZ===304){if(bD.ifModified){if((bV=bJ.getResponseHeader("Last-Modified"))){b.lastModified[bC]=bV}if((b2=bJ.getResponseHeader("Etag"))){b.etag[bC]=b2}}if(bZ===304){bX="notmodified";bT=true}else{try{b4=G(bD,bY);bX="success";bT=true}catch(b1){bX="parsererror";b3=b1}}}else{b3=bX;if(!bX||bZ){bX="error";if(bZ<0){bZ=0}}}bJ.status=bZ;bJ.statusText=""+(bU||bX);if(bT){bR.resolveWith(bS,[b4,bX,bJ])}else{bR.rejectWith(bS,[bJ,bX,b3])}bJ.statusCode(bB);bB=L;if(bw){bG.trigger("ajax"+(bT?"Success":"Error"),[bJ,bD,bT?b4:b3])}bN.fireWith(bS,[bJ,bX]);if(bw){bG.trigger("ajaxComplete",[bJ,bD]);if(!(--b.active)){b.event.trigger("ajaxStop")}}}bR.promise(bJ);bJ.success=bJ.done;bJ.error=bJ.fail;bJ.complete=bN.add;bJ.statusCode=function(bT){if(bT){var e;if(bA<2){for(e in bT){bB[e]=[bB[e],bT[e]]}}else{e=bT[bJ.status];bJ.then(e,e)}}return this};bD.url=((bz||bD.url)+"").replace(bq,"").replace(c,s[1]+"//");bD.dataTypes=b.trim(bD.dataType||"*").toLowerCase().split(h);if(bD.crossDomain==null){bI=K.exec(bD.url.toLowerCase());bD.crossDomain=!!(bI&&(bI[1]!=s[1]||bI[2]!=s[2]||(bI[3]||(bI[1]==="http:"?80:443))!=(s[3]||(s[1]==="http:"?80:443))))}if(bD.data&&bD.processData&&typeof bD.data!=="string"){bD.data=b.param(bD.data,bD.traditional)}aW(aa,bD,bx,bJ);if(bA===2){return false}bw=bD.global;bD.type=bD.type.toUpperCase();bD.hasContent=!aQ.test(bD.type);if(bw&&b.active++===0){b.event.trigger("ajaxStart")}if(!bD.hasContent){if(bD.data){bD.url+=(M.test(bD.url)?"&":"?")+bD.data;delete bD.data}bC=bD.url;if(bD.cache===false){var bv=b.now(),bP=bD.url.replace(br,"$1_="+bv);bD.url=bP+((bP===bD.url)?(M.test(bD.url)?"&":"?")+"_="+bv:"")}}if(bD.data&&bD.hasContent&&bD.contentType!==false||bx.contentType){bJ.setRequestHeader("Content-Type",bD.contentType)}if(bD.ifModified){bC=bC||bD.url;if(b.lastModified[bC]){bJ.setRequestHeader("If-Modified-Since",b.lastModified[bC])}if(b.etag[bC]){bJ.setRequestHeader("If-None-Match",b.etag[bC])}}bJ.setRequestHeader("Accept",bD.dataTypes[0]&&bD.accepts[bD.dataTypes[0]]?bD.accepts[bD.dataTypes[0]]+(bD.dataTypes[0]!=="*"?", "+aV+"; q=0.01":""):bD.accepts["*"]);for(bK in bD.headers){bJ.setRequestHeader(bK,bD.headers[bK])}if(bD.beforeSend&&(bD.beforeSend.call(bS,bJ,bD)===false||bA===2)){bJ.abort();return false}for(bK in {success:1,error:1,complete:1}){bJ[bK](bD[bK])}bL=aW(r,bD,bx,bJ);if(!bL){bF(-1,"No Transport")}else{bJ.readyState=1;if(bw){bG.trigger("ajaxSend",[bJ,bD])}if(bD.async&&bD.timeout>0){bE=setTimeout(function(){bJ.abort("timeout")},bD.timeout)}try{bA=1;bL.send(bH,bF)}catch(bM){if(bA<2){bF(-1,bM)}else{throw bM}}}return bJ},param:function(e,bw){var bv=[],by=function(bz,bA){bA=b.isFunction(bA)?bA():bA;bv[bv.length]=encodeURIComponent(bz)+"="+encodeURIComponent(bA)};if(bw===L){bw=b.ajaxSettings.traditional}if(b.isArray(e)||(e.jquery&&!b.isPlainObject(e))){b.each(e,function(){by(this.name,this.value)})}else{for(var bx in e){v(bx,e[bx],bw,by)}}return bv.join("&").replace(k,"+")}});function v(bw,by,bv,bx){if(b.isArray(by)){b.each(by,function(bA,bz){if(bv||ap.test(bw)){bx(bw,bz)}else{v(bw+"["+(typeof bz==="object"||b.isArray(bz)?bA:"")+"]",bz,bv,bx)}})}else{if(!bv&&by!=null&&typeof by==="object"){for(var e in by){v(bw+"["+e+"]",by[e],bv,bx)}}else{bx(bw,by)}}}b.extend({active:0,lastModified:{},etag:{}});function bj(bD,bC,bz){var bv=bD.contents,bB=bD.dataTypes,bw=bD.responseFields,by,bA,bx,e;for(bA in bw){if(bA in bz){bC[bw[bA]]=bz[bA]}}while(bB[0]==="*"){bB.shift();if(by===L){by=bD.mimeType||bC.getResponseHeader("content-type")}}if(by){for(bA in bv){if(bv[bA]&&bv[bA].test(by)){bB.unshift(bA);break}}}if(bB[0] in bz){bx=bB[0]}else{for(bA in bz){if(!bB[0]||bD.converters[bA+" "+bB[0]]){bx=bA;break}if(!e){e=bA}}bx=bx||e}if(bx){if(bx!==bB[0]){bB.unshift(bx)}return bz[bx]}}function G(bH,bz){if(bH.dataFilter){bz=bH.dataFilter(bz,bH.dataType)}var bD=bH.dataTypes,bG={},bA,bE,bw=bD.length,bB,bC=bD[0],bx,by,bF,bv,e;for(bA=1;bA=bw.duration+this.startTime){this.now=this.end;this.pos=this.state=1;this.update();bw.animatedProperties[this.prop]=true;for(bA in bw.animatedProperties){if(bw.animatedProperties[bA]!==true){e=false}}if(e){if(bw.overflow!=null&&!b.support.shrinkWrapBlocks){b.each(["","X","Y"],function(bC,bD){bz.style["overflow"+bD]=bw.overflow[bC]})}if(bw.hide){b(bz).hide()}if(bw.hide||bw.show){for(bA in bw.animatedProperties){b.style(bz,bA,bw.orig[bA]);b.removeData(bz,"fxshow"+bA,true);b.removeData(bz,"toggle"+bA,true)}}bv=bw.complete;if(bv){bw.complete=false;bv.call(bz)}}return false}else{if(bw.duration==Infinity){this.now=bx}else{bB=bx-this.startTime;this.state=bB/bw.duration;this.pos=b.easing[bw.animatedProperties[this.prop]](this.state,bB,0,1,bw.duration);this.now=this.start+((this.end-this.start)*this.pos)}this.update()}return true}};b.extend(b.fx,{tick:function(){var bw,bv=b.timers,e=0;for(;e").appendTo(e),bw=bv.css("display");bv.remove();if(bw==="none"||bw===""){if(!a8){a8=av.createElement("iframe");a8.frameBorder=a8.width=a8.height=0}e.appendChild(a8);if(!m||!a8.createElement){m=(a8.contentWindow||a8.contentDocument).document;m.write((av.compatMode==="CSS1Compat"?"":"")+"");m.close()}bv=m.createElement(bx);m.body.appendChild(bv);bw=b.css(bv,"display");e.removeChild(a8)}Q[bx]=bw}return Q[bx]}var V=/^t(?:able|d|h)$/i,ad=/^(?:body|html)$/i;if("getBoundingClientRect" in av.documentElement){b.fn.offset=function(bI){var by=this[0],bB;if(bI){return this.each(function(e){b.offset.setOffset(this,bI,e)})}if(!by||!by.ownerDocument){return null}if(by===by.ownerDocument.body){return b.offset.bodyOffset(by)}try{bB=by.getBoundingClientRect()}catch(bF){}var bH=by.ownerDocument,bw=bH.documentElement;if(!bB||!b.contains(bw,by)){return bB?{top:bB.top,left:bB.left}:{top:0,left:0}}var bC=bH.body,bD=aK(bH),bA=bw.clientTop||bC.clientTop||0,bE=bw.clientLeft||bC.clientLeft||0,bv=bD.pageYOffset||b.support.boxModel&&bw.scrollTop||bC.scrollTop,bz=bD.pageXOffset||b.support.boxModel&&bw.scrollLeft||bC.scrollLeft,bG=bB.top+bv-bA,bx=bB.left+bz-bE;return{top:bG,left:bx}}}else{b.fn.offset=function(bF){var bz=this[0];if(bF){return this.each(function(bG){b.offset.setOffset(this,bF,bG)})}if(!bz||!bz.ownerDocument){return null}if(bz===bz.ownerDocument.body){return b.offset.bodyOffset(bz)}var bC,bw=bz.offsetParent,bv=bz,bE=bz.ownerDocument,bx=bE.documentElement,bA=bE.body,bB=bE.defaultView,e=bB?bB.getComputedStyle(bz,null):bz.currentStyle,bD=bz.offsetTop,by=bz.offsetLeft;while((bz=bz.parentNode)&&bz!==bA&&bz!==bx){if(b.support.fixedPosition&&e.position==="fixed"){break}bC=bB?bB.getComputedStyle(bz,null):bz.currentStyle;bD-=bz.scrollTop;by-=bz.scrollLeft;if(bz===bw){bD+=bz.offsetTop;by+=bz.offsetLeft;if(b.support.doesNotAddBorder&&!(b.support.doesAddBorderForTableAndCells&&V.test(bz.nodeName))){bD+=parseFloat(bC.borderTopWidth)||0;by+=parseFloat(bC.borderLeftWidth)||0}bv=bw;bw=bz.offsetParent}if(b.support.subtractsBorderForOverflowNotVisible&&bC.overflow!=="visible"){bD+=parseFloat(bC.borderTopWidth)||0;by+=parseFloat(bC.borderLeftWidth)||0}e=bC}if(e.position==="relative"||e.position==="static"){bD+=bA.offsetTop;by+=bA.offsetLeft}if(b.support.fixedPosition&&e.position==="fixed"){bD+=Math.max(bx.scrollTop,bA.scrollTop);by+=Math.max(bx.scrollLeft,bA.scrollLeft)}return{top:bD,left:by}}}b.offset={bodyOffset:function(e){var bw=e.offsetTop,bv=e.offsetLeft;if(b.support.doesNotIncludeMarginInBodyOffset){bw+=parseFloat(b.css(e,"marginTop"))||0;bv+=parseFloat(b.css(e,"marginLeft"))||0}return{top:bw,left:bv}},setOffset:function(bx,bG,bA){var bB=b.css(bx,"position");if(bB==="static"){bx.style.position="relative"}var bz=b(bx),bv=bz.offset(),e=b.css(bx,"top"),bE=b.css(bx,"left"),bF=(bB==="absolute"||bB==="fixed")&&b.inArray("auto",[e,bE])>-1,bD={},bC={},bw,by;if(bF){bC=bz.position();bw=bC.top;by=bC.left}else{bw=parseFloat(e)||0;by=parseFloat(bE)||0}if(b.isFunction(bG)){bG=bG.call(bx,bA,bv)}if(bG.top!=null){bD.top=(bG.top-bv.top)+bw}if(bG.left!=null){bD.left=(bG.left-bv.left)+by}if("using" in bG){bG.using.call(bx,bD)}else{bz.css(bD)}}};b.fn.extend({position:function(){if(!this[0]){return null}var bw=this[0],bv=this.offsetParent(),bx=this.offset(),e=ad.test(bv[0].nodeName)?{top:0,left:0}:bv.offset();bx.top-=parseFloat(b.css(bw,"marginTop"))||0;bx.left-=parseFloat(b.css(bw,"marginLeft"))||0;e.top+=parseFloat(b.css(bv[0],"borderTopWidth"))||0;e.left+=parseFloat(b.css(bv[0],"borderLeftWidth"))||0;return{top:bx.top-e.top,left:bx.left-e.left}},offsetParent:function(){return this.map(function(){var e=this.offsetParent||av.body;while(e&&(!ad.test(e.nodeName)&&b.css(e,"position")==="static")){e=e.offsetParent}return e})}});b.each(["Left","Top"],function(bv,e){var bw="scroll"+e;b.fn[bw]=function(bz){var bx,by;if(bz===L){bx=this[0];if(!bx){return null}by=aK(bx);return by?("pageXOffset" in by)?by[bv?"pageYOffset":"pageXOffset"]:b.support.boxModel&&by.document.documentElement[bw]||by.document.body[bw]:bx[bw]}return this.each(function(){by=aK(this);if(by){by.scrollTo(!bv?bz:b(by).scrollLeft(),bv?bz:b(by).scrollTop())}else{this[bw]=bz}})}});function aK(e){return b.isWindow(e)?e:e.nodeType===9?e.defaultView||e.parentWindow:false}b.each(["Height","Width"],function(bv,e){var bw=e.toLowerCase();b.fn["inner"+e]=function(){var bx=this[0];return bx?bx.style?parseFloat(b.css(bx,bw,"padding")):this[bw]():null};b.fn["outer"+e]=function(by){var bx=this[0];return bx?bx.style?parseFloat(b.css(bx,bw,by?"margin":"border")):this[bw]():null};b.fn[bw]=function(bz){var bA=this[0];if(!bA){return bz==null?null:this}if(b.isFunction(bz)){return this.each(function(bE){var bD=b(this);bD[bw](bz.call(this,bE,bD[bw]()))})}if(b.isWindow(bA)){var bB=bA.document.documentElement["client"+e],bx=bA.document.body;return bA.document.compatMode==="CSS1Compat"&&bB||bx&&bx["client"+e]||bB}else{if(bA.nodeType===9){return Math.max(bA.documentElement["client"+e],bA.body["scroll"+e],bA.documentElement["scroll"+e],bA.body["offset"+e],bA.documentElement["offset"+e])}else{if(bz===L){var bC=b.css(bA,bw),by=parseFloat(bC);return b.isNumeric(by)?by:bC}else{return this.css(bw,typeof bz==="string"?bz:bz+"px")}}}}});bb.jQuery=bb.$=b;if(typeof define==="function"&&define.amd&&define.amd.jQuery){define("jquery",[],function(){return b})}})(window);/* +(function(){var bH=/((?:\((?:\([^()]+\)|[^()]+)+\)|\[(?:\[[^\[\]]*\]|['"][^'"]*['"]|[^\[\]'"]+)+\]|\\.|[^ >+~,(\[\\]+)+|[>+~])(\s*,\s*)?((?:.|\r|\n)*)/g,bC="sizcache"+(Math.random()+"").replace(".",""),bI=0,bL=Object.prototype.toString,bB=false,bA=true,bK=/\\/g,bO=/\r\n/g,bQ=/\W/;[0,0].sort(function(){bA=false;return 0});var by=function(bV,e,bY,bZ){bY=bY||[];e=e||av;var b1=e;if(e.nodeType!==1&&e.nodeType!==9){return[]}if(!bV||typeof bV!=="string"){return bY}var bS,b3,b6,bR,b2,b5,b4,bX,bU=true,bT=by.isXML(e),bW=[],b0=bV;do{bH.exec("");bS=bH.exec(b0);if(bS){b0=bS[3];bW.push(bS[1]);if(bS[2]){bR=bS[3];break}}}while(bS);if(bW.length>1&&bD.exec(bV)){if(bW.length===2&&bE.relative[bW[0]]){b3=bM(bW[0]+bW[1],e,bZ)}else{b3=bE.relative[bW[0]]?[e]:by(bW.shift(),e);while(bW.length){bV=bW.shift();if(bE.relative[bV]){bV+=bW.shift()}b3=bM(bV,b3,bZ)}}}else{if(!bZ&&bW.length>1&&e.nodeType===9&&!bT&&bE.match.ID.test(bW[0])&&!bE.match.ID.test(bW[bW.length-1])){b2=by.find(bW.shift(),e,bT);e=b2.expr?by.filter(b2.expr,b2.set)[0]:b2.set[0]}if(e){b2=bZ?{expr:bW.pop(),set:bF(bZ)}:by.find(bW.pop(),bW.length===1&&(bW[0]==="~"||bW[0]==="+")&&e.parentNode?e.parentNode:e,bT);b3=b2.expr?by.filter(b2.expr,b2.set):b2.set;if(bW.length>0){b6=bF(b3)}else{bU=false}while(bW.length){b5=bW.pop();b4=b5;if(!bE.relative[b5]){b5=""}else{b4=bW.pop()}if(b4==null){b4=e}bE.relative[b5](b6,b4,bT)}}else{b6=bW=[]}}if(!b6){b6=b3}if(!b6){by.error(b5||bV)}if(bL.call(b6)==="[object Array]"){if(!bU){bY.push.apply(bY,b6)}else{if(e&&e.nodeType===1){for(bX=0;b6[bX]!=null;bX++){if(b6[bX]&&(b6[bX]===true||b6[bX].nodeType===1&&by.contains(e,b6[bX]))){bY.push(b3[bX])}}}else{for(bX=0;b6[bX]!=null;bX++){if(b6[bX]&&b6[bX].nodeType===1){bY.push(b3[bX])}}}}}else{bF(b6,bY)}if(bR){by(bR,b1,bY,bZ);by.uniqueSort(bY)}return bY};by.uniqueSort=function(bR){if(bJ){bB=bA;bR.sort(bJ);if(bB){for(var e=1;e0};by.find=function(bX,e,bY){var bW,bS,bU,bT,bV,bR;if(!bX){return[]}for(bS=0,bU=bE.order.length;bS":function(bW,bR){var bV,bU=typeof bR==="string",bS=0,e=bW.length;if(bU&&!bQ.test(bR)){bR=bR.toLowerCase();for(;bS=0)){if(!bS){e.push(bV)}}else{if(bS){bR[bU]=false}}}}return false},ID:function(e){return e[1].replace(bK,"")},TAG:function(bR,e){return bR[1].replace(bK,"").toLowerCase()},CHILD:function(e){if(e[1]==="nth"){if(!e[2]){by.error(e[0])}e[2]=e[2].replace(/^\+|\s*/g,"");var bR=/(-?)(\d*)(?:n([+\-]?\d*))?/.exec(e[2]==="even"&&"2n"||e[2]==="odd"&&"2n+1"||!/\D/.test(e[2])&&"0n+"+e[2]||e[2]);e[2]=(bR[1]+(bR[2]||1))-0;e[3]=bR[3]-0}else{if(e[2]){by.error(e[0])}}e[0]=bI++;return e},ATTR:function(bU,bR,bS,e,bV,bW){var bT=bU[1]=bU[1].replace(bK,"");if(!bW&&bE.attrMap[bT]){bU[1]=bE.attrMap[bT]}bU[4]=(bU[4]||bU[5]||"").replace(bK,"");if(bU[2]==="~="){bU[4]=" "+bU[4]+" "}return bU},PSEUDO:function(bU,bR,bS,e,bV){if(bU[1]==="not"){if((bH.exec(bU[3])||"").length>1||/^\w/.test(bU[3])){bU[3]=by(bU[3],null,null,bR)}else{var bT=by.filter(bU[3],bR,bS,true^bV);if(!bS){e.push.apply(e,bT)}return false}}else{if(bE.match.POS.test(bU[0])||bE.match.CHILD.test(bU[0])){return true}}return bU},POS:function(e){e.unshift(true);return e}},filters:{enabled:function(e){return e.disabled===false&&e.type!=="hidden"},disabled:function(e){return e.disabled===true},checked:function(e){return e.checked===true},selected:function(e){if(e.parentNode){e.parentNode.selectedIndex}return e.selected===true},parent:function(e){return !!e.firstChild},empty:function(e){return !e.firstChild},has:function(bS,bR,e){return !!by(e[3],bS).length},header:function(e){return(/h\d/i).test(e.nodeName)},text:function(bS){var e=bS.getAttribute("type"),bR=bS.type;return bS.nodeName.toLowerCase()==="input"&&"text"===bR&&(e===bR||e===null)},radio:function(e){return e.nodeName.toLowerCase()==="input"&&"radio"===e.type},checkbox:function(e){return e.nodeName.toLowerCase()==="input"&&"checkbox"===e.type},file:function(e){return e.nodeName.toLowerCase()==="input"&&"file"===e.type},password:function(e){return e.nodeName.toLowerCase()==="input"&&"password"===e.type},submit:function(bR){var e=bR.nodeName.toLowerCase();return(e==="input"||e==="button")&&"submit"===bR.type},image:function(e){return e.nodeName.toLowerCase()==="input"&&"image"===e.type},reset:function(bR){var e=bR.nodeName.toLowerCase();return(e==="input"||e==="button")&&"reset"===bR.type},button:function(bR){var e=bR.nodeName.toLowerCase();return e==="input"&&"button"===bR.type||e==="button"},input:function(e){return(/input|select|textarea|button/i).test(e.nodeName)},focus:function(e){return e===e.ownerDocument.activeElement}},setFilters:{first:function(bR,e){return e===0},last:function(bS,bR,e,bT){return bR===bT.length-1},even:function(bR,e){return e%2===0},odd:function(bR,e){return e%2===1},lt:function(bS,bR,e){return bRe[3]-0},nth:function(bS,bR,e){return e[3]-0===bR},eq:function(bS,bR,e){return e[3]-0===bR}},filter:{PSEUDO:function(bS,bX,bW,bY){var e=bX[1],bR=bE.filters[e];if(bR){return bR(bS,bW,bX,bY)}else{if(e==="contains"){return(bS.textContent||bS.innerText||bw([bS])||"").indexOf(bX[3])>=0}else{if(e==="not"){var bT=bX[3];for(var bV=0,bU=bT.length;bV=0)}}},ID:function(bR,e){return bR.nodeType===1&&bR.getAttribute("id")===e},TAG:function(bR,e){return(e==="*"&&bR.nodeType===1)||!!bR.nodeName&&bR.nodeName.toLowerCase()===e},CLASS:function(bR,e){return(" "+(bR.className||bR.getAttribute("class"))+" ").indexOf(e)>-1},ATTR:function(bV,bT){var bS=bT[1],e=by.attr?by.attr(bV,bS):bE.attrHandle[bS]?bE.attrHandle[bS](bV):bV[bS]!=null?bV[bS]:bV.getAttribute(bS),bW=e+"",bU=bT[2],bR=bT[4];return e==null?bU==="!=":!bU&&by.attr?e!=null:bU==="="?bW===bR:bU==="*="?bW.indexOf(bR)>=0:bU==="~="?(" "+bW+" ").indexOf(bR)>=0:!bR?bW&&e!==false:bU==="!="?bW!==bR:bU==="^="?bW.indexOf(bR)===0:bU==="$="?bW.substr(bW.length-bR.length)===bR:bU==="|="?bW===bR||bW.substr(0,bR.length+1)===bR+"-":false},POS:function(bU,bR,bS,bV){var e=bR[2],bT=bE.setFilters[e];if(bT){return bT(bU,bS,bR,bV)}}}};var bD=bE.match.POS,bx=function(bR,e){return"\\"+(e-0+1)};for(var bz in bE.match){bE.match[bz]=new RegExp(bE.match[bz].source+(/(?![^\[]*\])(?![^\(]*\))/.source));bE.leftMatch[bz]=new RegExp(/(^(?:.|\r|\n)*?)/.source+bE.match[bz].source.replace(/\\(\d+)/g,bx))}var bF=function(bR,e){bR=Array.prototype.slice.call(bR,0);if(e){e.push.apply(e,bR);return e}return bR};try{Array.prototype.slice.call(av.documentElement.childNodes,0)[0].nodeType}catch(bP){bF=function(bU,bT){var bS=0,bR=bT||[];if(bL.call(bU)==="[object Array]"){Array.prototype.push.apply(bR,bU)}else{if(typeof bU.length==="number"){for(var e=bU.length;bS";e.insertBefore(bR,e.firstChild);if(av.getElementById(bS)){bE.find.ID=function(bU,bV,bW){if(typeof bV.getElementById!=="undefined"&&!bW){var bT=bV.getElementById(bU[1]);return bT?bT.id===bU[1]||typeof bT.getAttributeNode!=="undefined"&&bT.getAttributeNode("id").nodeValue===bU[1]?[bT]:L:[]}};bE.filter.ID=function(bV,bT){var bU=typeof bV.getAttributeNode!=="undefined"&&bV.getAttributeNode("id");return bV.nodeType===1&&bU&&bU.nodeValue===bT}}e.removeChild(bR);e=bR=null})();(function(){var e=av.createElement("div");e.appendChild(av.createComment(""));if(e.getElementsByTagName("*").length>0){bE.find.TAG=function(bR,bV){var bU=bV.getElementsByTagName(bR[1]);if(bR[1]==="*"){var bT=[];for(var bS=0;bU[bS];bS++){if(bU[bS].nodeType===1){bT.push(bU[bS])}}bU=bT}return bU}}e.innerHTML="";if(e.firstChild&&typeof e.firstChild.getAttribute!=="undefined"&&e.firstChild.getAttribute("href")!=="#"){bE.attrHandle.href=function(bR){return bR.getAttribute("href",2)}}e=null})();if(av.querySelectorAll){(function(){var e=by,bT=av.createElement("div"),bS="__sizzle__";bT.innerHTML="

";if(bT.querySelectorAll&&bT.querySelectorAll(".TEST").length===0){return}by=function(b4,bV,bZ,b3){bV=bV||av;if(!b3&&!by.isXML(bV)){var b2=/^(\w+$)|^\.([\w\-]+$)|^#([\w\-]+$)/.exec(b4);if(b2&&(bV.nodeType===1||bV.nodeType===9)){if(b2[1]){return bF(bV.getElementsByTagName(b4),bZ)}else{if(b2[2]&&bE.find.CLASS&&bV.getElementsByClassName){return bF(bV.getElementsByClassName(b2[2]),bZ)}}}if(bV.nodeType===9){if(b4==="body"&&bV.body){return bF([bV.body],bZ)}else{if(b2&&b2[3]){var bY=bV.getElementById(b2[3]);if(bY&&bY.parentNode){if(bY.id===b2[3]){return bF([bY],bZ)}}else{return bF([],bZ)}}}try{return bF(bV.querySelectorAll(b4),bZ)}catch(b0){}}else{if(bV.nodeType===1&&bV.nodeName.toLowerCase()!=="object"){var bW=bV,bX=bV.getAttribute("id"),bU=bX||bS,b6=bV.parentNode,b5=/^\s*[+~]/.test(b4);if(!bX){bV.setAttribute("id",bU)}else{bU=bU.replace(/'/g,"\\$&")}if(b5&&b6){bV=bV.parentNode}try{if(!b5||b6){return bF(bV.querySelectorAll("[id='"+bU+"'] "+b4),bZ)}}catch(b1){}finally{if(!bX){bW.removeAttribute("id")}}}}}return e(b4,bV,bZ,b3)};for(var bR in e){by[bR]=e[bR]}bT=null})()}(function(){var e=av.documentElement,bS=e.matchesSelector||e.mozMatchesSelector||e.webkitMatchesSelector||e.msMatchesSelector;if(bS){var bU=!bS.call(av.createElement("div"),"div"),bR=false;try{bS.call(av.documentElement,"[test!='']:sizzle")}catch(bT){bR=true}by.matchesSelector=function(bW,bY){bY=bY.replace(/\=\s*([^'"\]]*)\s*\]/g,"='$1']");if(!by.isXML(bW)){try{if(bR||!bE.match.PSEUDO.test(bY)&&!/!=/.test(bY)){var bV=bS.call(bW,bY);if(bV||!bU||bW.document&&bW.document.nodeType!==11){return bV}}}catch(bX){}}return by(bY,null,null,[bW]).length>0}}})();(function(){var e=av.createElement("div");e.innerHTML="
";if(!e.getElementsByClassName||e.getElementsByClassName("e").length===0){return}e.lastChild.className="e";if(e.getElementsByClassName("e").length===1){return}bE.order.splice(1,0,"CLASS");bE.find.CLASS=function(bR,bS,bT){if(typeof bS.getElementsByClassName!=="undefined"&&!bT){return bS.getElementsByClassName(bR[1])}};e=null})();function bv(bR,bW,bV,bZ,bX,bY){for(var bT=0,bS=bZ.length;bT0){bU=e;break}}}e=e[bR]}bZ[bT]=bU}}}if(av.documentElement.contains){by.contains=function(bR,e){return bR!==e&&(bR.contains?bR.contains(e):true)}}else{if(av.documentElement.compareDocumentPosition){by.contains=function(bR,e){return !!(bR.compareDocumentPosition(e)&16)}}else{by.contains=function(){return false}}}by.isXML=function(e){var bR=(e?e.ownerDocument||e:0).documentElement;return bR?bR.nodeName!=="HTML":false};var bM=function(bS,e,bW){var bV,bX=[],bU="",bY=e.nodeType?[e]:e;while((bV=bE.match.PSEUDO.exec(bS))){bU+=bV[0];bS=bS.replace(bE.match.PSEUDO,"")}bS=bE.relative[bS]?bS+"*":bS;for(var bT=0,bR=bY.length;bT0){for(bB=bA;bB=0:b.filter(e,this).length>0:this.filter(e).length>0)},closest:function(by,bx){var bv=[],bw,e,bz=this[0];if(b.isArray(by)){var bB=1;while(bz&&bz.ownerDocument&&bz!==bx){for(bw=0;bw-1:b.find.matchesSelector(bz,by)){bv.push(bz);break}else{bz=bz.parentNode;if(!bz||!bz.ownerDocument||bz===bx||bz.nodeType===11){break}}}}bv=bv.length>1?b.unique(bv):bv;return this.pushStack(bv,"closest",by)},index:function(e){if(!e){return(this[0]&&this[0].parentNode)?this.prevAll().length:-1}if(typeof e==="string"){return b.inArray(this[0],b(e))}return b.inArray(e.jquery?e[0]:e,this)},add:function(e,bv){var bx=typeof e==="string"?b(e,bv):b.makeArray(e&&e.nodeType?[e]:e),bw=b.merge(this.get(),bx);return this.pushStack(C(bx[0])||C(bw[0])?bw:b.unique(bw))},andSelf:function(){return this.add(this.prevObject)}});function C(e){return !e||!e.parentNode||e.parentNode.nodeType===11}b.each({parent:function(bv){var e=bv.parentNode;return e&&e.nodeType!==11?e:null},parents:function(e){return b.dir(e,"parentNode")},parentsUntil:function(bv,e,bw){return b.dir(bv,"parentNode",bw)},next:function(e){return b.nth(e,2,"nextSibling")},prev:function(e){return b.nth(e,2,"previousSibling")},nextAll:function(e){return b.dir(e,"nextSibling")},prevAll:function(e){return b.dir(e,"previousSibling")},nextUntil:function(bv,e,bw){return b.dir(bv,"nextSibling",bw)},prevUntil:function(bv,e,bw){return b.dir(bv,"previousSibling",bw)},siblings:function(e){return b.sibling(e.parentNode.firstChild,e)},children:function(e){return b.sibling(e.firstChild)},contents:function(e){return b.nodeName(e,"iframe")?e.contentDocument||e.contentWindow.document:b.makeArray(e.childNodes)}},function(e,bv){b.fn[e]=function(by,bw){var bx=b.map(this,bv,by);if(!ab.test(e)){bw=by}if(bw&&typeof bw==="string"){bx=b.filter(bw,bx)}bx=this.length>1&&!ay[e]?b.unique(bx):bx;if((this.length>1||a9.test(bw))&&aq.test(e)){bx=bx.reverse()}return this.pushStack(bx,e,P.call(arguments).join(","))}});b.extend({filter:function(bw,e,bv){if(bv){bw=":not("+bw+")"}return e.length===1?b.find.matchesSelector(e[0],bw)?[e[0]]:[]:b.find.matches(bw,e)},dir:function(bw,bv,by){var e=[],bx=bw[bv];while(bx&&bx.nodeType!==9&&(by===L||bx.nodeType!==1||!b(bx).is(by))){if(bx.nodeType===1){e.push(bx)}bx=bx[bv]}return e},nth:function(by,e,bw,bx){e=e||1;var bv=0;for(;by;by=by[bw]){if(by.nodeType===1&&++bv===e){break}}return by},sibling:function(bw,bv){var e=[];for(;bw;bw=bw.nextSibling){if(bw.nodeType===1&&bw!==bv){e.push(bw)}}return e}});function aG(bx,bw,e){bw=bw||0;if(b.isFunction(bw)){return b.grep(bx,function(bz,by){var bA=!!bw.call(bz,by,bz);return bA===e})}else{if(bw.nodeType){return b.grep(bx,function(bz,by){return(bz===bw)===e})}else{if(typeof bw==="string"){var bv=b.grep(bx,function(by){return by.nodeType===1});if(bp.test(bw)){return b.filter(bw,bv,!e)}else{bw=b.filter(bw,bv)}}}}return b.grep(bx,function(bz,by){return(b.inArray(bz,bw)>=0)===e})}function a(e){var bw=aR.split("|"),bv=e.createDocumentFragment();if(bv.createElement){while(bw.length){bv.createElement(bw.pop())}}return bv}var aR="abbr|article|aside|audio|canvas|datalist|details|figcaption|figure|footer|header|hgroup|mark|meter|nav|output|progress|section|summary|time|video",ag=/ jQuery\d+="(?:\d+|null)"/g,ar=/^\s+/,R=/<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/ig,d=/<([\w:]+)/,w=/
",""],legend:[1,"
","
"],thead:[1,"
","
"],tr:[2,"","
"],td:[3,"","
"],col:[2,"","
"],area:[1,"",""],_default:[0,"",""]},ac=a(av);ax.optgroup=ax.option;ax.tbody=ax.tfoot=ax.colgroup=ax.caption=ax.thead;ax.th=ax.td;if(!b.support.htmlSerialize){ax._default=[1,"div
","
"]}b.fn.extend({text:function(e){if(b.isFunction(e)){return this.each(function(bw){var bv=b(this);bv.text(e.call(this,bw,bv.text()))})}if(typeof e!=="object"&&e!==L){return this.empty().append((this[0]&&this[0].ownerDocument||av).createTextNode(e))}return b.text(this)},wrapAll:function(e){if(b.isFunction(e)){return this.each(function(bw){b(this).wrapAll(e.call(this,bw))})}if(this[0]){var bv=b(e,this[0].ownerDocument).eq(0).clone(true);if(this[0].parentNode){bv.insertBefore(this[0])}bv.map(function(){var bw=this;while(bw.firstChild&&bw.firstChild.nodeType===1){bw=bw.firstChild}return bw}).append(this)}return this},wrapInner:function(e){if(b.isFunction(e)){return this.each(function(bv){b(this).wrapInner(e.call(this,bv))})}return this.each(function(){var bv=b(this),bw=bv.contents();if(bw.length){bw.wrapAll(e)}else{bv.append(e)}})},wrap:function(e){var bv=b.isFunction(e);return this.each(function(bw){b(this).wrapAll(bv?e.call(this,bw):e)})},unwrap:function(){return this.parent().each(function(){if(!b.nodeName(this,"body")){b(this).replaceWith(this.childNodes)}}).end()},append:function(){return this.domManip(arguments,true,function(e){if(this.nodeType===1){this.appendChild(e)}})},prepend:function(){return this.domManip(arguments,true,function(e){if(this.nodeType===1){this.insertBefore(e,this.firstChild)}})},before:function(){if(this[0]&&this[0].parentNode){return this.domManip(arguments,false,function(bv){this.parentNode.insertBefore(bv,this)})}else{if(arguments.length){var e=b.clean(arguments);e.push.apply(e,this.toArray());return this.pushStack(e,"before",arguments)}}},after:function(){if(this[0]&&this[0].parentNode){return this.domManip(arguments,false,function(bv){this.parentNode.insertBefore(bv,this.nextSibling)})}else{if(arguments.length){var e=this.pushStack(this,"after",arguments);e.push.apply(e,b.clean(arguments));return e}}},remove:function(e,bx){for(var bv=0,bw;(bw=this[bv])!=null;bv++){if(!e||b.filter(e,[bw]).length){if(!bx&&bw.nodeType===1){b.cleanData(bw.getElementsByTagName("*"));b.cleanData([bw])}if(bw.parentNode){bw.parentNode.removeChild(bw)}}}return this},empty:function(){for(var e=0,bv;(bv=this[e])!=null;e++){if(bv.nodeType===1){b.cleanData(bv.getElementsByTagName("*"))}while(bv.firstChild){bv.removeChild(bv.firstChild)}}return this},clone:function(bv,e){bv=bv==null?false:bv;e=e==null?bv:e;return this.map(function(){return b.clone(this,bv,e)})},html:function(bx){if(bx===L){return this[0]&&this[0].nodeType===1?this[0].innerHTML.replace(ag,""):null}else{if(typeof bx==="string"&&!ae.test(bx)&&(b.support.leadingWhitespace||!ar.test(bx))&&!ax[(d.exec(bx)||["",""])[1].toLowerCase()]){bx=bx.replace(R,"<$1>");try{for(var bw=0,bv=this.length;bw1&&bw0?this.clone(true):this).get();b(bC[bA])[bv](by);bz=bz.concat(by)}return this.pushStack(bz,e,bC.selector)}}});function bg(e){if(typeof e.getElementsByTagName!=="undefined"){return e.getElementsByTagName("*")}else{if(typeof e.querySelectorAll!=="undefined"){return e.querySelectorAll("*")}else{return[]}}}function az(e){if(e.type==="checkbox"||e.type==="radio"){e.defaultChecked=e.checked}}function E(e){var bv=(e.nodeName||"").toLowerCase();if(bv==="input"){az(e)}else{if(bv!=="script"&&typeof e.getElementsByTagName!=="undefined"){b.grep(e.getElementsByTagName("input"),az)}}}function al(e){var bv=av.createElement("div");ac.appendChild(bv);bv.innerHTML=e.outerHTML;return bv.firstChild}b.extend({clone:function(by,bA,bw){var e,bv,bx,bz=b.support.html5Clone||!ah.test("<"+by.nodeName)?by.cloneNode(true):al(by);if((!b.support.noCloneEvent||!b.support.noCloneChecked)&&(by.nodeType===1||by.nodeType===11)&&!b.isXMLDoc(by)){ai(by,bz);e=bg(by);bv=bg(bz);for(bx=0;e[bx];++bx){if(bv[bx]){ai(e[bx],bv[bx])}}}if(bA){t(by,bz);if(bw){e=bg(by);bv=bg(bz);for(bx=0;e[bx];++bx){t(e[bx],bv[bx])}}}e=bv=null;return bz},clean:function(bw,by,bH,bA){var bF;by=by||av;if(typeof by.createElement==="undefined"){by=by.ownerDocument||by[0]&&by[0].ownerDocument||av}var bI=[],bB;for(var bE=0,bz;(bz=bw[bE])!=null;bE++){if(typeof bz==="number"){bz+=""}if(!bz){continue}if(typeof bz==="string"){if(!W.test(bz)){bz=by.createTextNode(bz)}else{bz=bz.replace(R,"<$1>");var bK=(d.exec(bz)||["",""])[1].toLowerCase(),bx=ax[bK]||ax._default,bD=bx[0],bv=by.createElement("div");if(by===av){ac.appendChild(bv)}else{a(by).appendChild(bv)}bv.innerHTML=bx[1]+bz+bx[2];while(bD--){bv=bv.lastChild}if(!b.support.tbody){var e=w.test(bz),bC=bK==="table"&&!e?bv.firstChild&&bv.firstChild.childNodes:bx[1]===""&&!e?bv.childNodes:[];for(bB=bC.length-1;bB>=0;--bB){if(b.nodeName(bC[bB],"tbody")&&!bC[bB].childNodes.length){bC[bB].parentNode.removeChild(bC[bB])}}}if(!b.support.leadingWhitespace&&ar.test(bz)){bv.insertBefore(by.createTextNode(ar.exec(bz)[0]),bv.firstChild)}bz=bv.childNodes}}var bG;if(!b.support.appendChecked){if(bz[0]&&typeof(bG=bz.length)==="number"){for(bB=0;bB=0){return bx+"px"}}else{return bx}}}});if(!b.support.opacity){b.cssHooks.opacity={get:function(bv,e){return au.test((e&&bv.currentStyle?bv.currentStyle.filter:bv.style.filter)||"")?(parseFloat(RegExp.$1)/100)+"":e?"1":""},set:function(by,bz){var bx=by.style,bv=by.currentStyle,e=b.isNumeric(bz)?"alpha(opacity="+bz*100+")":"",bw=bv&&bv.filter||bx.filter||"";bx.zoom=1;if(bz>=1&&b.trim(bw.replace(ak,""))===""){bx.removeAttribute("filter");if(bv&&!bv.filter){return}}bx.filter=ak.test(bw)?bw.replace(ak,e):bw+" "+e}}}b(function(){if(!b.support.reliableMarginRight){b.cssHooks.marginRight={get:function(bw,bv){var e;b.swap(bw,{display:"inline-block"},function(){if(bv){e=Z(bw,"margin-right","marginRight")}else{e=bw.style.marginRight}});return e}}}});if(av.defaultView&&av.defaultView.getComputedStyle){aI=function(by,bw){var bv,bx,e;bw=bw.replace(z,"-$1").toLowerCase();if((bx=by.ownerDocument.defaultView)&&(e=bx.getComputedStyle(by,null))){bv=e.getPropertyValue(bw);if(bv===""&&!b.contains(by.ownerDocument.documentElement,by)){bv=b.style(by,bw)}}return bv}}if(av.documentElement.currentStyle){aX=function(bz,bw){var bA,e,by,bv=bz.currentStyle&&bz.currentStyle[bw],bx=bz.style;if(bv===null&&bx&&(by=bx[bw])){bv=by}if(!bc.test(bv)&&bn.test(bv)){bA=bx.left;e=bz.runtimeStyle&&bz.runtimeStyle.left;if(e){bz.runtimeStyle.left=bz.currentStyle.left}bx.left=bw==="fontSize"?"1em":(bv||0);bv=bx.pixelLeft+"px";bx.left=bA;if(e){bz.runtimeStyle.left=e}}return bv===""?"auto":bv}}Z=aI||aX;function p(by,bw,bv){var bA=bw==="width"?by.offsetWidth:by.offsetHeight,bz=bw==="width"?an:a1,bx=0,e=bz.length;if(bA>0){if(bv!=="border"){for(;bx)<[^<]*)*<\/script>/gi,q=/^(?:select|textarea)/i,h=/\s+/,br=/([?&])_=[^&]*/,K=/^([\w\+\.\-]+:)(?:\/\/([^\/?#:]*)(?::(\d+))?)?/,A=b.fn.load,aa={},r={},aE,s,aV=["*/"]+["*"];try{aE=bl.href}catch(aw){aE=av.createElement("a");aE.href="";aE=aE.href}s=K.exec(aE.toLowerCase())||[];function f(e){return function(by,bA){if(typeof by!=="string"){bA=by;by="*"}if(b.isFunction(bA)){var bx=by.toLowerCase().split(h),bw=0,bz=bx.length,bv,bB,bC;for(;bw=0){var e=bw.slice(by,bw.length);bw=bw.slice(0,by)}var bx="GET";if(bz){if(b.isFunction(bz)){bA=bz;bz=L}else{if(typeof bz==="object"){bz=b.param(bz,b.ajaxSettings.traditional);bx="POST"}}}var bv=this;b.ajax({url:bw,type:bx,dataType:"html",data:bz,complete:function(bC,bB,bD){bD=bC.responseText;if(bC.isResolved()){bC.done(function(bE){bD=bE});bv.html(e?b("
").append(bD.replace(a6,"")).find(e):bD)}if(bA){bv.each(bA,[bD,bB,bC])}}});return this},serialize:function(){return b.param(this.serializeArray())},serializeArray:function(){return this.map(function(){return this.elements?b.makeArray(this.elements):this}).filter(function(){return this.name&&!this.disabled&&(this.checked||q.test(this.nodeName)||aZ.test(this.type))}).map(function(e,bv){var bw=b(this).val();return bw==null?null:b.isArray(bw)?b.map(bw,function(by,bx){return{name:bv.name,value:by.replace(bs,"\r\n")}}):{name:bv.name,value:bw.replace(bs,"\r\n")}}).get()}});b.each("ajaxStart ajaxStop ajaxComplete ajaxError ajaxSuccess ajaxSend".split(" "),function(e,bv){b.fn[bv]=function(bw){return this.on(bv,bw)}});b.each(["get","post"],function(e,bv){b[bv]=function(bw,by,bz,bx){if(b.isFunction(by)){bx=bx||bz;bz=by;by=L}return b.ajax({type:bv,url:bw,data:by,success:bz,dataType:bx})}});b.extend({getScript:function(e,bv){return b.get(e,L,bv,"script")},getJSON:function(e,bv,bw){return b.get(e,bv,bw,"json")},ajaxSetup:function(bv,e){if(e){am(bv,b.ajaxSettings)}else{e=bv;bv=b.ajaxSettings}am(bv,e);return bv},ajaxSettings:{url:aE,isLocal:aM.test(s[1]),global:true,type:"GET",contentType:"application/x-www-form-urlencoded",processData:true,async:true,accepts:{xml:"application/xml, text/xml",html:"text/html",text:"text/plain",json:"application/json, text/javascript","*":aV},contents:{xml:/xml/,html:/html/,json:/json/},responseFields:{xml:"responseXML",text:"responseText"},converters:{"* text":bb.String,"text html":true,"text json":b.parseJSON,"text xml":b.parseXML},flatOptions:{context:true,url:true}},ajaxPrefilter:f(aa),ajaxTransport:f(r),ajax:function(bz,bx){if(typeof bz==="object"){bx=bz;bz=L}bx=bx||{};var bD=b.ajaxSetup({},bx),bS=bD.context||bD,bG=bS!==bD&&(bS.nodeType||bS instanceof b)?b(bS):b.event,bR=b.Deferred(),bN=b.Callbacks("once memory"),bB=bD.statusCode||{},bC,bH={},bO={},bQ,by,bL,bE,bI,bA=0,bw,bK,bJ={readyState:0,setRequestHeader:function(bT,bU){if(!bA){var e=bT.toLowerCase();bT=bO[e]=bO[e]||bT;bH[bT]=bU}return this},getAllResponseHeaders:function(){return bA===2?bQ:null},getResponseHeader:function(bT){var e;if(bA===2){if(!by){by={};while((e=aD.exec(bQ))){by[e[1].toLowerCase()]=e[2]}}e=by[bT.toLowerCase()]}return e===L?null:e},overrideMimeType:function(e){if(!bA){bD.mimeType=e}return this},abort:function(e){e=e||"abort";if(bL){bL.abort(e)}bF(0,e);return this}};function bF(bZ,bU,b0,bW){if(bA===2){return}bA=2;if(bE){clearTimeout(bE)}bL=L;bQ=bW||"";bJ.readyState=bZ>0?4:0;var bT,b4,b3,bX=bU,bY=b0?bj(bD,bJ,b0):L,bV,b2;if(bZ>=200&&bZ<300||bZ===304){if(bD.ifModified){if((bV=bJ.getResponseHeader("Last-Modified"))){b.lastModified[bC]=bV}if((b2=bJ.getResponseHeader("Etag"))){b.etag[bC]=b2}}if(bZ===304){bX="notmodified";bT=true}else{try{b4=G(bD,bY);bX="success";bT=true}catch(b1){bX="parsererror";b3=b1}}}else{b3=bX;if(!bX||bZ){bX="error";if(bZ<0){bZ=0}}}bJ.status=bZ;bJ.statusText=""+(bU||bX);if(bT){bR.resolveWith(bS,[b4,bX,bJ])}else{bR.rejectWith(bS,[bJ,bX,b3])}bJ.statusCode(bB);bB=L;if(bw){bG.trigger("ajax"+(bT?"Success":"Error"),[bJ,bD,bT?b4:b3])}bN.fireWith(bS,[bJ,bX]);if(bw){bG.trigger("ajaxComplete",[bJ,bD]);if(!(--b.active)){b.event.trigger("ajaxStop")}}}bR.promise(bJ);bJ.success=bJ.done;bJ.error=bJ.fail;bJ.complete=bN.add;bJ.statusCode=function(bT){if(bT){var e;if(bA<2){for(e in bT){bB[e]=[bB[e],bT[e]]}}else{e=bT[bJ.status];bJ.then(e,e)}}return this};bD.url=((bz||bD.url)+"").replace(bq,"").replace(c,s[1]+"//");bD.dataTypes=b.trim(bD.dataType||"*").toLowerCase().split(h);if(bD.crossDomain==null){bI=K.exec(bD.url.toLowerCase());bD.crossDomain=!!(bI&&(bI[1]!=s[1]||bI[2]!=s[2]||(bI[3]||(bI[1]==="http:"?80:443))!=(s[3]||(s[1]==="http:"?80:443))))}if(bD.data&&bD.processData&&typeof bD.data!=="string"){bD.data=b.param(bD.data,bD.traditional)}aW(aa,bD,bx,bJ);if(bA===2){return false}bw=bD.global;bD.type=bD.type.toUpperCase();bD.hasContent=!aQ.test(bD.type);if(bw&&b.active++===0){b.event.trigger("ajaxStart")}if(!bD.hasContent){if(bD.data){bD.url+=(M.test(bD.url)?"&":"?")+bD.data;delete bD.data}bC=bD.url;if(bD.cache===false){var bv=b.now(),bP=bD.url.replace(br,"$1_="+bv);bD.url=bP+((bP===bD.url)?(M.test(bD.url)?"&":"?")+"_="+bv:"")}}if(bD.data&&bD.hasContent&&bD.contentType!==false||bx.contentType){bJ.setRequestHeader("Content-Type",bD.contentType)}if(bD.ifModified){bC=bC||bD.url;if(b.lastModified[bC]){bJ.setRequestHeader("If-Modified-Since",b.lastModified[bC])}if(b.etag[bC]){bJ.setRequestHeader("If-None-Match",b.etag[bC])}}bJ.setRequestHeader("Accept",bD.dataTypes[0]&&bD.accepts[bD.dataTypes[0]]?bD.accepts[bD.dataTypes[0]]+(bD.dataTypes[0]!=="*"?", "+aV+"; q=0.01":""):bD.accepts["*"]);for(bK in bD.headers){bJ.setRequestHeader(bK,bD.headers[bK])}if(bD.beforeSend&&(bD.beforeSend.call(bS,bJ,bD)===false||bA===2)){bJ.abort();return false}for(bK in {success:1,error:1,complete:1}){bJ[bK](bD[bK])}bL=aW(r,bD,bx,bJ);if(!bL){bF(-1,"No Transport")}else{bJ.readyState=1;if(bw){bG.trigger("ajaxSend",[bJ,bD])}if(bD.async&&bD.timeout>0){bE=setTimeout(function(){bJ.abort("timeout")},bD.timeout)}try{bA=1;bL.send(bH,bF)}catch(bM){if(bA<2){bF(-1,bM)}else{throw bM}}}return bJ},param:function(e,bw){var bv=[],by=function(bz,bA){bA=b.isFunction(bA)?bA():bA;bv[bv.length]=encodeURIComponent(bz)+"="+encodeURIComponent(bA)};if(bw===L){bw=b.ajaxSettings.traditional}if(b.isArray(e)||(e.jquery&&!b.isPlainObject(e))){b.each(e,function(){by(this.name,this.value)})}else{for(var bx in e){v(bx,e[bx],bw,by)}}return bv.join("&").replace(k,"+")}});function v(bw,by,bv,bx){if(b.isArray(by)){b.each(by,function(bA,bz){if(bv||ap.test(bw)){bx(bw,bz)}else{v(bw+"["+(typeof bz==="object"||b.isArray(bz)?bA:"")+"]",bz,bv,bx)}})}else{if(!bv&&by!=null&&typeof by==="object"){for(var e in by){v(bw+"["+e+"]",by[e],bv,bx)}}else{bx(bw,by)}}}b.extend({active:0,lastModified:{},etag:{}});function bj(bD,bC,bz){var bv=bD.contents,bB=bD.dataTypes,bw=bD.responseFields,by,bA,bx,e;for(bA in bw){if(bA in bz){bC[bw[bA]]=bz[bA]}}while(bB[0]==="*"){bB.shift();if(by===L){by=bD.mimeType||bC.getResponseHeader("content-type")}}if(by){for(bA in bv){if(bv[bA]&&bv[bA].test(by)){bB.unshift(bA);break}}}if(bB[0] in bz){bx=bB[0]}else{for(bA in bz){if(!bB[0]||bD.converters[bA+" "+bB[0]]){bx=bA;break}if(!e){e=bA}}bx=bx||e}if(bx){if(bx!==bB[0]){bB.unshift(bx)}return bz[bx]}}function G(bH,bz){if(bH.dataFilter){bz=bH.dataFilter(bz,bH.dataType)}var bD=bH.dataTypes,bG={},bA,bE,bw=bD.length,bB,bC=bD[0],bx,by,bF,bv,e;for(bA=1;bA=bw.duration+this.startTime){this.now=this.end;this.pos=this.state=1;this.update();bw.animatedProperties[this.prop]=true;for(bA in bw.animatedProperties){if(bw.animatedProperties[bA]!==true){e=false}}if(e){if(bw.overflow!=null&&!b.support.shrinkWrapBlocks){b.each(["","X","Y"],function(bC,bD){bz.style["overflow"+bD]=bw.overflow[bC]})}if(bw.hide){b(bz).hide()}if(bw.hide||bw.show){for(bA in bw.animatedProperties){b.style(bz,bA,bw.orig[bA]);b.removeData(bz,"fxshow"+bA,true);b.removeData(bz,"toggle"+bA,true)}}bv=bw.complete;if(bv){bw.complete=false;bv.call(bz)}}return false}else{if(bw.duration==Infinity){this.now=bx}else{bB=bx-this.startTime;this.state=bB/bw.duration;this.pos=b.easing[bw.animatedProperties[this.prop]](this.state,bB,0,1,bw.duration);this.now=this.start+((this.end-this.start)*this.pos)}this.update()}return true}};b.extend(b.fx,{tick:function(){var bw,bv=b.timers,e=0;for(;e").appendTo(e),bw=bv.css("display");bv.remove();if(bw==="none"||bw===""){if(!a8){a8=av.createElement("iframe");a8.frameBorder=a8.width=a8.height=0}e.appendChild(a8);if(!m||!a8.createElement){m=(a8.contentWindow||a8.contentDocument).document;m.write((av.compatMode==="CSS1Compat"?"":"")+"");m.close()}bv=m.createElement(bx);m.body.appendChild(bv);bw=b.css(bv,"display");e.removeChild(a8)}Q[bx]=bw}return Q[bx]}var V=/^t(?:able|d|h)$/i,ad=/^(?:body|html)$/i;if("getBoundingClientRect" in av.documentElement){b.fn.offset=function(bI){var by=this[0],bB;if(bI){return this.each(function(e){b.offset.setOffset(this,bI,e)})}if(!by||!by.ownerDocument){return null}if(by===by.ownerDocument.body){return b.offset.bodyOffset(by)}try{bB=by.getBoundingClientRect()}catch(bF){}var bH=by.ownerDocument,bw=bH.documentElement;if(!bB||!b.contains(bw,by)){return bB?{top:bB.top,left:bB.left}:{top:0,left:0}}var bC=bH.body,bD=aK(bH),bA=bw.clientTop||bC.clientTop||0,bE=bw.clientLeft||bC.clientLeft||0,bv=bD.pageYOffset||b.support.boxModel&&bw.scrollTop||bC.scrollTop,bz=bD.pageXOffset||b.support.boxModel&&bw.scrollLeft||bC.scrollLeft,bG=bB.top+bv-bA,bx=bB.left+bz-bE;return{top:bG,left:bx}}}else{b.fn.offset=function(bF){var bz=this[0];if(bF){return this.each(function(bG){b.offset.setOffset(this,bF,bG)})}if(!bz||!bz.ownerDocument){return null}if(bz===bz.ownerDocument.body){return b.offset.bodyOffset(bz)}var bC,bw=bz.offsetParent,bv=bz,bE=bz.ownerDocument,bx=bE.documentElement,bA=bE.body,bB=bE.defaultView,e=bB?bB.getComputedStyle(bz,null):bz.currentStyle,bD=bz.offsetTop,by=bz.offsetLeft;while((bz=bz.parentNode)&&bz!==bA&&bz!==bx){if(b.support.fixedPosition&&e.position==="fixed"){break}bC=bB?bB.getComputedStyle(bz,null):bz.currentStyle;bD-=bz.scrollTop;by-=bz.scrollLeft;if(bz===bw){bD+=bz.offsetTop;by+=bz.offsetLeft;if(b.support.doesNotAddBorder&&!(b.support.doesAddBorderForTableAndCells&&V.test(bz.nodeName))){bD+=parseFloat(bC.borderTopWidth)||0;by+=parseFloat(bC.borderLeftWidth)||0}bv=bw;bw=bz.offsetParent}if(b.support.subtractsBorderForOverflowNotVisible&&bC.overflow!=="visible"){bD+=parseFloat(bC.borderTopWidth)||0;by+=parseFloat(bC.borderLeftWidth)||0}e=bC}if(e.position==="relative"||e.position==="static"){bD+=bA.offsetTop;by+=bA.offsetLeft}if(b.support.fixedPosition&&e.position==="fixed"){bD+=Math.max(bx.scrollTop,bA.scrollTop);by+=Math.max(bx.scrollLeft,bA.scrollLeft)}return{top:bD,left:by}}}b.offset={bodyOffset:function(e){var bw=e.offsetTop,bv=e.offsetLeft;if(b.support.doesNotIncludeMarginInBodyOffset){bw+=parseFloat(b.css(e,"marginTop"))||0;bv+=parseFloat(b.css(e,"marginLeft"))||0}return{top:bw,left:bv}},setOffset:function(bx,bG,bA){var bB=b.css(bx,"position");if(bB==="static"){bx.style.position="relative"}var bz=b(bx),bv=bz.offset(),e=b.css(bx,"top"),bE=b.css(bx,"left"),bF=(bB==="absolute"||bB==="fixed")&&b.inArray("auto",[e,bE])>-1,bD={},bC={},bw,by;if(bF){bC=bz.position();bw=bC.top;by=bC.left}else{bw=parseFloat(e)||0;by=parseFloat(bE)||0}if(b.isFunction(bG)){bG=bG.call(bx,bA,bv)}if(bG.top!=null){bD.top=(bG.top-bv.top)+bw}if(bG.left!=null){bD.left=(bG.left-bv.left)+by}if("using" in bG){bG.using.call(bx,bD)}else{bz.css(bD)}}};b.fn.extend({position:function(){if(!this[0]){return null}var bw=this[0],bv=this.offsetParent(),bx=this.offset(),e=ad.test(bv[0].nodeName)?{top:0,left:0}:bv.offset();bx.top-=parseFloat(b.css(bw,"marginTop"))||0;bx.left-=parseFloat(b.css(bw,"marginLeft"))||0;e.top+=parseFloat(b.css(bv[0],"borderTopWidth"))||0;e.left+=parseFloat(b.css(bv[0],"borderLeftWidth"))||0;return{top:bx.top-e.top,left:bx.left-e.left}},offsetParent:function(){return this.map(function(){var e=this.offsetParent||av.body;while(e&&(!ad.test(e.nodeName)&&b.css(e,"position")==="static")){e=e.offsetParent}return e})}});b.each(["Left","Top"],function(bv,e){var bw="scroll"+e;b.fn[bw]=function(bz){var bx,by;if(bz===L){bx=this[0];if(!bx){return null}by=aK(bx);return by?("pageXOffset" in by)?by[bv?"pageYOffset":"pageXOffset"]:b.support.boxModel&&by.document.documentElement[bw]||by.document.body[bw]:bx[bw]}return this.each(function(){by=aK(this);if(by){by.scrollTo(!bv?bz:b(by).scrollLeft(),bv?bz:b(by).scrollTop())}else{this[bw]=bz}})}});function aK(e){return b.isWindow(e)?e:e.nodeType===9?e.defaultView||e.parentWindow:false}b.each(["Height","Width"],function(bv,e){var bw=e.toLowerCase();b.fn["inner"+e]=function(){var bx=this[0];return bx?bx.style?parseFloat(b.css(bx,bw,"padding")):this[bw]():null};b.fn["outer"+e]=function(by){var bx=this[0];return bx?bx.style?parseFloat(b.css(bx,bw,by?"margin":"border")):this[bw]():null};b.fn[bw]=function(bz){var bA=this[0];if(!bA){return bz==null?null:this}if(b.isFunction(bz)){return this.each(function(bE){var bD=b(this);bD[bw](bz.call(this,bE,bD[bw]()))})}if(b.isWindow(bA)){var bB=bA.document.documentElement["client"+e],bx=bA.document.body;return bA.document.compatMode==="CSS1Compat"&&bB||bx&&bx["client"+e]||bB}else{if(bA.nodeType===9){return Math.max(bA.documentElement["client"+e],bA.body["scroll"+e],bA.documentElement["scroll"+e],bA.body["offset"+e],bA.documentElement["offset"+e])}else{if(bz===L){var bC=b.css(bA,bw),by=parseFloat(bC);return b.isNumeric(by)?by:bC}else{return this.css(bw,typeof bz==="string"?bz:bz+"px")}}}}});bb.jQuery=bb.$=b;if(typeof define==="function"&&define.amd&&define.amd.jQuery){define("jquery",[],function(){return b})}})(window);/*! * jQuery UI 1.8.18 * * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about) @@ -29,7 +29,7 @@ * * http://docs.jquery.com/UI */ -(function(a,d){a.ui=a.ui||{};if(a.ui.version){return}a.extend(a.ui,{version:"1.8.18",keyCode:{ALT:18,BACKSPACE:8,CAPS_LOCK:20,COMMA:188,COMMAND:91,COMMAND_LEFT:91,COMMAND_RIGHT:93,CONTROL:17,DELETE:46,DOWN:40,END:35,ENTER:13,ESCAPE:27,HOME:36,INSERT:45,LEFT:37,MENU:93,NUMPAD_ADD:107,NUMPAD_DECIMAL:110,NUMPAD_DIVIDE:111,NUMPAD_ENTER:108,NUMPAD_MULTIPLY:106,NUMPAD_SUBTRACT:109,PAGE_DOWN:34,PAGE_UP:33,PERIOD:190,RIGHT:39,SHIFT:16,SPACE:32,TAB:9,UP:38,WINDOWS:91}});a.fn.extend({propAttr:a.fn.prop||a.fn.attr,_focus:a.fn.focus,focus:function(e,f){return typeof e==="number"?this.each(function(){var g=this;setTimeout(function(){a(g).focus();if(f){f.call(g)}},e)}):this._focus.apply(this,arguments)},scrollParent:function(){var e;if((a.browser.msie&&(/(static|relative)/).test(this.css("position")))||(/absolute/).test(this.css("position"))){e=this.parents().filter(function(){return(/(relative|absolute|fixed)/).test(a.curCSS(this,"position",1))&&(/(auto|scroll)/).test(a.curCSS(this,"overflow",1)+a.curCSS(this,"overflow-y",1)+a.curCSS(this,"overflow-x",1))}).eq(0)}else{e=this.parents().filter(function(){return(/(auto|scroll)/).test(a.curCSS(this,"overflow",1)+a.curCSS(this,"overflow-y",1)+a.curCSS(this,"overflow-x",1))}).eq(0)}return(/fixed/).test(this.css("position"))||!e.length?a(document):e},zIndex:function(h){if(h!==d){return this.css("zIndex",h)}if(this.length){var f=a(this[0]),e,g;while(f.length&&f[0]!==document){e=f.css("position");if(e==="absolute"||e==="relative"||e==="fixed"){g=parseInt(f.css("zIndex"),10);if(!isNaN(g)&&g!==0){return g}}f=f.parent()}}return 0},disableSelection:function(){return this.bind((a.support.selectstart?"selectstart":"mousedown")+".ui-disableSelection",function(e){e.preventDefault()})},enableSelection:function(){return this.unbind(".ui-disableSelection")}});a.each(["Width","Height"],function(g,e){var f=e==="Width"?["Left","Right"]:["Top","Bottom"],h=e.toLowerCase(),k={innerWidth:a.fn.innerWidth,innerHeight:a.fn.innerHeight,outerWidth:a.fn.outerWidth,outerHeight:a.fn.outerHeight};function j(m,l,i,n){a.each(f,function(){l-=parseFloat(a.curCSS(m,"padding"+this,true))||0;if(i){l-=parseFloat(a.curCSS(m,"border"+this+"Width",true))||0}if(n){l-=parseFloat(a.curCSS(m,"margin"+this,true))||0}});return l}a.fn["inner"+e]=function(i){if(i===d){return k["inner"+e].call(this)}return this.each(function(){a(this).css(h,j(this,i)+"px")})};a.fn["outer"+e]=function(i,l){if(typeof i!=="number"){return k["outer"+e].call(this,i)}return this.each(function(){a(this).css(h,j(this,i,true,l)+"px")})}});function c(g,e){var j=g.nodeName.toLowerCase();if("area"===j){var i=g.parentNode,h=i.name,f;if(!g.href||!h||i.nodeName.toLowerCase()!=="map"){return false}f=a("img[usemap=#"+h+"]")[0];return !!f&&b(f)}return(/input|select|textarea|button|object/.test(j)?!g.disabled:"a"==j?g.href||e:e)&&b(g)}function b(e){return !a(e).parents().andSelf().filter(function(){return a.curCSS(this,"visibility")==="hidden"||a.expr.filters.hidden(this)}).length}a.extend(a.expr[":"],{data:function(g,f,e){return !!a.data(g,e[3])},focusable:function(e){return c(e,!isNaN(a.attr(e,"tabindex")))},tabbable:function(g){var e=a.attr(g,"tabindex"),f=isNaN(e);return(f||e>=0)&&c(g,!f)}});a(function(){var e=document.body,f=e.appendChild(f=document.createElement("div"));f.offsetHeight;a.extend(f.style,{minHeight:"100px",height:"auto",padding:0,borderWidth:0});a.support.minHeight=f.offsetHeight===100;a.support.selectstart="onselectstart" in f;e.removeChild(f).style.display="none"});a.extend(a.ui,{plugin:{add:function(f,g,j){var h=a.ui[f].prototype;for(var e in j){h.plugins[e]=h.plugins[e]||[];h.plugins[e].push([g,j[e]])}},call:function(e,g,f){var j=e.plugins[g];if(!j||!e.element[0].parentNode){return}for(var h=0;h0){return true}h[e]=1;g=(h[e]>0);h[e]=0;return g},isOverAxis:function(f,e,g){return(f>e)&&(f<(e+g))},isOver:function(j,f,i,h,e,g){return a.ui.isOverAxis(j,i,e)&&a.ui.isOverAxis(f,h,g)}})})(jQuery);/* +(function(a,d){a.ui=a.ui||{};if(a.ui.version){return}a.extend(a.ui,{version:"1.8.18",keyCode:{ALT:18,BACKSPACE:8,CAPS_LOCK:20,COMMA:188,COMMAND:91,COMMAND_LEFT:91,COMMAND_RIGHT:93,CONTROL:17,DELETE:46,DOWN:40,END:35,ENTER:13,ESCAPE:27,HOME:36,INSERT:45,LEFT:37,MENU:93,NUMPAD_ADD:107,NUMPAD_DECIMAL:110,NUMPAD_DIVIDE:111,NUMPAD_ENTER:108,NUMPAD_MULTIPLY:106,NUMPAD_SUBTRACT:109,PAGE_DOWN:34,PAGE_UP:33,PERIOD:190,RIGHT:39,SHIFT:16,SPACE:32,TAB:9,UP:38,WINDOWS:91}});a.fn.extend({propAttr:a.fn.prop||a.fn.attr,_focus:a.fn.focus,focus:function(e,f){return typeof e==="number"?this.each(function(){var g=this;setTimeout(function(){a(g).focus();if(f){f.call(g)}},e)}):this._focus.apply(this,arguments)},scrollParent:function(){var e;if((a.browser.msie&&(/(static|relative)/).test(this.css("position")))||(/absolute/).test(this.css("position"))){e=this.parents().filter(function(){return(/(relative|absolute|fixed)/).test(a.curCSS(this,"position",1))&&(/(auto|scroll)/).test(a.curCSS(this,"overflow",1)+a.curCSS(this,"overflow-y",1)+a.curCSS(this,"overflow-x",1))}).eq(0)}else{e=this.parents().filter(function(){return(/(auto|scroll)/).test(a.curCSS(this,"overflow",1)+a.curCSS(this,"overflow-y",1)+a.curCSS(this,"overflow-x",1))}).eq(0)}return(/fixed/).test(this.css("position"))||!e.length?a(document):e},zIndex:function(h){if(h!==d){return this.css("zIndex",h)}if(this.length){var f=a(this[0]),e,g;while(f.length&&f[0]!==document){e=f.css("position");if(e==="absolute"||e==="relative"||e==="fixed"){g=parseInt(f.css("zIndex"),10);if(!isNaN(g)&&g!==0){return g}}f=f.parent()}}return 0},disableSelection:function(){return this.bind((a.support.selectstart?"selectstart":"mousedown")+".ui-disableSelection",function(e){e.preventDefault()})},enableSelection:function(){return this.unbind(".ui-disableSelection")}});a.each(["Width","Height"],function(g,e){var f=e==="Width"?["Left","Right"]:["Top","Bottom"],h=e.toLowerCase(),k={innerWidth:a.fn.innerWidth,innerHeight:a.fn.innerHeight,outerWidth:a.fn.outerWidth,outerHeight:a.fn.outerHeight};function j(m,l,i,n){a.each(f,function(){l-=parseFloat(a.curCSS(m,"padding"+this,true))||0;if(i){l-=parseFloat(a.curCSS(m,"border"+this+"Width",true))||0}if(n){l-=parseFloat(a.curCSS(m,"margin"+this,true))||0}});return l}a.fn["inner"+e]=function(i){if(i===d){return k["inner"+e].call(this)}return this.each(function(){a(this).css(h,j(this,i)+"px")})};a.fn["outer"+e]=function(i,l){if(typeof i!=="number"){return k["outer"+e].call(this,i)}return this.each(function(){a(this).css(h,j(this,i,true,l)+"px")})}});function c(g,e){var j=g.nodeName.toLowerCase();if("area"===j){var i=g.parentNode,h=i.name,f;if(!g.href||!h||i.nodeName.toLowerCase()!=="map"){return false}f=a("img[usemap=#"+h+"]")[0];return !!f&&b(f)}return(/input|select|textarea|button|object/.test(j)?!g.disabled:"a"==j?g.href||e:e)&&b(g)}function b(e){return !a(e).parents().andSelf().filter(function(){return a.curCSS(this,"visibility")==="hidden"||a.expr.filters.hidden(this)}).length}a.extend(a.expr[":"],{data:function(g,f,e){return !!a.data(g,e[3])},focusable:function(e){return c(e,!isNaN(a.attr(e,"tabindex")))},tabbable:function(g){var e=a.attr(g,"tabindex"),f=isNaN(e);return(f||e>=0)&&c(g,!f)}});a(function(){var e=document.body,f=e.appendChild(f=document.createElement("div"));f.offsetHeight;a.extend(f.style,{minHeight:"100px",height:"auto",padding:0,borderWidth:0});a.support.minHeight=f.offsetHeight===100;a.support.selectstart="onselectstart" in f;e.removeChild(f).style.display="none"});a.extend(a.ui,{plugin:{add:function(f,g,j){var h=a.ui[f].prototype;for(var e in j){h.plugins[e]=h.plugins[e]||[];h.plugins[e].push([g,j[e]])}},call:function(e,g,f){var j=e.plugins[g];if(!j||!e.element[0].parentNode){return}for(var h=0;h0){return true}h[e]=1;g=(h[e]>0);h[e]=0;return g},isOverAxis:function(f,e,g){return(f>e)&&(f<(e+g))},isOver:function(j,f,i,h,e,g){return a.ui.isOverAxis(j,i,e)&&a.ui.isOverAxis(f,h,g)}})})(jQuery);/*! * jQuery UI Widget 1.8.18 * * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about) @@ -38,7 +38,7 @@ * * http://docs.jquery.com/UI/Widget */ -(function(b,d){if(b.cleanData){var c=b.cleanData;b.cleanData=function(f){for(var g=0,h;(h=f[g])!=null;g++){try{b(h).triggerHandler("remove")}catch(j){}}c(f)}}else{var a=b.fn.remove;b.fn.remove=function(e,f){return this.each(function(){if(!f){if(!e||b.filter(e,[this]).length){b("*",this).add([this]).each(function(){try{b(this).triggerHandler("remove")}catch(g){}})}}return a.call(b(this),e,f)})}}b.widget=function(f,h,e){var g=f.split(".")[0],j;f=f.split(".")[1];j=g+"-"+f;if(!e){e=h;h=b.Widget}b.expr[":"][j]=function(k){return !!b.data(k,f)};b[g]=b[g]||{};b[g][f]=function(k,l){if(arguments.length){this._createWidget(k,l)}};var i=new h();i.options=b.extend(true,{},i.options);b[g][f].prototype=b.extend(true,i,{namespace:g,widgetName:f,widgetEventPrefix:b[g][f].prototype.widgetEventPrefix||f,widgetBaseClass:j},e);b.widget.bridge(f,b[g][f])};b.widget.bridge=function(f,e){b.fn[f]=function(i){var g=typeof i==="string",h=Array.prototype.slice.call(arguments,1),j=this;i=!g&&h.length?b.extend.apply(null,[true,i].concat(h)):i;if(g&&i.charAt(0)==="_"){return j}if(g){this.each(function(){var k=b.data(this,f),l=k&&b.isFunction(k[i])?k[i].apply(k,h):k;if(l!==k&&l!==d){j=l;return false}})}else{this.each(function(){var k=b.data(this,f);if(k){k.option(i||{})._init()}else{b.data(this,f,new e(i,this))}})}return j}};b.Widget=function(e,f){if(arguments.length){this._createWidget(e,f)}};b.Widget.prototype={widgetName:"widget",widgetEventPrefix:"",options:{disabled:false},_createWidget:function(f,g){b.data(g,this.widgetName,this);this.element=b(g);this.options=b.extend(true,{},this.options,this._getCreateOptions(),f);var e=this;this.element.bind("remove."+this.widgetName,function(){e.destroy()});this._create();this._trigger("create");this._init()},_getCreateOptions:function(){return b.metadata&&b.metadata.get(this.element[0])[this.widgetName]},_create:function(){},_init:function(){},destroy:function(){this.element.unbind("."+this.widgetName).removeData(this.widgetName);this.widget().unbind("."+this.widgetName).removeAttr("aria-disabled").removeClass(this.widgetBaseClass+"-disabled ui-state-disabled")},widget:function(){return this.element},option:function(f,g){var e=f;if(arguments.length===0){return b.extend({},this.options)}if(typeof f==="string"){if(g===d){return this.options[f]}e={};e[f]=g}this._setOptions(e);return this},_setOptions:function(f){var e=this;b.each(f,function(g,h){e._setOption(g,h)});return this},_setOption:function(e,f){this.options[e]=f;if(e==="disabled"){this.widget()[f?"addClass":"removeClass"](this.widgetBaseClass+"-disabled ui-state-disabled").attr("aria-disabled",f)}return this},enable:function(){return this._setOption("disabled",false)},disable:function(){return this._setOption("disabled",true)},_trigger:function(e,f,g){var j,i,h=this.options[e];g=g||{};f=b.Event(f);f.type=(e===this.widgetEventPrefix?e:this.widgetEventPrefix+e).toLowerCase();f.target=this.element[0];i=f.originalEvent;if(i){for(j in i){if(!(j in f)){f[j]=i[j]}}}this.element.trigger(f,g);return !(b.isFunction(h)&&h.call(this.element[0],f,g)===false||f.isDefaultPrevented())}}})(jQuery);/* +(function(b,d){if(b.cleanData){var c=b.cleanData;b.cleanData=function(f){for(var g=0,h;(h=f[g])!=null;g++){try{b(h).triggerHandler("remove")}catch(j){}}c(f)}}else{var a=b.fn.remove;b.fn.remove=function(e,f){return this.each(function(){if(!f){if(!e||b.filter(e,[this]).length){b("*",this).add([this]).each(function(){try{b(this).triggerHandler("remove")}catch(g){}})}}return a.call(b(this),e,f)})}}b.widget=function(f,h,e){var g=f.split(".")[0],j;f=f.split(".")[1];j=g+"-"+f;if(!e){e=h;h=b.Widget}b.expr[":"][j]=function(k){return !!b.data(k,f)};b[g]=b[g]||{};b[g][f]=function(k,l){if(arguments.length){this._createWidget(k,l)}};var i=new h();i.options=b.extend(true,{},i.options);b[g][f].prototype=b.extend(true,i,{namespace:g,widgetName:f,widgetEventPrefix:b[g][f].prototype.widgetEventPrefix||f,widgetBaseClass:j},e);b.widget.bridge(f,b[g][f])};b.widget.bridge=function(f,e){b.fn[f]=function(i){var g=typeof i==="string",h=Array.prototype.slice.call(arguments,1),j=this;i=!g&&h.length?b.extend.apply(null,[true,i].concat(h)):i;if(g&&i.charAt(0)==="_"){return j}if(g){this.each(function(){var k=b.data(this,f),l=k&&b.isFunction(k[i])?k[i].apply(k,h):k;if(l!==k&&l!==d){j=l;return false}})}else{this.each(function(){var k=b.data(this,f);if(k){k.option(i||{})._init()}else{b.data(this,f,new e(i,this))}})}return j}};b.Widget=function(e,f){if(arguments.length){this._createWidget(e,f)}};b.Widget.prototype={widgetName:"widget",widgetEventPrefix:"",options:{disabled:false},_createWidget:function(f,g){b.data(g,this.widgetName,this);this.element=b(g);this.options=b.extend(true,{},this.options,this._getCreateOptions(),f);var e=this;this.element.bind("remove."+this.widgetName,function(){e.destroy()});this._create();this._trigger("create");this._init()},_getCreateOptions:function(){return b.metadata&&b.metadata.get(this.element[0])[this.widgetName]},_create:function(){},_init:function(){},destroy:function(){this.element.unbind("."+this.widgetName).removeData(this.widgetName);this.widget().unbind("."+this.widgetName).removeAttr("aria-disabled").removeClass(this.widgetBaseClass+"-disabled ui-state-disabled")},widget:function(){return this.element},option:function(f,g){var e=f;if(arguments.length===0){return b.extend({},this.options)}if(typeof f==="string"){if(g===d){return this.options[f]}e={};e[f]=g}this._setOptions(e);return this},_setOptions:function(f){var e=this;b.each(f,function(g,h){e._setOption(g,h)});return this},_setOption:function(e,f){this.options[e]=f;if(e==="disabled"){this.widget()[f?"addClass":"removeClass"](this.widgetBaseClass+"-disabled ui-state-disabled").attr("aria-disabled",f)}return this},enable:function(){return this._setOption("disabled",false)},disable:function(){return this._setOption("disabled",true)},_trigger:function(e,f,g){var j,i,h=this.options[e];g=g||{};f=b.Event(f);f.type=(e===this.widgetEventPrefix?e:this.widgetEventPrefix+e).toLowerCase();f.target=this.element[0];i=f.originalEvent;if(i){for(j in i){if(!(j in f)){f[j]=i[j]}}}this.element.trigger(f,g);return !(b.isFunction(h)&&h.call(this.element[0],f,g)===false||f.isDefaultPrevented())}}})(jQuery);/*! * jQuery UI Mouse 1.8.18 * * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about) @@ -50,7 +50,7 @@ * Depends: * jquery.ui.widget.js */ -(function(b,c){var a=false;b(document).mouseup(function(d){a=false});b.widget("ui.mouse",{options:{cancel:":input,option",distance:1,delay:0},_mouseInit:function(){var d=this;this.element.bind("mousedown."+this.widgetName,function(e){return d._mouseDown(e)}).bind("click."+this.widgetName,function(e){if(true===b.data(e.target,d.widgetName+".preventClickEvent")){b.removeData(e.target,d.widgetName+".preventClickEvent");e.stopImmediatePropagation();return false}});this.started=false},_mouseDestroy:function(){this.element.unbind("."+this.widgetName)},_mouseDown:function(f){if(a){return}(this._mouseStarted&&this._mouseUp(f));this._mouseDownEvent=f;var e=this,g=(f.which==1),d=(typeof this.options.cancel=="string"&&f.target.nodeName?b(f.target).closest(this.options.cancel).length:false);if(!g||d||!this._mouseCapture(f)){return true}this.mouseDelayMet=!this.options.delay;if(!this.mouseDelayMet){this._mouseDelayTimer=setTimeout(function(){e.mouseDelayMet=true},this.options.delay)}if(this._mouseDistanceMet(f)&&this._mouseDelayMet(f)){this._mouseStarted=(this._mouseStart(f)!==false);if(!this._mouseStarted){f.preventDefault();return true}}if(true===b.data(f.target,this.widgetName+".preventClickEvent")){b.removeData(f.target,this.widgetName+".preventClickEvent")}this._mouseMoveDelegate=function(h){return e._mouseMove(h)};this._mouseUpDelegate=function(h){return e._mouseUp(h)};b(document).bind("mousemove."+this.widgetName,this._mouseMoveDelegate).bind("mouseup."+this.widgetName,this._mouseUpDelegate);f.preventDefault();a=true;return true},_mouseMove:function(d){if(b.browser.msie&&!(document.documentMode>=9)&&!d.button){return this._mouseUp(d)}if(this._mouseStarted){this._mouseDrag(d);return d.preventDefault()}if(this._mouseDistanceMet(d)&&this._mouseDelayMet(d)){this._mouseStarted=(this._mouseStart(this._mouseDownEvent,d)!==false);(this._mouseStarted?this._mouseDrag(d):this._mouseUp(d))}return !this._mouseStarted},_mouseUp:function(d){b(document).unbind("mousemove."+this.widgetName,this._mouseMoveDelegate).unbind("mouseup."+this.widgetName,this._mouseUpDelegate);if(this._mouseStarted){this._mouseStarted=false;if(d.target==this._mouseDownEvent.target){b.data(d.target,this.widgetName+".preventClickEvent",true)}this._mouseStop(d)}return false},_mouseDistanceMet:function(d){return(Math.max(Math.abs(this._mouseDownEvent.pageX-d.pageX),Math.abs(this._mouseDownEvent.pageY-d.pageY))>=this.options.distance)},_mouseDelayMet:function(d){return this.mouseDelayMet},_mouseStart:function(d){},_mouseDrag:function(d){},_mouseStop:function(d){},_mouseCapture:function(d){return true}})})(jQuery);(function(c,d){c.widget("ui.resizable",c.ui.mouse,{widgetEventPrefix:"resize",options:{alsoResize:false,animate:false,animateDuration:"slow",animateEasing:"swing",aspectRatio:false,autoHide:false,containment:false,ghost:false,grid:false,handles:"e,s,se",helper:false,maxHeight:null,maxWidth:null,minHeight:10,minWidth:10,zIndex:1000},_create:function(){var f=this,k=this.options;this.element.addClass("ui-resizable");c.extend(this,{_aspectRatio:!!(k.aspectRatio),aspectRatio:k.aspectRatio,originalElement:this.element,_proportionallyResizeElements:[],_helper:k.helper||k.ghost||k.animate?k.helper||"ui-resizable-helper":null});if(this.element[0].nodeName.match(/canvas|textarea|input|select|button|img/i)){this.element.wrap(c('
').css({position:this.element.css("position"),width:this.element.outerWidth(),height:this.element.outerHeight(),top:this.element.css("top"),left:this.element.css("left")}));this.element=this.element.parent().data("resizable",this.element.data("resizable"));this.elementIsWrapper=true;this.element.css({marginLeft:this.originalElement.css("marginLeft"),marginTop:this.originalElement.css("marginTop"),marginRight:this.originalElement.css("marginRight"),marginBottom:this.originalElement.css("marginBottom")});this.originalElement.css({marginLeft:0,marginTop:0,marginRight:0,marginBottom:0});this.originalResizeStyle=this.originalElement.css("resize");this.originalElement.css("resize","none");this._proportionallyResizeElements.push(this.originalElement.css({position:"static",zoom:1,display:"block"}));this.originalElement.css({margin:this.originalElement.css("margin")});this._proportionallyResize()}this.handles=k.handles||(!c(".ui-resizable-handle",this.element).length?"e,s,se":{n:".ui-resizable-n",e:".ui-resizable-e",s:".ui-resizable-s",w:".ui-resizable-w",se:".ui-resizable-se",sw:".ui-resizable-sw",ne:".ui-resizable-ne",nw:".ui-resizable-nw"});if(this.handles.constructor==String){if(this.handles=="all"){this.handles="n,e,s,w,se,sw,ne,nw"}var l=this.handles.split(",");this.handles={};for(var g=0;g
');if(/sw|se|ne|nw/.test(j)){h.css({zIndex:++k.zIndex})}if("se"==j){h.addClass("ui-icon ui-icon-gripsmall-diagonal-se")}this.handles[j]=".ui-resizable-"+j;this.element.append(h)}}this._renderAxis=function(q){q=q||this.element;for(var n in this.handles){if(this.handles[n].constructor==String){this.handles[n]=c(this.handles[n],this.element).show()}if(this.elementIsWrapper&&this.originalElement[0].nodeName.match(/textarea|input|select|button/i)){var o=c(this.handles[n],this.element),p=0;p=/sw|ne|nw|se|n|s/.test(n)?o.outerHeight():o.outerWidth();var m=["padding",/ne|nw|n/.test(n)?"Top":/se|sw|s/.test(n)?"Bottom":/^e$/.test(n)?"Right":"Left"].join("");q.css(m,p);this._proportionallyResize()}if(!c(this.handles[n]).length){continue}}};this._renderAxis(this.element);this._handles=c(".ui-resizable-handle",this.element).disableSelection();this._handles.mouseover(function(){if(!f.resizing){if(this.className){var i=this.className.match(/ui-resizable-(se|sw|ne|nw|n|e|s|w)/i)}f.axis=i&&i[1]?i[1]:"se"}});if(k.autoHide){this._handles.hide();c(this.element).addClass("ui-resizable-autohide").hover(function(){if(k.disabled){return}c(this).removeClass("ui-resizable-autohide");f._handles.show()},function(){if(k.disabled){return}if(!f.resizing){c(this).addClass("ui-resizable-autohide");f._handles.hide()}})}this._mouseInit()},destroy:function(){this._mouseDestroy();var e=function(g){c(g).removeClass("ui-resizable ui-resizable-disabled ui-resizable-resizing").removeData("resizable").unbind(".resizable").find(".ui-resizable-handle").remove()};if(this.elementIsWrapper){e(this.element);var f=this.element;f.after(this.originalElement.css({position:f.css("position"),width:f.outerWidth(),height:f.outerHeight(),top:f.css("top"),left:f.css("left")})).remove()}this.originalElement.css("resize",this.originalResizeStyle);e(this.originalElement);return this},_mouseCapture:function(f){var g=false;for(var e in this.handles){if(c(this.handles[e])[0]==f.target){g=true}}return !this.options.disabled&&g},_mouseStart:function(g){var j=this.options,f=this.element.position(),e=this.element;this.resizing=true;this.documentScroll={top:c(document).scrollTop(),left:c(document).scrollLeft()};if(e.is(".ui-draggable")||(/absolute/).test(e.css("position"))){e.css({position:"absolute",top:f.top,left:f.left})}this._renderProxy();var k=b(this.helper.css("left")),h=b(this.helper.css("top"));if(j.containment){k+=c(j.containment).scrollLeft()||0;h+=c(j.containment).scrollTop()||0}this.offset=this.helper.offset();this.position={left:k,top:h};this.size=this._helper?{width:e.outerWidth(),height:e.outerHeight()}:{width:e.width(),height:e.height()};this.originalSize=this._helper?{width:e.outerWidth(),height:e.outerHeight()}:{width:e.width(),height:e.height()};this.originalPosition={left:k,top:h};this.sizeDiff={width:e.outerWidth()-e.width(),height:e.outerHeight()-e.height()};this.originalMousePosition={left:g.pageX,top:g.pageY};this.aspectRatio=(typeof j.aspectRatio=="number")?j.aspectRatio:((this.originalSize.width/this.originalSize.height)||1);var i=c(".ui-resizable-"+this.axis).css("cursor");c("body").css("cursor",i=="auto"?this.axis+"-resize":i);e.addClass("ui-resizable-resizing");this._propagate("start",g);return true},_mouseDrag:function(e){var h=this.helper,g=this.options,m={},q=this,j=this.originalMousePosition,n=this.axis;var r=(e.pageX-j.left)||0,p=(e.pageY-j.top)||0;var i=this._change[n];if(!i){return false}var l=i.apply(this,[e,r,p]),k=c.browser.msie&&c.browser.version<7,f=this.sizeDiff;this._updateVirtualBoundaries(e.shiftKey);if(this._aspectRatio||e.shiftKey){l=this._updateRatio(l,e)}l=this._respectSize(l,e);this._propagate("resize",e);h.css({top:this.position.top+"px",left:this.position.left+"px",width:this.size.width+"px",height:this.size.height+"px"});if(!this._helper&&this._proportionallyResizeElements.length){this._proportionallyResize()}this._updateCache(l);this._trigger("resize",e,this.ui());return false},_mouseStop:function(h){this.resizing=false;var i=this.options,m=this;if(this._helper){var g=this._proportionallyResizeElements,e=g.length&&(/textarea/i).test(g[0].nodeName),f=e&&c.ui.hasScroll(g[0],"left")?0:m.sizeDiff.height,k=e?0:m.sizeDiff.width;var n={width:(m.helper.width()-k),height:(m.helper.height()-f)},j=(parseInt(m.element.css("left"),10)+(m.position.left-m.originalPosition.left))||null,l=(parseInt(m.element.css("top"),10)+(m.position.top-m.originalPosition.top))||null;if(!i.animate){this.element.css(c.extend(n,{top:l,left:j}))}m.helper.height(m.size.height);m.helper.width(m.size.width);if(this._helper&&!i.animate){this._proportionallyResize()}}c("body").css("cursor","auto");this.element.removeClass("ui-resizable-resizing");this._propagate("stop",h);if(this._helper){this.helper.remove()}return false},_updateVirtualBoundaries:function(g){var j=this.options,i,h,f,k,e;e={minWidth:a(j.minWidth)?j.minWidth:0,maxWidth:a(j.maxWidth)?j.maxWidth:Infinity,minHeight:a(j.minHeight)?j.minHeight:0,maxHeight:a(j.maxHeight)?j.maxHeight:Infinity};if(this._aspectRatio||g){i=e.minHeight*this.aspectRatio;f=e.minWidth/this.aspectRatio;h=e.maxHeight*this.aspectRatio;k=e.maxWidth/this.aspectRatio;if(i>e.minWidth){e.minWidth=i}if(f>e.minHeight){e.minHeight=f}if(hl.width),s=a(l.height)&&i.minHeight&&(i.minHeight>l.height);if(h){l.width=i.minWidth}if(s){l.height=i.minHeight}if(t){l.width=i.maxWidth}if(m){l.height=i.maxHeight}var f=this.originalPosition.left+this.originalSize.width,p=this.position.top+this.size.height;var k=/sw|nw|w/.test(q),e=/nw|ne|n/.test(q);if(h&&k){l.left=f-i.minWidth}if(t&&k){l.left=f-i.maxWidth}if(s&&e){l.top=p-i.minHeight}if(m&&e){l.top=p-i.maxHeight}var n=!l.width&&!l.height;if(n&&!l.left&&l.top){l.top=null}else{if(n&&!l.top&&l.left){l.left=null}}return l},_proportionallyResize:function(){var k=this.options;if(!this._proportionallyResizeElements.length){return}var g=this.helper||this.element;for(var f=0;f');var e=c.browser.msie&&c.browser.version<7,g=(e?1:0),h=(e?2:-1);this.helper.addClass(this._helper).css({width:this.element.outerWidth()+h,height:this.element.outerHeight()+h,position:"absolute",left:this.elementOffset.left-g+"px",top:this.elementOffset.top-g+"px",zIndex:++i.zIndex});this.helper.appendTo("body").disableSelection()}else{this.helper=this.element}},_change:{e:function(g,f,e){return{width:this.originalSize.width+f}},w:function(h,f,e){var j=this.options,g=this.originalSize,i=this.originalPosition;return{left:i.left+f,width:g.width-f}},n:function(h,f,e){var j=this.options,g=this.originalSize,i=this.originalPosition;return{top:i.top+e,height:g.height-e}},s:function(g,f,e){return{height:this.originalSize.height+e}},se:function(g,f,e){return c.extend(this._change.s.apply(this,arguments),this._change.e.apply(this,[g,f,e]))},sw:function(g,f,e){return c.extend(this._change.s.apply(this,arguments),this._change.w.apply(this,[g,f,e]))},ne:function(g,f,e){return c.extend(this._change.n.apply(this,arguments),this._change.e.apply(this,[g,f,e]))},nw:function(g,f,e){return c.extend(this._change.n.apply(this,arguments),this._change.w.apply(this,[g,f,e]))}},_propagate:function(f,e){c.ui.plugin.call(this,f,[e,this.ui()]);(f!="resize"&&this._trigger(f,e,this.ui()))},plugins:{},ui:function(){return{originalElement:this.originalElement,element:this.element,helper:this.helper,position:this.position,size:this.size,originalSize:this.originalSize,originalPosition:this.originalPosition}}});c.extend(c.ui.resizable,{version:"1.8.18"});c.ui.plugin.add("resizable","alsoResize",{start:function(f,g){var e=c(this).data("resizable"),i=e.options;var h=function(j){c(j).each(function(){var k=c(this);k.data("resizable-alsoresize",{width:parseInt(k.width(),10),height:parseInt(k.height(),10),left:parseInt(k.css("left"),10),top:parseInt(k.css("top"),10)})})};if(typeof(i.alsoResize)=="object"&&!i.alsoResize.parentNode){if(i.alsoResize.length){i.alsoResize=i.alsoResize[0];h(i.alsoResize)}else{c.each(i.alsoResize,function(j){h(j)})}}else{h(i.alsoResize)}},resize:function(g,i){var f=c(this).data("resizable"),j=f.options,h=f.originalSize,l=f.originalPosition;var k={height:(f.size.height-h.height)||0,width:(f.size.width-h.width)||0,top:(f.position.top-l.top)||0,left:(f.position.left-l.left)||0},e=function(m,n){c(m).each(function(){var q=c(this),r=c(this).data("resizable-alsoresize"),p={},o=n&&n.length?n:q.parents(i.originalElement[0]).length?["width","height"]:["width","height","top","left"];c.each(o,function(s,u){var t=(r[u]||0)+(k[u]||0);if(t&&t>=0){p[u]=t||null}});q.css(p)})};if(typeof(j.alsoResize)=="object"&&!j.alsoResize.nodeType){c.each(j.alsoResize,function(m,n){e(m,n)})}else{e(j.alsoResize)}},stop:function(e,f){c(this).removeData("resizable-alsoresize")}});c.ui.plugin.add("resizable","animate",{stop:function(i,n){var p=c(this).data("resizable"),j=p.options;var h=p._proportionallyResizeElements,e=h.length&&(/textarea/i).test(h[0].nodeName),f=e&&c.ui.hasScroll(h[0],"left")?0:p.sizeDiff.height,l=e?0:p.sizeDiff.width;var g={width:(p.size.width-l),height:(p.size.height-f)},k=(parseInt(p.element.css("left"),10)+(p.position.left-p.originalPosition.left))||null,m=(parseInt(p.element.css("top"),10)+(p.position.top-p.originalPosition.top))||null;p.element.animate(c.extend(g,m&&k?{top:m,left:k}:{}),{duration:j.animateDuration,easing:j.animateEasing,step:function(){var o={width:parseInt(p.element.css("width"),10),height:parseInt(p.element.css("height"),10),top:parseInt(p.element.css("top"),10),left:parseInt(p.element.css("left"),10)};if(h&&h.length){c(h[0]).css({width:o.width,height:o.height})}p._updateCache(o);p._propagate("resize",i)}})}});c.ui.plugin.add("resizable","containment",{start:function(f,r){var t=c(this).data("resizable"),j=t.options,l=t.element;var g=j.containment,k=(g instanceof c)?g.get(0):(/parent/.test(g))?l.parent().get(0):g;if(!k){return}t.containerElement=c(k);if(/document/.test(g)||g==document){t.containerOffset={left:0,top:0};t.containerPosition={left:0,top:0};t.parentData={element:c(document),left:0,top:0,width:c(document).width(),height:c(document).height()||document.body.parentNode.scrollHeight}}else{var n=c(k),i=[];c(["Top","Right","Left","Bottom"]).each(function(p,o){i[p]=b(n.css("padding"+o))});t.containerOffset=n.offset();t.containerPosition=n.position();t.containerSize={height:(n.innerHeight()-i[3]),width:(n.innerWidth()-i[1])};var q=t.containerOffset,e=t.containerSize.height,m=t.containerSize.width,h=(c.ui.hasScroll(k,"left")?k.scrollWidth:m),s=(c.ui.hasScroll(k)?k.scrollHeight:e);t.parentData={element:k,left:q.left,top:q.top,width:h,height:s}}},resize:function(g,q){var t=c(this).data("resizable"),i=t.options,f=t.containerSize,p=t.containerOffset,m=t.size,n=t.position,r=t._aspectRatio||g.shiftKey,e={top:0,left:0},h=t.containerElement;if(h[0]!=document&&(/static/).test(h.css("position"))){e=p}if(n.left<(t._helper?p.left:0)){t.size.width=t.size.width+(t._helper?(t.position.left-p.left):(t.position.left-e.left));if(r){t.size.height=t.size.width/i.aspectRatio}t.position.left=i.helper?p.left:0}if(n.top<(t._helper?p.top:0)){t.size.height=t.size.height+(t._helper?(t.position.top-p.top):t.position.top);if(r){t.size.width=t.size.height*i.aspectRatio}t.position.top=t._helper?p.top:0}t.offset.left=t.parentData.left+t.position.left;t.offset.top=t.parentData.top+t.position.top;var l=Math.abs((t._helper?t.offset.left-e.left:(t.offset.left-e.left))+t.sizeDiff.width),s=Math.abs((t._helper?t.offset.top-e.top:(t.offset.top-p.top))+t.sizeDiff.height);var k=t.containerElement.get(0)==t.element.parent().get(0),j=/relative|absolute/.test(t.containerElement.css("position"));if(k&&j){l-=t.parentData.left}if(l+t.size.width>=t.parentData.width){t.size.width=t.parentData.width-l;if(r){t.size.height=t.size.width/t.aspectRatio}}if(s+t.size.height>=t.parentData.height){t.size.height=t.parentData.height-s;if(r){t.size.width=t.size.height*t.aspectRatio}}},stop:function(f,n){var q=c(this).data("resizable"),g=q.options,l=q.position,m=q.containerOffset,e=q.containerPosition,i=q.containerElement;var j=c(q.helper),r=j.offset(),p=j.outerWidth()-q.sizeDiff.width,k=j.outerHeight()-q.sizeDiff.height;if(q._helper&&!g.animate&&(/relative/).test(i.css("position"))){c(this).css({left:r.left-e.left-m.left,width:p,height:k})}if(q._helper&&!g.animate&&(/static/).test(i.css("position"))){c(this).css({left:r.left-e.left-m.left,width:p,height:k})}}});c.ui.plugin.add("resizable","ghost",{start:function(g,h){var e=c(this).data("resizable"),i=e.options,f=e.size;e.ghost=e.originalElement.clone();e.ghost.css({opacity:0.25,display:"block",position:"relative",height:f.height,width:f.width,margin:0,left:0,top:0}).addClass("ui-resizable-ghost").addClass(typeof i.ghost=="string"?i.ghost:"");e.ghost.appendTo(e.helper)},resize:function(f,g){var e=c(this).data("resizable"),h=e.options;if(e.ghost){e.ghost.css({position:"relative",height:e.size.height,width:e.size.width})}},stop:function(f,g){var e=c(this).data("resizable"),h=e.options;if(e.ghost&&e.helper){e.helper.get(0).removeChild(e.ghost.get(0))}}});c.ui.plugin.add("resizable","grid",{resize:function(e,m){var p=c(this).data("resizable"),h=p.options,k=p.size,i=p.originalSize,j=p.originalPosition,n=p.axis,l=h._aspectRatio||e.shiftKey;h.grid=typeof h.grid=="number"?[h.grid,h.grid]:h.grid;var g=Math.round((k.width-i.width)/(h.grid[0]||1))*(h.grid[0]||1),f=Math.round((k.height-i.height)/(h.grid[1]||1))*(h.grid[1]||1);if(/^(se|s|e)$/.test(n)){p.size.width=i.width+g;p.size.height=i.height+f}else{if(/^(ne)$/.test(n)){p.size.width=i.width+g;p.size.height=i.height+f;p.position.top=j.top-f}else{if(/^(sw)$/.test(n)){p.size.width=i.width+g;p.size.height=i.height+f;p.position.left=j.left-g}else{p.size.width=i.width+g;p.size.height=i.height+f;p.position.top=j.top-f;p.position.left=j.left-g}}}}});var b=function(e){return parseInt(e,10)||0};var a=function(e){return !isNaN(parseInt(e,10))}})(jQuery);/* +(function(b,c){var a=false;b(document).mouseup(function(d){a=false});b.widget("ui.mouse",{options:{cancel:":input,option",distance:1,delay:0},_mouseInit:function(){var d=this;this.element.bind("mousedown."+this.widgetName,function(e){return d._mouseDown(e)}).bind("click."+this.widgetName,function(e){if(true===b.data(e.target,d.widgetName+".preventClickEvent")){b.removeData(e.target,d.widgetName+".preventClickEvent");e.stopImmediatePropagation();return false}});this.started=false},_mouseDestroy:function(){this.element.unbind("."+this.widgetName)},_mouseDown:function(f){if(a){return}(this._mouseStarted&&this._mouseUp(f));this._mouseDownEvent=f;var e=this,g=(f.which==1),d=(typeof this.options.cancel=="string"&&f.target.nodeName?b(f.target).closest(this.options.cancel).length:false);if(!g||d||!this._mouseCapture(f)){return true}this.mouseDelayMet=!this.options.delay;if(!this.mouseDelayMet){this._mouseDelayTimer=setTimeout(function(){e.mouseDelayMet=true},this.options.delay)}if(this._mouseDistanceMet(f)&&this._mouseDelayMet(f)){this._mouseStarted=(this._mouseStart(f)!==false);if(!this._mouseStarted){f.preventDefault();return true}}if(true===b.data(f.target,this.widgetName+".preventClickEvent")){b.removeData(f.target,this.widgetName+".preventClickEvent")}this._mouseMoveDelegate=function(h){return e._mouseMove(h)};this._mouseUpDelegate=function(h){return e._mouseUp(h)};b(document).bind("mousemove."+this.widgetName,this._mouseMoveDelegate).bind("mouseup."+this.widgetName,this._mouseUpDelegate);f.preventDefault();a=true;return true},_mouseMove:function(d){if(b.browser.msie&&!(document.documentMode>=9)&&!d.button){return this._mouseUp(d)}if(this._mouseStarted){this._mouseDrag(d);return d.preventDefault()}if(this._mouseDistanceMet(d)&&this._mouseDelayMet(d)){this._mouseStarted=(this._mouseStart(this._mouseDownEvent,d)!==false);(this._mouseStarted?this._mouseDrag(d):this._mouseUp(d))}return !this._mouseStarted},_mouseUp:function(d){b(document).unbind("mousemove."+this.widgetName,this._mouseMoveDelegate).unbind("mouseup."+this.widgetName,this._mouseUpDelegate);if(this._mouseStarted){this._mouseStarted=false;if(d.target==this._mouseDownEvent.target){b.data(d.target,this.widgetName+".preventClickEvent",true)}this._mouseStop(d)}return false},_mouseDistanceMet:function(d){return(Math.max(Math.abs(this._mouseDownEvent.pageX-d.pageX),Math.abs(this._mouseDownEvent.pageY-d.pageY))>=this.options.distance)},_mouseDelayMet:function(d){return this.mouseDelayMet},_mouseStart:function(d){},_mouseDrag:function(d){},_mouseStop:function(d){},_mouseCapture:function(d){return true}})})(jQuery);(function(c,d){c.widget("ui.resizable",c.ui.mouse,{widgetEventPrefix:"resize",options:{alsoResize:false,animate:false,animateDuration:"slow",animateEasing:"swing",aspectRatio:false,autoHide:false,containment:false,ghost:false,grid:false,handles:"e,s,se",helper:false,maxHeight:null,maxWidth:null,minHeight:10,minWidth:10,zIndex:1000},_create:function(){var f=this,k=this.options;this.element.addClass("ui-resizable");c.extend(this,{_aspectRatio:!!(k.aspectRatio),aspectRatio:k.aspectRatio,originalElement:this.element,_proportionallyResizeElements:[],_helper:k.helper||k.ghost||k.animate?k.helper||"ui-resizable-helper":null});if(this.element[0].nodeName.match(/canvas|textarea|input|select|button|img/i)){this.element.wrap(c('
').css({position:this.element.css("position"),width:this.element.outerWidth(),height:this.element.outerHeight(),top:this.element.css("top"),left:this.element.css("left")}));this.element=this.element.parent().data("resizable",this.element.data("resizable"));this.elementIsWrapper=true;this.element.css({marginLeft:this.originalElement.css("marginLeft"),marginTop:this.originalElement.css("marginTop"),marginRight:this.originalElement.css("marginRight"),marginBottom:this.originalElement.css("marginBottom")});this.originalElement.css({marginLeft:0,marginTop:0,marginRight:0,marginBottom:0});this.originalResizeStyle=this.originalElement.css("resize");this.originalElement.css("resize","none");this._proportionallyResizeElements.push(this.originalElement.css({position:"static",zoom:1,display:"block"}));this.originalElement.css({margin:this.originalElement.css("margin")});this._proportionallyResize()}this.handles=k.handles||(!c(".ui-resizable-handle",this.element).length?"e,s,se":{n:".ui-resizable-n",e:".ui-resizable-e",s:".ui-resizable-s",w:".ui-resizable-w",se:".ui-resizable-se",sw:".ui-resizable-sw",ne:".ui-resizable-ne",nw:".ui-resizable-nw"});if(this.handles.constructor==String){if(this.handles=="all"){this.handles="n,e,s,w,se,sw,ne,nw"}var l=this.handles.split(",");this.handles={};for(var g=0;g');if(/sw|se|ne|nw/.test(j)){h.css({zIndex:++k.zIndex})}if("se"==j){h.addClass("ui-icon ui-icon-gripsmall-diagonal-se")}this.handles[j]=".ui-resizable-"+j;this.element.append(h)}}this._renderAxis=function(q){q=q||this.element;for(var n in this.handles){if(this.handles[n].constructor==String){this.handles[n]=c(this.handles[n],this.element).show()}if(this.elementIsWrapper&&this.originalElement[0].nodeName.match(/textarea|input|select|button/i)){var o=c(this.handles[n],this.element),p=0;p=/sw|ne|nw|se|n|s/.test(n)?o.outerHeight():o.outerWidth();var m=["padding",/ne|nw|n/.test(n)?"Top":/se|sw|s/.test(n)?"Bottom":/^e$/.test(n)?"Right":"Left"].join("");q.css(m,p);this._proportionallyResize()}if(!c(this.handles[n]).length){continue}}};this._renderAxis(this.element);this._handles=c(".ui-resizable-handle",this.element).disableSelection();this._handles.mouseover(function(){if(!f.resizing){if(this.className){var i=this.className.match(/ui-resizable-(se|sw|ne|nw|n|e|s|w)/i)}f.axis=i&&i[1]?i[1]:"se"}});if(k.autoHide){this._handles.hide();c(this.element).addClass("ui-resizable-autohide").hover(function(){if(k.disabled){return}c(this).removeClass("ui-resizable-autohide");f._handles.show()},function(){if(k.disabled){return}if(!f.resizing){c(this).addClass("ui-resizable-autohide");f._handles.hide()}})}this._mouseInit()},destroy:function(){this._mouseDestroy();var e=function(g){c(g).removeClass("ui-resizable ui-resizable-disabled ui-resizable-resizing").removeData("resizable").unbind(".resizable").find(".ui-resizable-handle").remove()};if(this.elementIsWrapper){e(this.element);var f=this.element;f.after(this.originalElement.css({position:f.css("position"),width:f.outerWidth(),height:f.outerHeight(),top:f.css("top"),left:f.css("left")})).remove()}this.originalElement.css("resize",this.originalResizeStyle);e(this.originalElement);return this},_mouseCapture:function(f){var g=false;for(var e in this.handles){if(c(this.handles[e])[0]==f.target){g=true}}return !this.options.disabled&&g},_mouseStart:function(g){var j=this.options,f=this.element.position(),e=this.element;this.resizing=true;this.documentScroll={top:c(document).scrollTop(),left:c(document).scrollLeft()};if(e.is(".ui-draggable")||(/absolute/).test(e.css("position"))){e.css({position:"absolute",top:f.top,left:f.left})}this._renderProxy();var k=b(this.helper.css("left")),h=b(this.helper.css("top"));if(j.containment){k+=c(j.containment).scrollLeft()||0;h+=c(j.containment).scrollTop()||0}this.offset=this.helper.offset();this.position={left:k,top:h};this.size=this._helper?{width:e.outerWidth(),height:e.outerHeight()}:{width:e.width(),height:e.height()};this.originalSize=this._helper?{width:e.outerWidth(),height:e.outerHeight()}:{width:e.width(),height:e.height()};this.originalPosition={left:k,top:h};this.sizeDiff={width:e.outerWidth()-e.width(),height:e.outerHeight()-e.height()};this.originalMousePosition={left:g.pageX,top:g.pageY};this.aspectRatio=(typeof j.aspectRatio=="number")?j.aspectRatio:((this.originalSize.width/this.originalSize.height)||1);var i=c(".ui-resizable-"+this.axis).css("cursor");c("body").css("cursor",i=="auto"?this.axis+"-resize":i);e.addClass("ui-resizable-resizing");this._propagate("start",g);return true},_mouseDrag:function(e){var h=this.helper,g=this.options,m={},q=this,j=this.originalMousePosition,n=this.axis;var r=(e.pageX-j.left)||0,p=(e.pageY-j.top)||0;var i=this._change[n];if(!i){return false}var l=i.apply(this,[e,r,p]),k=c.browser.msie&&c.browser.version<7,f=this.sizeDiff;this._updateVirtualBoundaries(e.shiftKey);if(this._aspectRatio||e.shiftKey){l=this._updateRatio(l,e)}l=this._respectSize(l,e);this._propagate("resize",e);h.css({top:this.position.top+"px",left:this.position.left+"px",width:this.size.width+"px",height:this.size.height+"px"});if(!this._helper&&this._proportionallyResizeElements.length){this._proportionallyResize()}this._updateCache(l);this._trigger("resize",e,this.ui());return false},_mouseStop:function(h){this.resizing=false;var i=this.options,m=this;if(this._helper){var g=this._proportionallyResizeElements,e=g.length&&(/textarea/i).test(g[0].nodeName),f=e&&c.ui.hasScroll(g[0],"left")?0:m.sizeDiff.height,k=e?0:m.sizeDiff.width;var n={width:(m.helper.width()-k),height:(m.helper.height()-f)},j=(parseInt(m.element.css("left"),10)+(m.position.left-m.originalPosition.left))||null,l=(parseInt(m.element.css("top"),10)+(m.position.top-m.originalPosition.top))||null;if(!i.animate){this.element.css(c.extend(n,{top:l,left:j}))}m.helper.height(m.size.height);m.helper.width(m.size.width);if(this._helper&&!i.animate){this._proportionallyResize()}}c("body").css("cursor","auto");this.element.removeClass("ui-resizable-resizing");this._propagate("stop",h);if(this._helper){this.helper.remove()}return false},_updateVirtualBoundaries:function(g){var j=this.options,i,h,f,k,e;e={minWidth:a(j.minWidth)?j.minWidth:0,maxWidth:a(j.maxWidth)?j.maxWidth:Infinity,minHeight:a(j.minHeight)?j.minHeight:0,maxHeight:a(j.maxHeight)?j.maxHeight:Infinity};if(this._aspectRatio||g){i=e.minHeight*this.aspectRatio;f=e.minWidth/this.aspectRatio;h=e.maxHeight*this.aspectRatio;k=e.maxWidth/this.aspectRatio;if(i>e.minWidth){e.minWidth=i}if(f>e.minHeight){e.minHeight=f}if(hl.width),s=a(l.height)&&i.minHeight&&(i.minHeight>l.height);if(h){l.width=i.minWidth}if(s){l.height=i.minHeight}if(t){l.width=i.maxWidth}if(m){l.height=i.maxHeight}var f=this.originalPosition.left+this.originalSize.width,p=this.position.top+this.size.height;var k=/sw|nw|w/.test(q),e=/nw|ne|n/.test(q);if(h&&k){l.left=f-i.minWidth}if(t&&k){l.left=f-i.maxWidth}if(s&&e){l.top=p-i.minHeight}if(m&&e){l.top=p-i.maxHeight}var n=!l.width&&!l.height;if(n&&!l.left&&l.top){l.top=null}else{if(n&&!l.top&&l.left){l.left=null}}return l},_proportionallyResize:function(){var k=this.options;if(!this._proportionallyResizeElements.length){return}var g=this.helper||this.element;for(var f=0;f');var e=c.browser.msie&&c.browser.version<7,g=(e?1:0),h=(e?2:-1);this.helper.addClass(this._helper).css({width:this.element.outerWidth()+h,height:this.element.outerHeight()+h,position:"absolute",left:this.elementOffset.left-g+"px",top:this.elementOffset.top-g+"px",zIndex:++i.zIndex});this.helper.appendTo("body").disableSelection()}else{this.helper=this.element}},_change:{e:function(g,f,e){return{width:this.originalSize.width+f}},w:function(h,f,e){var j=this.options,g=this.originalSize,i=this.originalPosition;return{left:i.left+f,width:g.width-f}},n:function(h,f,e){var j=this.options,g=this.originalSize,i=this.originalPosition;return{top:i.top+e,height:g.height-e}},s:function(g,f,e){return{height:this.originalSize.height+e}},se:function(g,f,e){return c.extend(this._change.s.apply(this,arguments),this._change.e.apply(this,[g,f,e]))},sw:function(g,f,e){return c.extend(this._change.s.apply(this,arguments),this._change.w.apply(this,[g,f,e]))},ne:function(g,f,e){return c.extend(this._change.n.apply(this,arguments),this._change.e.apply(this,[g,f,e]))},nw:function(g,f,e){return c.extend(this._change.n.apply(this,arguments),this._change.w.apply(this,[g,f,e]))}},_propagate:function(f,e){c.ui.plugin.call(this,f,[e,this.ui()]);(f!="resize"&&this._trigger(f,e,this.ui()))},plugins:{},ui:function(){return{originalElement:this.originalElement,element:this.element,helper:this.helper,position:this.position,size:this.size,originalSize:this.originalSize,originalPosition:this.originalPosition}}});c.extend(c.ui.resizable,{version:"1.8.18"});c.ui.plugin.add("resizable","alsoResize",{start:function(f,g){var e=c(this).data("resizable"),i=e.options;var h=function(j){c(j).each(function(){var k=c(this);k.data("resizable-alsoresize",{width:parseInt(k.width(),10),height:parseInt(k.height(),10),left:parseInt(k.css("left"),10),top:parseInt(k.css("top"),10)})})};if(typeof(i.alsoResize)=="object"&&!i.alsoResize.parentNode){if(i.alsoResize.length){i.alsoResize=i.alsoResize[0];h(i.alsoResize)}else{c.each(i.alsoResize,function(j){h(j)})}}else{h(i.alsoResize)}},resize:function(g,i){var f=c(this).data("resizable"),j=f.options,h=f.originalSize,l=f.originalPosition;var k={height:(f.size.height-h.height)||0,width:(f.size.width-h.width)||0,top:(f.position.top-l.top)||0,left:(f.position.left-l.left)||0},e=function(m,n){c(m).each(function(){var q=c(this),r=c(this).data("resizable-alsoresize"),p={},o=n&&n.length?n:q.parents(i.originalElement[0]).length?["width","height"]:["width","height","top","left"];c.each(o,function(s,u){var t=(r[u]||0)+(k[u]||0);if(t&&t>=0){p[u]=t||null}});q.css(p)})};if(typeof(j.alsoResize)=="object"&&!j.alsoResize.nodeType){c.each(j.alsoResize,function(m,n){e(m,n)})}else{e(j.alsoResize)}},stop:function(e,f){c(this).removeData("resizable-alsoresize")}});c.ui.plugin.add("resizable","animate",{stop:function(i,n){var p=c(this).data("resizable"),j=p.options;var h=p._proportionallyResizeElements,e=h.length&&(/textarea/i).test(h[0].nodeName),f=e&&c.ui.hasScroll(h[0],"left")?0:p.sizeDiff.height,l=e?0:p.sizeDiff.width;var g={width:(p.size.width-l),height:(p.size.height-f)},k=(parseInt(p.element.css("left"),10)+(p.position.left-p.originalPosition.left))||null,m=(parseInt(p.element.css("top"),10)+(p.position.top-p.originalPosition.top))||null;p.element.animate(c.extend(g,m&&k?{top:m,left:k}:{}),{duration:j.animateDuration,easing:j.animateEasing,step:function(){var o={width:parseInt(p.element.css("width"),10),height:parseInt(p.element.css("height"),10),top:parseInt(p.element.css("top"),10),left:parseInt(p.element.css("left"),10)};if(h&&h.length){c(h[0]).css({width:o.width,height:o.height})}p._updateCache(o);p._propagate("resize",i)}})}});c.ui.plugin.add("resizable","containment",{start:function(f,r){var t=c(this).data("resizable"),j=t.options,l=t.element;var g=j.containment,k=(g instanceof c)?g.get(0):(/parent/.test(g))?l.parent().get(0):g;if(!k){return}t.containerElement=c(k);if(/document/.test(g)||g==document){t.containerOffset={left:0,top:0};t.containerPosition={left:0,top:0};t.parentData={element:c(document),left:0,top:0,width:c(document).width(),height:c(document).height()||document.body.parentNode.scrollHeight}}else{var n=c(k),i=[];c(["Top","Right","Left","Bottom"]).each(function(p,o){i[p]=b(n.css("padding"+o))});t.containerOffset=n.offset();t.containerPosition=n.position();t.containerSize={height:(n.innerHeight()-i[3]),width:(n.innerWidth()-i[1])};var q=t.containerOffset,e=t.containerSize.height,m=t.containerSize.width,h=(c.ui.hasScroll(k,"left")?k.scrollWidth:m),s=(c.ui.hasScroll(k)?k.scrollHeight:e);t.parentData={element:k,left:q.left,top:q.top,width:h,height:s}}},resize:function(g,q){var t=c(this).data("resizable"),i=t.options,f=t.containerSize,p=t.containerOffset,m=t.size,n=t.position,r=t._aspectRatio||g.shiftKey,e={top:0,left:0},h=t.containerElement;if(h[0]!=document&&(/static/).test(h.css("position"))){e=p}if(n.left<(t._helper?p.left:0)){t.size.width=t.size.width+(t._helper?(t.position.left-p.left):(t.position.left-e.left));if(r){t.size.height=t.size.width/i.aspectRatio}t.position.left=i.helper?p.left:0}if(n.top<(t._helper?p.top:0)){t.size.height=t.size.height+(t._helper?(t.position.top-p.top):t.position.top);if(r){t.size.width=t.size.height*i.aspectRatio}t.position.top=t._helper?p.top:0}t.offset.left=t.parentData.left+t.position.left;t.offset.top=t.parentData.top+t.position.top;var l=Math.abs((t._helper?t.offset.left-e.left:(t.offset.left-e.left))+t.sizeDiff.width),s=Math.abs((t._helper?t.offset.top-e.top:(t.offset.top-p.top))+t.sizeDiff.height);var k=t.containerElement.get(0)==t.element.parent().get(0),j=/relative|absolute/.test(t.containerElement.css("position"));if(k&&j){l-=t.parentData.left}if(l+t.size.width>=t.parentData.width){t.size.width=t.parentData.width-l;if(r){t.size.height=t.size.width/t.aspectRatio}}if(s+t.size.height>=t.parentData.height){t.size.height=t.parentData.height-s;if(r){t.size.width=t.size.height*t.aspectRatio}}},stop:function(f,n){var q=c(this).data("resizable"),g=q.options,l=q.position,m=q.containerOffset,e=q.containerPosition,i=q.containerElement;var j=c(q.helper),r=j.offset(),p=j.outerWidth()-q.sizeDiff.width,k=j.outerHeight()-q.sizeDiff.height;if(q._helper&&!g.animate&&(/relative/).test(i.css("position"))){c(this).css({left:r.left-e.left-m.left,width:p,height:k})}if(q._helper&&!g.animate&&(/static/).test(i.css("position"))){c(this).css({left:r.left-e.left-m.left,width:p,height:k})}}});c.ui.plugin.add("resizable","ghost",{start:function(g,h){var e=c(this).data("resizable"),i=e.options,f=e.size;e.ghost=e.originalElement.clone();e.ghost.css({opacity:0.25,display:"block",position:"relative",height:f.height,width:f.width,margin:0,left:0,top:0}).addClass("ui-resizable-ghost").addClass(typeof i.ghost=="string"?i.ghost:"");e.ghost.appendTo(e.helper)},resize:function(f,g){var e=c(this).data("resizable"),h=e.options;if(e.ghost){e.ghost.css({position:"relative",height:e.size.height,width:e.size.width})}},stop:function(f,g){var e=c(this).data("resizable"),h=e.options;if(e.ghost&&e.helper){e.helper.get(0).removeChild(e.ghost.get(0))}}});c.ui.plugin.add("resizable","grid",{resize:function(e,m){var p=c(this).data("resizable"),h=p.options,k=p.size,i=p.originalSize,j=p.originalPosition,n=p.axis,l=h._aspectRatio||e.shiftKey;h.grid=typeof h.grid=="number"?[h.grid,h.grid]:h.grid;var g=Math.round((k.width-i.width)/(h.grid[0]||1))*(h.grid[0]||1),f=Math.round((k.height-i.height)/(h.grid[1]||1))*(h.grid[1]||1);if(/^(se|s|e)$/.test(n)){p.size.width=i.width+g;p.size.height=i.height+f}else{if(/^(ne)$/.test(n)){p.size.width=i.width+g;p.size.height=i.height+f;p.position.top=j.top-f}else{if(/^(sw)$/.test(n)){p.size.width=i.width+g;p.size.height=i.height+f;p.position.left=j.left-g}else{p.size.width=i.width+g;p.size.height=i.height+f;p.position.top=j.top-f;p.position.left=j.left-g}}}}});var b=function(e){return parseInt(e,10)||0};var a=function(e){return !isNaN(parseInt(e,10))}})(jQuery);/*! * jQuery hashchange event - v1.3 - 7/21/2010 * http://benalman.com/projects/jquery-hashchange-plugin/ * @@ -58,11 +58,30 @@ * Dual licensed under the MIT and GPL licenses. * http://benalman.com/about/license/ */ -(function($,e,b){var c="hashchange",h=document,f,g=$.event.special,i=h.documentMode,d="on"+c in e&&(i===b||i>7);function a(j){j=j||location.href;return"#"+j.replace(/^[^#]*#?(.*)$/,"$1")}$.fn[c]=function(j){return j?this.bind(c,j):this.trigger(c)};$.fn[c].delay=50;g[c]=$.extend(g[c],{setup:function(){if(d){return false}$(f.start)},teardown:function(){if(d){return false}$(f.stop)}});f=(function(){var j={},p,m=a(),k=function(q){return q},l=k,o=k;j.start=function(){p||n()};j.stop=function(){p&&clearTimeout(p);p=b};function n(){var r=a(),q=o(m);if(r!==m){l(m=r,q);$(e).trigger(c)}else{if(q!==m){location.href=location.href.replace(/#.*/,"")+q}}p=setTimeout(n,$.fn[c].delay)}$.browser.msie&&!d&&(function(){var q,r;j.start=function(){if(!q){r=$.fn[c].src;r=r&&r+a();q=$('