Index: src/Makefile
===================================================================
RCS file: /cvs/kseries/kseries/sosse/src/Makefile,v
retrieving revision 1.1.1.1
retrieving revision 1.3
diff -u -p -r1.1.1.1 -r1.3
--- src/Makefile	8 Nov 2004 11:59:25 -0000	1.1.1.1
+++ src/Makefile	24 Nov 2004 15:19:09 -0000	1.3
@@ -5,16 +5,16 @@
 #   atmega161
 
 #ARCH=at90s2323
-#ARCH=at90s8515
+ARCH=at90s8515
 #ARCH=at90s8535
-ARCH=atmega161
+#ARCH=atmega161
 
 CC=avr-gcc -mmcu=$(ARCH)
 AS=avr-as
 OBJCOPY=avr-objcopy
 SIZE=avr-size
 
-CFLAGS=-Wall -I. -Os -mcall-prologues
+CFLAGS=-Wall -I. -Os -mcall-prologues -MMD
 ASFLAGS=-Wall -I.
 
 CSRC= \
@@ -91,3 +91,5 @@ clean-sosse:
 clean-eedata:
 	rm -rf eedata eedata.bin eedata.hex eedata.lst
 
+# Include dependencies
+-include $(OBJ:%.o=%.d)
Index: src/Makefile.emu
===================================================================
RCS file: /cvs/kseries/kseries/sosse/src/Makefile.emu,v
retrieving revision 1.1.1.1
retrieving revision 1.3
diff -u -p -r1.1.1.1 -r1.3
--- src/Makefile.emu	8 Nov 2004 11:59:25 -0000	1.1.1.1
+++ src/Makefile.emu	16 Nov 2004 17:36:31 -0000	1.3
@@ -2,7 +2,7 @@ CC=gcc
 AS=as
 OBJCOPY=objcopy
 
-CFLAGS=-Wall -I. -O6 -g -DDEBUG
+CFLAGS=-Wall -I. -O0 -ggdb -DDEBUG
 
 SRC=\
 	auth.c \
@@ -34,16 +34,16 @@ OBJ=\
 	tools.o \
 	transaction.o
 
-all: sosse fstest authtest
+all: sosse fstest #authtest
 
 sosse: $(OBJ) main.o
-	$(CC) $(CFLAGS) -o sosse-emu $(OBJ) main.o -L. -lsio
+	$(CC) $(CFLAGS) -o sosse-emu $(OBJ) main.o
 
 fstest: $(OBJ) fstest.o
-	$(CC) $(CFLAGS) -o fstest $(OBJ) fstest.o -L. -lsio
+	$(CC) $(CFLAGS) -o fstest $(OBJ) fstest.o -L.
 
 authtest: $(OBJ) authtest.o
-	$(CC) $(CFLAGS) -o authtest $(OBJ) authtest.o -L. -lsio
+	$(CC) $(CFLAGS) -o authtest $(OBJ) authtest.o -L.
 
 clean: clean-sosse clean-fstest clean-authtest
 	rm -rf core
Index: src/commands.c
===================================================================
RCS file: /cvs/kseries/kseries/sosse/src/commands.c,v
retrieving revision 1.1.1.1
retrieving revision 1.9
diff -u -p -r1.1.1.1 -r1.9
--- src/commands.c	8 Nov 2004 11:59:25 -0000	1.1.1.1
+++ src/commands.c	1 Dec 2004 17:45:58 -0000	1.9
@@ -41,7 +41,7 @@
 #include <types.h>
 
 #ifdef __AVR__
-#include <io.h>
+#include <avr/io.h>
 #endif /* __AVR__ */
 
 /*! \brief Valid data in response array. Invalid if zero. */
@@ -50,8 +50,13 @@ iu8 resplen;
 
 	The size of this array is the max. of sizeof(S_FINFO) and CRYPT_BLOCK_LEN.
 */
+
 iu8 response[8];
 
+#if CONF_32BIT_EEPROM==1
+eeprom_addr_t readadd=0L,writeadd=0L;
+#endif
+
 #if CONF_WITH_TESTCMDS==1
 void cmd_write( void )
 {
@@ -207,17 +212,20 @@ void cmd_create( void )
 		sw_set( SW_NOT_ALLOWED );
 		return;
 	}
-
+#if CONF_WITH_KEYAUTH==1
 	/* Correct permissions? */
 	if( !auth_checkAc( (fi.ac[0]>>4)&0x0F ) ) return;
-
+#endif
 	/* ACK */
 	t0_sendAck();
 
 	/* Receive */
 	t0_recBlock( (iu8 *)&fi, sizeof(S_FINFO) );
-
-	hton_us( &fi.size, 1 );
+#if CONF_32BIT_EEPROM==1
+	hton_ul( (iu32 *)&fi.size, 1 );
+#else
+	hton_us( (iu16 *)&fi.size, 1 );
+#endif
 	hton_us( &fi.fid, 1 );
 
 	if( !fs_create( &fi ) ) return;
@@ -246,10 +254,10 @@ void cmd_delete( void )
 		sw_set( SW_NOT_ALLOWED );
 		return;
 	}
-
+#if CONF_WITH_KEYAUTH==1
 	/* Correct permissions? */
 	if( !auth_checkAc( fi.ac[0]&0x0F ) ) return;
-
+#endif
 	/* ACK */
 	t0_sendAck();
 
@@ -374,11 +382,20 @@ void cmd_intAuth( void )
 }
 #endif /* CONF_WITH_KEYCMDS==1 */
 
+#if CONF_32BIT_EEPROM==1
+void cmd_setHighWord( eeprom_addr_t *address )
+{
+	if( !t0_testP3( 0 ) ) return;
+	*address = (*address&0x0000FFFFL)|(((eeprom_addr_t)header[2]<<24)|((eeprom_addr_t)header[3]<<16));
+	sw_set( SW_OK );
+}
+#endif /* CONF_32BIT_EEPROM==1 */
+
 void cmd_readBinary( void )
 {
 	S_FSTREAM fs;
 	S_FINFO fi;
-	iu16 i, max=header[4];
+	iu16 i,max=header[4];
 	iu8 b;
 
 	/* Get file data */
@@ -389,14 +406,19 @@ void cmd_readBinary( void )
 		sw_set( SW_NOT_ALLOWED );
 		return;
 	}
-
+#if CONF_WITH_KEYAUTH==1
 	/* Correct permissions? */
 	if( !auth_checkAc( fi.ac[0]&0x0F ) ) return;
+#endif
 
 	if( !max ) max=256;
 
-	/* Test file size */
+	/* Test file size */	
+#if CONF_32BIT_EEPROM==1
+	fs.pos=(readadd&0xFFFF0000L)|(((eeprom_addr_t)header[2]<<8)|header[3]);
+#else
 	fs.pos=((iu16)header[2]<<8)|header[3];
+#endif
 	if(fs.pos>fs.size) {
 		sw_set( SW_WRONG_REFERENCE );
 		return;
@@ -441,7 +463,11 @@ void cmd_select( void )
 	memcpy( &selected, &fp, sizeof(S_FPATH) );
 
 	resplen=sizeof(S_FINFO);
-	hton_us( &(fi->size), 1 );
+#if CONF_32BIT_EEPROM==1
+	hton_ul( (iu32 *)&(fi->size), 1 );
+#else
+	hton_us( (iu16 *)&(fi->size), 1 );
+#endif
 	hton_us( &(fi->fid), 1 );
 
 	sw_set( SW_AVAILABLE|sizeof(S_FINFO) );
@@ -467,12 +493,18 @@ void cmd_updateBinary( void )
 		sw_set( SW_NOT_ALLOWED );
 		return;
 	}
-
+	
+ #if CONF_WITH_KEYAUTH==1
 	/* Correct permissions? */
 	if( !auth_checkAc( (fi.ac[0]>>4)&0x0F ) ) return;
+	#endif
 
 	/* Test file size */
+#if CONF_32BIT_EEPROM==1
+	fs.pos=(writeadd&0xFFFF0000L)|(((eeprom_addr_t)header[2]<<8)|header[3]);
+#else
 	fs.pos=((iu16)header[2]<<8)|header[3];
+#endif
 	if(fs.pos>fs.size) {
 		sw_set( SW_WRONG_REFERENCE );
 		return;
Index: src/commands.h
===================================================================
RCS file: /cvs/kseries/kseries/sosse/src/commands.h,v
retrieving revision 1.1.1.1
retrieving revision 1.5
diff -u -p -r1.1.1.1 -r1.5
--- src/commands.h	8 Nov 2004 11:59:25 -0000	1.1.1.1
+++ src/commands.h	2 Dec 2004 16:47:00 -0000	1.5
@@ -28,6 +28,7 @@
 
 #ifndef SOSSE_COMMANDS_H
 #define SOSSE_COMMANDS_H
+#include <config.h>
 
 #define CLA_PROP			0x80	//!< CLA byte: Proprietary
 
@@ -48,6 +49,21 @@
 #define INS_UPDATE_BINARY	0xD6	//!< INS byte: Update Binary
 #define INS_VERIFY_KEY		0x2A	//!< INS byte: Verify Key
 #define INS_VERIFY_PIN		0x20	//!< INS byte: Verify PIN
+#if CONF_32BIT_EEPROM==1
+#define INS_SET_READ_HIGH_WORD	0xB8	//!< INS byte: Set Read High word
+#define INS_SET_WRITE_HIGH_WORD	0xD8	//!< INS byte: Set Write High word
+
+#include <hal.h>
+extern eeprom_addr_t readadd,writeadd;
+/*! \brief Set high word for 32 bit EEPROM.
+*/
+#define cmd_setReadHighWord()	cmd_setHighWord( &readadd )
+/*! \brief Set high word for 32 bit EEPROM.
+*/
+#define cmd_setWriteHighWord()	cmd_setHighWord( &writeadd )
+
+void cmd_setHighWord( eeprom_addr_t * );
+#endif
 
 /*! \brief Valid data in response array. Invalid if zero. */
 extern iu8 resplen;
Index: src/config.h
===================================================================
RCS file: /cvs/kseries/kseries/sosse/src/config.h,v
retrieving revision 1.1.1.1
retrieving revision 1.8
diff -u -p -r1.1.1.1 -r1.8
--- src/config.h	8 Nov 2004 11:59:25 -0000	1.1.1.1
+++ src/config.h	27 Jan 2005 18:03:05 -0000	1.8
@@ -35,9 +35,17 @@
 */
 #define CONF_WITH_FILESYSTEM	1
 
+/*! \brief En-/disables eeprom cancellation when creating/deleting file.
+*/
+#define CONF_ERASE_EEPROM 0
+
+/*! \brief Select type of eeprom addressing: 0=16bit, 1=32bit.
+*/
+#define CONF_32BIT_EEPROM 1
+
 /*! \brief En-/disables transactions.
 */
-#define CONF_WITH_TRANSACTIONS	1
+#define CONF_WITH_TRANSACTIONS	0
 
 /*! \brief En-/disables test commands.
 
@@ -58,27 +66,27 @@
 	If set to 1, functions to set and test PIN and PUK are included. This is a
 	requirement for CONF_WITH_PINCMDS.
 */
-#define CONF_WITH_PINAUTH		1
+#define CONF_WITH_PINAUTH		0
 
 /*! \brief En-/disables PIN commands.
 
 	If set to 1, commands CHANGE PIN and VERIFY PIN are included.
 */
-#define CONF_WITH_PINCMDS		1
+#define CONF_WITH_PINCMDS		0
 
 /*! \brief En-/disables key authentication functions.
 
 	If set to 1, functions impelementing calculations with challenges are
 	included. This is a requirement for CONF_WITH_KEY_CMDS.
 */
-#define CONF_WITH_KEYAUTH		1
+#define CONF_WITH_KEYAUTH		0
 
 /*! \brief En-/disables key related commands.
 
 	If set to 1, commands EXTERNAL KEYENTIFICATION, GET CHALLENGE,
 	INTERNAL KEYENTIFICATION and VERIFY KEY are included.
 */
-#define CONF_WITH_KEYCMDS		1
+#define CONF_WITH_KEYCMDS		0
 
 /*! \brief En-/disables support for the external I2C EEPROM.
 */
@@ -89,13 +97,13 @@
 	If set to 1, support for decryption side of the cryptographic algorithms
 	are included.
 */
-#define CONF_WITH_DECRYPT		1
+#define CONF_WITH_DECRYPT		0
 
 /*! \brief En-/disables support for logging.
 
 	If set to 1, support for logging is included.
 */
-#define CONF_WITH_LOGGING		1
+#define CONF_WITH_LOGGING		0
 
 /*! \brief En-/disables return code manager.
 
@@ -241,7 +249,7 @@
 //! Chip ID.
 #define CHIP				0x01
 //! External EEPROM ID.
-#define ESIZ				0x03
+#define ESIZ				0x07 /* put 0x05 for funcard 4 (256kbit) */
 //! AVR architecture. Needed for assembler.
 #define ARCH				avr2
 #elif defined(__AVR_AT90S8535__)
Index: src/eedata.S
===================================================================
RCS file: /cvs/kseries/kseries/sosse/src/eedata.S,v
retrieving revision 1.1.1.1
retrieving revision 1.7
diff -u -p -r1.1.1.1 -r1.7
--- src/eedata.S	8 Nov 2004 11:59:25 -0000	1.1.1.1
+++ src/eedata.S	27 Jan 2005 16:26:33 -0000	1.7
@@ -12,7 +12,7 @@
 	; T0:		AA	- TB1/TD1 follows,  historical bytes
 	; TB1:		00	- no Vpp
 	; TD1:		40	- TC2 follows
-	; TC2:		0A	- WI (1 second)
+	; TC2:		20	- WI (1 second)
 	; T1-T5:	53 4F 53 53 45	- "SOSSE"
 	; T6-T8:	02 03 25	- BCD coded date
 	; T9:		01	- Chip type
@@ -29,6 +29,8 @@
 	;				  03: 64k bit
 	;				  04: 128k bit
 	;				  05: 256k bit
+	;				  06: 512k bit
+	;				  07: 1024k bit
 	;				  FF: unspec.
 	.byte	0x3B, 0xAA, 0x00, 0x40, 0x20, 0x53, 0x4F, 0x53
 	.byte	0x53, 0x45, YEAR, MONTH, DAY, CHIP, ESIZ, 0x00
@@ -70,10 +72,44 @@
 ; PUK_RETCNTR_ADDR
 	.byte	0x0A
 #else /* CONF_WITH_FILESYSTEM==1 */
+#if CONF_32BIT_EEPROM==1
 ; FS_START_PTR
-	.byte	0x5C, 0x00
+	.byte	0x5E, 0x00, 0x00, 0x00
 ; *FS_START_PTR
-	.byte	0x00, 0x02, 0x00, 0x3F, 0x38, 0x00
+#if ESIZ==0x07
+	.byte	0xA2, 0x01, 0x02, 0x00, 0x00, 0x3F, 0x38, 0x00 ;1024kbit eeprom
+#else
+	#if ESIZ==0x05
+	.byte	0xA2, 0x81, 0x00, 0x00, 0x00, 0x3F, 0x38, 0x00 ;32kbit eeprom
+	#else 
+		#error Master file for this eeprom size not defined!
+	#endif
+
+#endif /* ESIZ */
+
+	; Ext Auth key file
+	.byte	0x11, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x2F
+	.byte	0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF
+	.byte	0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF
+	.byte	0x0A
+	; Int Auth key file
+	.byte	0x11, 0x00, 0x00, 0x00, 0x01, 0xFF, 0x00, 0x2F
+	.byte	0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF
+	.byte	0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF
+	.byte	0x0A
+	; PIN file
+	.byte	0x12, 0x00, 0x00, 0x00, 0x02, 0xFF, 0x00, 0x2F
+	.byte	0x31, 0x32, 0x33, 0x34, 0x31, 0x32, 0x33, 0x34
+	.byte	0x03
+	.byte	0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38
+	.byte	0x0A
+	; Empty entry
+	.byte	0x00, 0x00, 0x00, 0x00
+#else /* CONF_32BIT_EEPROM!=1 */
+; FS_START_PTR
+	.byte	0x5C, 0x00,
+; *FS_START_PTR
+	.byte	0x00, 0x82, 0x00, 0x3F, 0x38, 0x00
 	; Ext Auth key file
 	.byte	0x11, 0x00, 0x00, 0xFF, 0x00, 0x2F
 	.byte	0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF
@@ -92,5 +128,7 @@
 	.byte	0x0A
 	; Empty entry
 	.byte	0x00, 0x00
+#endif /* CONF_32BIT_EEPROM */
+
 #endif /* CONF_WITH_FILESYSTEM==1 */
 
Index: src/eepromi2c.S
===================================================================
RCS file: /cvs/kseries/kseries/sosse/src/eepromi2c.S,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -p -r1.1.1.1 -r1.2
--- src/eepromi2c.S	8 Nov 2004 11:59:25 -0000	1.1.1.1
+++ src/eepromi2c.S	7 Dec 2004 18:03:09 -0000	1.2
@@ -11,8 +11,15 @@ PORTB=0x18
 	.global xeread, xewrt
 XEAddr:
 	rcall  XEStrt
+#if CONF_32BIT_EEPROM==1
+	ldi    r19,0x28
+	rol    r19
+	clc
+	rol    r19
+#else
 	clc
 	ldi	   r19,0xA0
+#endif	
 	rcall  XEEOut
 	rcall  XE0Bit
 	mov	   r19,r31
@@ -22,9 +29,13 @@ XEAddr:
 	rcall  XEEOut
 	rcall  XE0Bit
 	ret
-
+;#if CONF_32BIT_EEPROM==1
+; address r25:r24:r23:r22
+; result r25(=0):r24
+;#else
 ; address r25:r24 
 ; result r25(=0):r24
+;#endif
 xeread:
 	push	r31
 	push	r30
@@ -33,8 +44,14 @@ xeread:
 	push	r16
 	push	r1
 	push	r0
-	mov	r31,r25
+#if CONF_32BIT_EEPROM==1
+	mov	r31,r23
+	mov	r30,r22
+	ror	r24
+#else
+	mov r31,r25
 	mov	r30,r24
+#endif
 ; Start
 	rcall	xereadlocal
 ; Done
@@ -62,9 +79,13 @@ xereadlocal:
 	rcall	XE1Bit
 	rcall	XEStop
 	ret
-
+;#if CONF_32BIT_EEPROM==1
+; address r25:r24:r23:r22
+; byte r21(=0):r20
+;#else
 ; address r25:r24 
 ; byte r23(=0):r22
+;#endif
 xewrt:
 	push	r31
 	push	r30
@@ -73,6 +94,23 @@ xewrt:
 	push	r16
 	push	r1
 	push	r0
+#if CONF_32BIT_EEPROM==1
+	push	r17
+	mov	r31,r23
+	mov	r30,r22
+	mov	r17,r24
+	ror	r17
+; Start
+; address r31:r30 
+; result XE(Z+) = r20
+	rcall	xereadlocal
+	cp	r0,r20
+	breq	dontwrite
+	mov	r17,r24
+	ror	r17
+	rcall	XEAddr
+	mov	r19,r20
+#else
 	mov	r31,r25
 	mov	r30,r24
 ; Start
@@ -83,12 +121,16 @@ xewrt:
 	breq	dontwrite
 	rcall	XEAddr
 	mov	r19,r22
+#endif
 	rcall	XEEOut
 	rcall	XE0Bit
 	rcall	XEStop
 	rcall	XEDly
 dontwrite: 
 ; Done
+#if CONF_32BIT_EEPROM==1
+	pop	r17
+#endif
 	pop	r0
 	pop	r1
 	pop	r16
Index: src/fs.c
===================================================================
RCS file: /cvs/kseries/kseries/sosse/src/fs.c,v
retrieving revision 1.1.1.1
retrieving revision 1.11
diff -u -p -r1.1.1.1 -r1.11
--- src/fs.c	8 Nov 2004 11:59:25 -0000	1.1.1.1
+++ src/fs.c	26 Nov 2004 18:26:47 -0000	1.11
@@ -32,10 +32,16 @@
 #include <transaction.h>
 #include <types.h>
 
+#if CONF_32BIT_EEPROM==1
+ #define ERASE_MASK 0xFFFFFFFFL
+#else 
+ #define ERASE_MASK 0xFFFF
+#endif
+
 //! Start address of the MF file header.
-iu16 fsstart;
+eeprom_addr_t fsstart;
 //! Size of the content area of the MF.
-iu16 fssize;
+eeprom_addr_t fssize;
 
 S_FPATH selected;
 
@@ -66,14 +72,14 @@ bool fs_seek( iu16 fid, S_FSTREAM *fs, S
 		return TRUE;
 	}
 
-	while( fstream_read( fs, (iu8 *)fi, sizeof(iu16) ) ) {
-		//fs->pos-=sizeof(iu16);
+	while( fstream_read( fs, (iu8 *)fi, sizeof(fi->size) ) ) {
+		//fs->pos-=sizeof(fi->size);
 		if( !fi->size ) {
 			sw_set( SW_FILE_NOT_FOUND );
 			return FALSE;
 		}
-		if( !fstream_read( fs, (iu8 *)fi+sizeof(iu16),
-			sizeof(S_FINFO)-sizeof(iu16) ) ) break;
+		if( !fstream_read( fs, (iu8 *)fi+sizeof(fi->size),
+			sizeof(S_FINFO)-sizeof(fi->size) ) ) break;
 
 		if( fid==fi->fid ) {
 			if( fi->type!=type ) {
@@ -98,10 +104,10 @@ bool fs_seekEnd( S_FSTREAM *fs )
 {
 	S_FINFO fi;
 
-	while( fstream_read( fs, (iu8 *)&fi, sizeof(iu16) ) ) {
-		fs->pos-=sizeof(iu16);
+	while( fstream_read( fs, (iu8 *)&fi, sizeof(fi.size) ) ) {
+		fs->pos-=sizeof(fi.size);
 		/* Test also for erased cells. */
-		if( (!fi.size) || (fi.size==0xFFFF) ) {
+		if( (!fi.size) || (fi.size==ERASE_MASK) ) {
 			return TRUE;
 		}
 		if( !fstream_read( fs, (iu8 *)&fi, sizeof(S_FINFO) ) ) break;
@@ -115,12 +121,12 @@ bool fs_seekEnd( S_FSTREAM *fs )
 bool fs_getData( S_FPATH *fp, S_FSTREAM *fs, S_FINFO *fi )
 {
 	fs->start=fsstart;
-	fs->size=fssize+6;
+	fs->size=fssize+sizeof(S_FINFO);
 	fs->pos=0;
 
 	if( !fstream_read( fs, (iu8 *)fi, sizeof(S_FINFO) ) ) return FALSE;
 
-	fs->start=fsstart+FS_HEADER_SIZE;
+	fs->start=fsstart+sizeof(S_FINFO);
 	fs->size=fssize;
 	fs->pos=0;
 
@@ -141,8 +147,14 @@ bool fs_getFPath( iu16 fid, S_FPATH *fp,
 		return FALSE;
 	}
 
-	fp->df=selected.df;
-	fp->ef=fid;
+ if( fid==0x3F00 ) {
+		fp->ef=0xFFFF;
+		fp->df=0xFFFF;
+	}
+	else {
+		fp->df=selected.df;
+		fp->ef=fid;
+	}
 
 	if( !fs_getData( fp, &fstmp, &fitmp ) ) {
 		fp->df=fid;
@@ -153,7 +165,8 @@ bool fs_getFPath( iu16 fid, S_FPATH *fp,
 		}
 	}
 
-	if( fp->df==0x3F00 ) fp->df=0xFFFF;
+	/* if( fp->df==0x3F00 ) fp->df=0xFFFF; */
+
 	if( fs!=NULL ) memcpy( fs, &fstmp, sizeof(fstmp) );
 	if( fi!=NULL ) memcpy( fi, &fitmp, sizeof(fitmp) );
 
@@ -165,9 +178,9 @@ bool fs_delete( iu16 fid )
 	S_FPATH fp;
 	S_FSTREAM fs;
 	S_FINFO fi;
-	iu16 size, dfend;
+	eeprom_addr_t size, dfend;
 
-	if( (selected.ef!=0xFFFF) || (fid==0xFFFF) ) {
+	if( (selected.ef!=0xFFFF) || (fid==0xFFFF) || (fid==0x3F00) ) {
 		sw_set( SW_NOT_ALLOWED );
 		return FALSE;
 	}
@@ -190,12 +203,12 @@ bool fs_delete( iu16 fid )
 		if( !fs_getData( &fp, &fs, &fi ) ) return FALSE;
 	}
 
-	/* Less then 6 bytes empty after file? Then this must be the last file. */
-	if( fs.start+fs.size+FS_HEADER_SIZE<=dfend ) {
+	/* Less then 8 bytes empty after file? Then this must be the last file. */
+	if( fs.start+fs.size+sizeof(S_FINFO)<=dfend ) {
 		fs.pos=fs.size;
-		fs.size+=sizeof(iu16);
-		if( !fstream_read( &fs, (iu8 *)&size, sizeof(iu16) ) ) return FALSE;
-		fs.size-=sizeof(iu16);
+		fs.size+=sizeof(fi.size);
+		if( !fstream_read( &fs, (iu8 *)&size, sizeof(fi.size) ) ) return FALSE;
+		fs.size-=sizeof(fi.size);
 
 		if( size ) {
 			sw_set( SW_INCOMPATIBLE_FILE );
@@ -204,23 +217,23 @@ bool fs_delete( iu16 fid )
 	}
 
 	fs.pos=0;
-
-	/* Clear content */
 	memset( &fi, 0xFF, sizeof(fi) );
+#if CONF_ERASE_EEPROM==1
+	/* Clear content */
 	while( fs.pos<fs.size ) {
 		size=(fs.size-fs.pos)<sizeof(fi) ? fs.size-fs.pos : sizeof(fi);
-
 		if( !fstream_write( &fs, (iu8*)&fi, size ) ) return FALSE;
 	}
+#endif /* !CONF_ERASE_EEPROM==1 */
 
 	/*  file header */
 #if CONF_WITH_TRANSACTIONS==1
-	fs.start-=FS_HEADER_SIZE;
+	fs.start-=sizeof(S_FINFO);
 	fi.size=0;
 	if( !( ta_setdata( (iu8*)&fi, sizeof(S_FINFO), fs.start ) &&
 		ta_commit() ) ) return FALSE;
 #else /* !CONF_WITH_TRANSACTIONS==1 */
-	fs.start-=FS_HEADER_SIZE;
+	fs.start-=sizeof(S_FINFO);
 	fi.size=0;
 	fs.pos=0;
 	if( !fstream_write( &fs, (iu8 *)&fi, sizeof(S_FINFO) ) ) return FALSE;
@@ -234,14 +247,18 @@ bool fs_create( S_FINFO *fi )
 	S_FPATH fp;
 	S_FSTREAM fs;
 	S_FINFO fitmp;
-	iu8 size, dfend;
+#if CONF_ERASE_EEPROM==1
+	eeprom_addr_t size, dfend;
+#else
+	eeprom_addr_t dfend;
+#endif /* CONF_ERASE_EEPROM==1 */
 
 	if( fi->fid==0x3F00 ) {
 		sw_set( SW_FILE_EXISTS );
 		return FALSE;
 	}
 
-	if( (!fi->size) || (fi->size>0x7FFF) || (fi->fid==0xFFFF) ||
+	if( (!fi->size) || (fi->fid==0xFFFF) ||
 		((fi->type!=FS_TYPE_DF) && (fi->type!=FS_TYPE_EF)) ) {
 		sw_set( SW_WRONG_DATA );
 		return FALSE;
@@ -262,6 +279,7 @@ bool fs_create( S_FINFO *fi )
 	dfend = fs.start+fs.size;
 
 	/* Look if file exists already */
+	/*
 	if( fi->type==FS_TYPE_DF )
 		fp.df=fi->fid;
 	else
@@ -269,10 +287,21 @@ bool fs_create( S_FINFO *fi )
 	if( fs_getData( &fp, &fs, &fitmp ) ) {
 		sw_set( SW_FILE_EXISTS );
 		return FALSE;
+	}*/
+	fp.df=fi->fid;
+	if( fs_getData( &fp, &fs, &fitmp ) ) {
+		sw_set( SW_FILE_EXISTS );
+		return FALSE;
+	}
+	fp.df=selected.df;
+	fp.ef=fi->fid;
+	if( fs_getData( &fp, &fs, &fitmp ) ) {
+		sw_set( SW_FILE_EXISTS );
+		return FALSE;
 	}
 
 	/* Begin with MF */
-	fs.start=fsstart+FS_HEADER_SIZE;
+	fs.start=fsstart+sizeof(S_FINFO);
 	fs.size=fssize;
 	fs.pos=0;
 
@@ -283,16 +312,17 @@ bool fs_create( S_FINFO *fi )
 	/* Seek to free data */
 	if( !fs_seekEnd( &fs ) ) return FALSE;
 
-	if( (fs.pos+FS_HEADER_SIZE+fi->size+sizeof(iu16))>fs.size ) {
+	if( (fs.pos+sizeof(S_FINFO)+fi->size+sizeof(fi->size))>fs.size ) {
 		sw_set( SW_FILE_TO_SHORT );
 		return FALSE;
 	}
 
 	/* Set fs to file dimensions. */
 	fs.start+=fs.pos;
-	fs.size=FS_HEADER_SIZE+fi->size+sizeof(iu16);
-	fs.pos=sizeof(iu16);
+	fs.size=sizeof(S_FINFO)+fi->size+sizeof(fi->size);
+	fs.pos=sizeof(fi->size);
 
+#if CONF_ERASE_EEPROM==1
 	/* Clear all */
 	memset( &fitmp, 0, sizeof(fitmp) );
 	while( fs.pos<fs.size ) {
@@ -300,6 +330,13 @@ bool fs_create( S_FINFO *fi )
 
 		if( !fstream_write( &fs, (iu8*)&fitmp, size ) ) return FALSE;
 	}
+#else
+	/* Clear only file terminator */
+	memset( &fitmp, 0, sizeof(fitmp.size) );
+	fs.pos=fs.size-sizeof(fitmp.size);
+	if( !fstream_write( &fs, (iu8*)&fitmp, sizeof(fitmp.size) ) ) return FALSE;
+#endif /* CONF_ERASE_EEPROM==1 */
+
 
 	/* Write file header */
 #if CONF_WITH_TRANSACTIONS==1
Index: src/fs.h
===================================================================
RCS file: /cvs/kseries/kseries/sosse/src/fs.h,v
retrieving revision 1.1.1.1
retrieving revision 1.4
diff -u -p -r1.1.1.1 -r1.4
--- src/fs.h	8 Nov 2004 11:59:25 -0000	1.1.1.1
+++ src/fs.h	26 Nov 2004 18:26:47 -0000	1.4
@@ -70,10 +70,10 @@ typedef struct s_fpath {
 	file system.
 */
 typedef struct s_finfo {
-	iu16 size;	//!< Size of the file content.
-	iu16 fid;		//!< ID of the file.
-	iu8 type;		//!< Type of the file. (FS_TYPE_*)
-	iu8 ac[1];	//!< Access conditions of the file. (See CREATE FILE dox.)
+	eeprom_addr_t size;	//!< Size of the file content.
+	iu16          fid;		//!< ID of the file.
+	iu8           type;		//!< Type of the file. (FS_TYPE_*)
+	iu8           ac[1];	//!< Access conditions of the file. (See CREATE FILE dox.)
 } S_FINFO;
 
 //! File type DF
@@ -82,7 +82,7 @@ typedef struct s_finfo {
 #define FS_TYPE_EF	0x00
 
 //! Size of the file header, which is the same as S_FINFO.
-#define FS_HEADER_SIZE	sizeof(S_FINFO)
+//#define FS_HEADER_SIZE	sizeof(S_FINFO)
 
 /*! \brief Path specified of the currently selected file.
 
Index: src/fstest.c
===================================================================
RCS file: /cvs/kseries/kseries/sosse/src/fstest.c,v
retrieving revision 1.1.1.1
retrieving revision 1.7
diff -u -p -r1.1.1.1 -r1.7
--- src/fstest.c	8 Nov 2004 11:59:25 -0000	1.1.1.1
+++ src/fstest.c	26 Nov 2004 18:26:47 -0000	1.7
@@ -24,13 +24,14 @@
 */
 
 #include <stdio.h>
+#include <string.h>
 
 #include <auth.h>
 #include <fs.h>
 #include <fstream.h>
 #include <hal.h>
 
-extern iu16 fsstart, fssize;
+extern eeprom_addr_t fsstart, fssize;
 extern iu8 authstate;
 
 int main( int argc, char *argv[] )
@@ -41,7 +42,8 @@ int main( int argc, char *argv[] )
 	S_FSTREAM fs;
 	S_FPATH fp;
 	S_FINFO fi;
-	int i, ret=1;
+	int ret=1;
+	unsigned long i;
 
 #if 0
 	printf( "hal_init()\n" );
@@ -51,21 +53,21 @@ int main( int argc, char *argv[] )
 	printf( "fs_init()\n" );
 	if( !fs_init() ) goto reterror;
 
-	printf( "fsstart=%.4X\n", fsstart );
-	printf( "fssize=%.4X\n", fssize );
+	printf( "fsstart=%.8X\n", fsstart );
+	printf( "fssize=%.8X\n", fssize );
 
 	printf( "fs_getFPath( 0x3F00, &fp, &fs, &fi )\n" );
 	if( !fs_getFPath( 0x3F00, &fp, &fs, &fi ) ) goto reterror;
 
 	printf( "fp.df=%.4X\n", fp.df );
 	printf( "fp.ef=%.4X\n", fp.ef );
-	printf( "fi.size=%.4X\n", fi.size );
+	printf( "fi.size=%.8X\n", (int)fi.size );
 	printf( "fi.fid=%.4X\n", fi.fid );
 	printf( "fi.type=%.2X\n", fi.type );
 	printf( "fi.ac[0]=%.2X\n", fi.ac[0] );
-	printf( "fs.start=%.4X\n", fs.start );
-	printf( "fs.size=%.4X\n", fs.size );
-	printf( "fs.pos=%.4X\n", fs.pos );
+	printf( "fs.start=%.8X\n", (int)fs.start );
+	printf( "fs.size=%.8X\n", (int)fs.size );
+	printf( "fs.pos=%.8X\n", (int)fs.pos );
 
 	printf( "fs_create( {20, 0x1234, FS_TYPE_EF, 0x00} )\n" );
 	if( !fs_create( &ef ) ) goto reterror;
@@ -75,13 +77,13 @@ int main( int argc, char *argv[] )
 
 	printf( "fp.df=%.4X\n", fp.df );
 	printf( "fp.ef=%.4X\n", fp.ef );
-	printf( "fi.size=%.4X\n", fi.size );
+	printf( "fi.size=%.8X\n", (int)fi.size );
 	printf( "fi.fid=%.4X\n", fi.fid );
 	printf( "fi.type=%.2X\n", fi.type );
 	printf( "fi.ac[0]=%.2X\n", fi.ac[0] );
-	printf( "fs.start=%.4X\n", fs.start );
-	printf( "fs.size=%.4X\n", fs.size );
-	printf( "fs.pos=%.4X\n", fs.pos );
+	printf( "fs.start=%.8X\n", (int)fs.start );
+	printf( "fs.size=%.8X\n", (int)fs.size );
+	printf( "fs.pos=%.8X\n", (int)fs.pos );
 
 	printf( "fstream_write( &fs, {0x12,0x34,0x56} , 3 )\n" );
 	if( !fstream_write( &fs, "\x12\x34\x56" , 3 ) ) goto reterror;
@@ -92,33 +94,33 @@ int main( int argc, char *argv[] )
 	if( !fstream_read( &fs, buf , 3 ) ) goto reterror;
 	printf( "%.2X %.2X %.2X\n", buf[0], buf[1], buf[2] );
 
-	printf( "fs.start=%.4X\n", fs.start );
-	printf( "fs.size=%.4X\n", fs.size );
-	printf( "fs.pos=%.4X\n", fs.pos );
+	printf( "fs.start=%.8X\n", (int)fs.start );
+	printf( "fs.size=%.8X\n", (int)fs.size );
+	printf( "fs.pos=%.8X\n", (int)fs.pos );
 
 	printf( "fstream_read( &fs, buf , 17 )\n" );
 	if( fstream_read( &fs, buf , 17 ) ) goto reterror;
 
-	printf( "fs.start=%.4X\n", fs.start );
-	printf( "fs.size=%.4X\n", fs.size );
-	printf( "fs.pos=%.4X\n", fs.pos );
+	printf( "fs.start=%.8X\n", (int)fs.start );
+	printf( "fs.size=%.8X\n", (int)fs.size );
+	printf( "fs.pos=%.8X\n", (int)fs.pos );
 
 	selected.ef=0xFFFF;
 	printf( "fs_create( {20, 0x1235, FS_TYPE_EF, 0x00} )\n" );
 	ef.fid=0x1235;
 	if( !fs_create( &ef ) ) goto reterror;
 
-	printf( "fs_create( {600, 0x1236, FS_TYPE_EF, 0x00} )\n" );
+ printf( "fs_create( {600, 0x1236, FS_TYPE_EF, 0x00} )\n" );
 	ef.fid=0x1236;
-	ef.size=600;
+	ef.size=0xb000;
 	if( fs_create( &ef ) ) goto reterror;
 
-	printf( "fs_delete( 0x1235 )\n" );
-	if( !fs_delete( 0x1235 ) ) goto reterror;
-
 	printf( "fs_delete( 0x1236 )\n" );
 	if( fs_delete( 0x1236 ) ) goto reterror;
 
+	printf( "fs_delete( 0x1235 )\n" );
+	if( !fs_delete( 0x1235 ) ) goto reterror;
+
 	printf( "fs_delete( 0x1234 )\n" );
 	if( !fs_delete( 0x1234 ) ) goto reterror;
 
@@ -127,7 +129,7 @@ int main( int argc, char *argv[] )
 	ef.size=60;
 	ef.type=FS_TYPE_DF;
 	if( !fs_create( &ef ) ) goto reterror;
-
+#if CONF_WITH_KEYAUTH==1
 	authstate=0;
 	printf( "auth_checkAc(AUTH_AC_ALW)\n" );
 	if( !auth_checkAc(AUTH_AC_ALW) ) goto reterror;
@@ -143,20 +145,20 @@ int main( int argc, char *argv[] )
 	authstate=0;
 	printf( "auth_checkAc(AUTH_AC_ADM)\n" );
 	if( auth_checkAc(AUTH_AC_ADM) ) goto reterror;
-
+#endif
 	printf( "fs_getData( &fp, &fs, &fi )\n" );
 	fp.df=fp.ef=0xFFFF;
 	memset( &fi, 0, sizeof(fi) );
 	if( !fs_getData( &fp, &fs, &fi ) ) goto reterror;
 	printf( "fp.df=%.4X\n", fp.df );
 	printf( "fp.ef=%.4X\n", fp.ef );
-	printf( "fi.size=%.4X\n", fi.size );
+	printf( "fi.size=%.8X\n", (int)fi.size );
 	printf( "fi.fid=%.4X\n", fi.fid );
 	printf( "fi.type=%.2X\n", fi.type );
 	printf( "fi.ac[0]=%.2X\n", fi.ac[0] );
-	printf( "fs.start=%.4X\n", fs.start );
-	printf( "fs.size=%.4X\n", fs.size );
-	printf( "fs.pos=%.4X\n", fs.pos );
+	printf( "fs.start=%.8X\n", (int)fs.start );
+	printf( "fs.size=%.8X\n", (int)fs.size );
+	printf( "fs.pos=%.8X\n", (int)fs.pos );
 
 	ret = 0;
 
Index: src/fstream.h
===================================================================
RCS file: /cvs/kseries/kseries/sosse/src/fstream.h,v
retrieving revision 1.1.1.1
retrieving revision 1.3
diff -u -p -r1.1.1.1 -r1.3
--- src/fstream.h	8 Nov 2004 11:59:25 -0000	1.1.1.1
+++ src/fstream.h	26 Nov 2004 18:26:47 -0000	1.3
@@ -33,13 +33,15 @@
 #ifndef SOSSE_FSTREAM_H
 #define SOSSE_FSTREAM_H
 
+#include <hal.h>  // for eeprom_addr_t
 #include <types.h>
 
+
 //! Stream struct.
 typedef struct s_fstream {
-	iu16 start;	//!< EEPROM start address of the stream.
-	iu16 size;	//!< Data size of the stream.
-	iu16 pos;		//!< Current position in the stream.
+	eeprom_addr_t start;	//!< EEPROM start address of the stream.
+	eeprom_addr_t size;	//!< Data size of the stream.
+	eeprom_addr_t pos;		//!< Current position in the stream.
 } S_FSTREAM;
 
 /*! \brief Read data from a stream.
Index: src/hal-emu.c
===================================================================
RCS file: /cvs/kseries/kseries/sosse/src/hal-emu.c,v
retrieving revision 1.1.1.1
retrieving revision 1.7
diff -u -p -r1.1.1.1 -r1.7
--- src/hal-emu.c	8 Nov 2004 11:59:25 -0000	1.1.1.1
+++ src/hal-emu.c	26 Nov 2004 18:26:47 -0000	1.7
@@ -27,7 +27,9 @@
 #if defined(CTAPI)
 #include <ctapi.h>
 #endif
+#if defined(USE_SIO)
 #include <sio/sio.h>
+#endif
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -42,7 +44,13 @@
 
 #define PORT "/dev/ttyS0"
 
-iu8 eeprom[1*1024] = {
+#if CONF_32BIT_EEPROM==1
+	typedef iu32 eeprom_addr_t;
+#else
+	typedef iu16 eeprom_addr_t;
+#endif
+
+iu8 eeprom[0x8200L] = {
 	/* CARD_STATE_ADDR */
 	0x00,
 	/* ATR_LEN_ADDR */
@@ -83,11 +91,37 @@ iu8 eeprom[1*1024] = {
 	/* PUK_RETCNTR_ADDR */
 	0x0A,
 #endif
+#if CONF_32BIT_EEPROM==1
+	/* Beginning here is the FS data little endian */
+	/* FS_START_PTR_ADDR */
+    (FS_START_PTR_ADDR+4)&0xFF, (FS_START_PTR_ADDR+4)>>8, (FS_START_PTR_ADDR+4)>>16, (FS_START_PTR_ADDR+4)>>24,
+ /* MF */
+    0x00, 0x82, 0x00, 0x00, 0x00, 0x3F, 0x38, 0x00,
+    /* Ext Auth key file */
+    0x11, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x2F,
+    0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
+    0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
+    0x0A,
+    /* Int Auth key file */
+    0x11, 0x00, 0x00, 0x00, 0x01, 0xFF, 0x00, 0x2F,
+    0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
+    0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
+    0x0A,
+    /* PIN file */
+    0x12, 0x00, 0x00, 0x00, 0x02, 0xFF, 0x00, 0x2F,
+    0x31, 0x32, 0x33, 0x34, 0x31, 0x32, 0x33, 0x34,
+    0x03,
+    0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38,
+    0x0A,
+    /* Empty entry */
+    0x00, 0x00, 0x00, 0x00
+};
+#else /* CONF_32BIT_EEPROM!=1 */
 	/* Beginning here is the FS data little endian */
 	/* FS_START_PTR_ADDR */
     (FS_START_PTR_ADDR+2)&0xFF, (FS_START_PTR_ADDR+2)>>8,
-	/* MF */
-	0x00, 0x02, 0x00, 0x3F, 0x38, 0x00,
+ /* MF */
+    0x00, 0x82, 0x00, 0x3F, 0x38, 0x00,
     /* Ext Auth key file */
     0x11, 0x00, 0x00, 0xFF, 0x00, 0x2F,
     0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
@@ -106,8 +140,13 @@ iu8 eeprom[1*1024] = {
     0x0A,
     /* Empty entry */
     0x00, 0x00
-
 };
+#endif /* CONF_32BIT_EEPROM */
+#if CONF_32BIT_EEPROM==1
+	#define ROOT_SIZE 92
+#else
+	#define ROOT_SIZE 80
+#endif
 
 #if defined(CTAPI)
 #if defined(USE_SIO)
@@ -121,6 +160,10 @@ int halsend;
 
 void hal_init( void )
 {
+	/* Set EEPROM in the real state! (all 0xFF) */
+	int i;
+	for(i=FS_START_PTR_ADDR+ROOT_SIZE; i < sizeof(eeprom); i++) eeprom[i] = 0xFF;
+	
 #if defined(DEBUG) && !defined(CTAPI)
 	fprintf( stderr, "hal_init()\n" );
 
@@ -141,6 +184,8 @@ void hal_init( void )
 	fprintf( stderr, "\tPIN_LEN: %d\n", PIN_LEN );
 	fprintf( stderr, "\tPUK_LEN: %d\n", PUK_LEN );
 	fprintf( stderr, "\tFS_START_PTR_ADDR: 0x%.4X\n", FS_START_PTR_ADDR );
+	fprintf( stderr, "\tERASE EEPROM: %s\n", CONF_ERASE_EEPROM?"yes":"no" );
+	fprintf( stderr, "\tEEPROM ADDRESS SIZE: %dbit\n", CONF_32BIT_EEPROM?32:16 );
 #endif
 
 #if defined(CTAPI)
@@ -180,21 +225,21 @@ void hal_destroy( void )
 #endif
 }
 
-bool hal_eeprom_read( iu8 *dst, iu16 src, iu8 len )
+bool hal_eeprom_read( iu8 *dst, eeprom_addr_t src, iu8 len )
 {
 #ifdef DEBUG
-	fprintf( stderr, "hal_eeprom_read( %.8X, %.4X, %d )=", (int)dst, (int)src, len );
+	fprintf( stderr, "hal_eeprom_read( %.8X, %.8X, %d )=", (int)dst, (int)src, len );
 #endif
 
 	while( len-- ) {
-		if( (unsigned int)src>=sizeof(eeprom) ) {
+		if( src>=sizeof(eeprom) ) {
 			sw_set( 0x6F00 );
 			return FALSE;
 		}
 #ifdef DEBUG
-	fprintf( stderr, " %.2X", eeprom[(unsigned int)src] );
+	fprintf( stderr, " %.2X", eeprom[src] );
 #endif
-		*dst++ = eeprom[(unsigned int)src++];
+		*dst++ = eeprom[src++];
 	}
 
 #ifdef DEBUG
@@ -204,21 +249,21 @@ bool hal_eeprom_read( iu8 *dst, iu16 src
 	return TRUE;
 }
 
-bool hal_eeprom_write( iu16 dst, iu8 *src, iu8 len )
+bool hal_eeprom_write( eeprom_addr_t dst, iu8 *src, iu8 len )
 {
 #ifdef DEBUG
-	fprintf( stderr, "hal_eeprom_write( %.4X, %.8X, %d )=", (int)dst, (int)src, len );
+	fprintf( stderr, "hal_eeprom_write( %.8X, %.8X, %d )=", (int)dst, (int)src, len );
 #endif
 
 	while( len-- ) {
-		if( (unsigned int)dst>=sizeof(eeprom) ) {
+		if( dst>=sizeof(eeprom) ) {
 			sw_set( 0x6F00 );
 			return FALSE;
 		}
 #ifdef DEBUG
 	fprintf( stderr, " %.2X", *src );
 #endif
-		eeprom[(unsigned int)dst++]=*src++;
+		eeprom[dst++]=*src++;
 	}
 
 #ifdef DEBUG
Index: src/hal.c
===================================================================
RCS file: /cvs/kseries/kseries/sosse/src/hal.c,v
retrieving revision 1.1.1.1
retrieving revision 1.8
diff -u -p -r1.1.1.1 -r1.8
--- src/hal.c	8 Nov 2004 11:59:25 -0000	1.1.1.1
+++ src/hal.c	22 Jan 2005 13:05:48 -0000	1.8
@@ -26,8 +26,8 @@
 #include <config.h>
 #include <crypt.h>
 #include <hal.h>
-#include <eeprom.h>
-#include <io.h>
+#include <avr/eeprom.h>
+#include <avr/io.h>
 #include <log.h>
 #include <string.h>
 #include <tools.h>
@@ -44,15 +44,16 @@ iu8 randbytes;
 
 void hal_init( void )
 {
-	outb(0x80,ACSR);
-	outb(0xFF,DDRA);
-	outb(0xFF,DDRB);
-	outb(0xFF,DDRC);
-	outb(0xFF,DDRD);
-	outb(0xFF,PORTA);
-	outb(0xFF,PORTB);
-	outb(0xFF,PORTC);
-	outb(0xFF,PORTD);
+	ACSR  = 0x80;
+	PORTA = 0xFF;
+	PORTB = 0xFF;
+	PORTC = 0xFF;
+	PORTD = 0xFF;
+	DDRA  = 0xFF;
+	DDRB  = ~BV(PB5); /* All pins as output except for PB5 that is connected to kfront reset!*/
+	DDRC  = 0xFF;
+	DDRD  = 0xFF;
+
 
 #if CONF_WITH_TRNG==1
 	/* Random number gathering */
@@ -64,7 +65,16 @@ void hal_init( void )
 
 	return;
 }
-
+#if CONF_32BIT_EEPROM==1
+/*	addr: r25:r24:r23:r22
+	ret: r25(=0):r24
+*/
+extern iu8 xeread( iu32 addr );
+/*	addr: r25:r24:r23:r22
+	b: r20
+*/
+extern void xewrt( iu32 addr, iu8 b );
+#else /* CONF_32BIT_EEPROM==1 */
 /*	addr: r25:r24
 	ret: r25(=0):r24
 */
@@ -73,15 +83,14 @@ extern iu8 xeread( iu16 addr );
 	b: r22
 */
 extern void xewrt( iu16 addr, iu8 b );
+#endif /* CONF_32BIT_EEPROM==0 */
 
-bool hal_eeprom_read( iu8 *dst, iu16 src, iu8 len )
+bool hal_eeprom_read( iu8 *dst, eeprom_addr_t src, iu8 len )
 {
 	while( len-- ) {
 		if( src<EEPROM_SIZE ) {
 			/* Internal EEPROM */
-			while( !eeprom_is_ready() ) {}
-
-			*dst++ = eeprom_rb( src++ );
+			*dst++ = eeprom_read_byte( (uint8_t *)(uint16_t)src++ );
 #if CONF_WITH_I2CEEPROM==1
 		} else {
 			/* External I2C EEPROM */
@@ -98,14 +107,12 @@ bool hal_eeprom_read( iu8 *dst, iu16 src
 }
 
 /* TODO: Compare written data? Return 6581 on error. */
-bool hal_eeprom_write( iu16 dst, iu8 *src, iu8 len )
+bool hal_eeprom_write( eeprom_addr_t dst, iu8 *src, iu8 len )
 {
 	while( len-- ) {
 		if( dst<EEPROM_SIZE ) {
 			/* Internal EEPROM */
-			while( !eeprom_is_ready() ) {}
-
-			eeprom_wb( dst++, *src++ );
+			eeprom_write_byte( (uint8_t *)(uint16_t)dst++, *src++ );
 #if CONF_WITH_I2CEEPROM==1
 		} else {
 			/* External I2C EEPROM */
@@ -158,7 +165,7 @@ bool hal_rnd_addEntropy( void )
 			sizeof(x917) ) )
 			return FALSE;
 
-		x917.state[0]=randdata.l[0]; 
+		x917.state[0]=randdata.l[0];
 		x917.state[1]=randdata.l[1];
 
 		crypt_enc( x917.state, x917.key );
@@ -219,7 +226,7 @@ log_add( LOG_TAG_JOKER, NULL, 0 );
 #if 0
 data = RAND_STATE_ADDR+sizeof(x917.counter);
 log_add( LOG_TAG_EEWRITE_DST, &data, 2 );
-data = &x917+sizeof(x917.counter); 
+data = &x917+sizeof(x917.counter);
 log_add( LOG_TAG_EEWRITE_SRC, &data, 2 );
 data = RAND_STATE_LEN+sizeof(x917.counter);
 log_add( LOG_TAG_EEWRITE_LEN, &data, 2 );
Index: src/hal.h
===================================================================
RCS file: /cvs/kseries/kseries/sosse/src/hal.h,v
retrieving revision 1.1.1.1
retrieving revision 1.4
diff -u -p -r1.1.1.1 -r1.4
--- src/hal.h	8 Nov 2004 11:59:25 -0000	1.1.1.1
+++ src/hal.h	26 Nov 2004 18:26:47 -0000	1.4
@@ -26,8 +26,18 @@
 #ifndef SOSSE_HAL_H
 #define SOSSE_HAL_H
 
+#include <config.h>
 #include <types.h>
 
+/*! \brief Type for eeprom adressing.
+
+*/
+#if CONF_32BIT_EEPROM==1
+	typedef iu32 eeprom_addr_t;
+#else
+	typedef iu16 eeprom_addr_t;
+#endif
+
 /*! \brief Initializes the HAL.
 
 	Must be called after each reset.
@@ -46,7 +56,7 @@ void hal_init( void );
 	\retval TRUE on success.
 	\retval FALSE on failure. Error code given in sw.
 */
-bool hal_eeprom_read( iu8 *dst, iu16 src, iu8 len );
+bool hal_eeprom_read( iu8 *dst, eeprom_addr_t src, iu8 len );
 /*! \brief Write data to EEPROM.
 
 	The internal EEPROM begins at address 0, the external EEPROM is
@@ -59,7 +69,7 @@ bool hal_eeprom_read( iu8 *dst, iu16 src
 	\retval TRUE on success.
 	\retval FALSE on failure. Error code given in sw.
 */
-bool hal_eeprom_write( iu16 dst, iu8 *src, iu8 len );
+bool hal_eeprom_write( eeprom_addr_t dst, iu8 *src, iu8 len );
 
 /*! \brief Send a byte with T=0 error detection and recovery.
 
Index: src/main.c
===================================================================
RCS file: /cvs/kseries/kseries/sosse/src/main.c,v
retrieving revision 1.1.1.1
retrieving revision 1.3
diff -u -p -r1.1.1.1 -r1.3
--- src/main.c	8 Nov 2004 11:59:25 -0000	1.1.1.1
+++ src/main.c	1 Dec 2004 17:44:30 -0000	1.3
@@ -170,11 +170,19 @@ int main( void )
 				cmd_verifyKeyPIN();
 				break;
 #endif /* CONF_WITH_PINCMDS==1 */
+#if CONF_32BIT_EEPROM==1
+			case INS_SET_READ_HIGH_WORD:
+				cmd_setReadHighWord();
+				break;
+			case INS_SET_WRITE_HIGH_WORD:
+				cmd_setWriteHighWord();
+				break;
+#endif /* CONF_32BIT_EEPROM==1 */
 			default:
-				t0_sendWord( SW_WRONG_INS );
+				sw_set( SW_WRONG_INS );
 			}
 		} else {
-			t0_sendWord( SW_WRONG_CLA );
+			sw_set( SW_WRONG_CLA );
 		}
 
 #if CONF_WITH_TRNG==1
Index: src/main.h
===================================================================
RCS file: /cvs/kseries/kseries/sosse/src/main.h,v
retrieving revision 1.1.1.1
retrieving revision 1.3
diff -u -p -r1.1.1.1 -r1.3
--- src/main.h	8 Nov 2004 11:59:25 -0000	1.1.1.1
+++ src/main.h	23 Nov 2004 17:49:11 -0000	1.3
@@ -642,6 +642,7 @@
 	<TR> <TD>SW</TD> <TD>Description</TD> </TR>
 	<TR> <TD>90 00</TD> <TD>Command completed successfully</TD> </TR>
 	<TR> <TD>67 00</TD> <TD>Wrong Lc</TD> </TR>
+	<TR> <TD>69 81</TD> <TD>File incompatible: not the last one</TD> </TR>
 	<TR> <TD>69 82</TD> <TD>Security status not satisfied</TD> </TR>
 	<TR> <TD>69 86</TD> <TD>Command not allowed (no DF selected)</TD> </TR>
 	<TR> <TD>6A 82</TD> <TD>File not found</TD> </TR>
@@ -1108,8 +1109,8 @@
 	<TR>
 		<TD>80</TD>
 		<TD>D6</TD>
-		<TD>Offset high</TD>
-		<TD>Offset low</TD>
+		<TD>0</TD>
+		<TD>0</TD>
 		<TD>Length</TD>
 	</TR>
 	</TABLE>
Index: src/tea-at90s8515.S
===================================================================
RCS file: /cvs/kseries/kseries/sosse/src/tea-at90s8515.S,v
retrieving revision 1.1.1.1
retrieving revision 1.3
diff -u -p -r1.1.1.1 -r1.3
--- src/tea-at90s8515.S	8 Nov 2004 11:59:25 -0000	1.1.1.1
+++ src/tea-at90s8515.S	4 Mar 2005 00:31:10 -0000	1.3
@@ -1,4 +1,3 @@
-	.file	"tea-avr.c"
 	.arch at90s8515
 __SREG__ = 0x3f
 __SP_H__ = 0x3e
@@ -218,8 +217,9 @@ tea_enc:
 	mov r24,r13
 	dec r13
 	tst r24
-	breq _PC_+2
+	breq .B1
 	rjmp .L5
+.B1:
 	ldd r24,Y+9
 	ldd r25,Y+10
 	ldd r26,Y+11
@@ -359,8 +359,9 @@ tea_dec:
 	mov r24,r13
 	dec r13
 	tst r24
-	breq _PC_+2
+	breq .B2
 	rjmp .L11
+.B2:
 	mov r31,r17
 	mov r30,r16
 	st Z,r21
Index: src/tools.c
===================================================================
RCS file: /cvs/kseries/kseries/sosse/src/tools.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -p -r1.1.1.1 -r1.2
--- src/tools.c	8 Nov 2004 11:59:25 -0000	1.1.1.1
+++ src/tools.c	16 Nov 2004 17:36:31 -0000	1.2
@@ -38,7 +38,7 @@ void hton_us( iu16 *us, iu8 num )
 	}
 }
 
-#if defined(__i386__)
+//#if defined(__i386__)
 void hton_ul( iu32 *ul, iu8 num )
 {
 	iu32 local;
@@ -48,6 +48,6 @@ void hton_ul( iu32 *ul, iu8 num )
 		*ul++=swap_ul(local);
 	}
 }
-#endif
+//#endif
 #endif /* ENDIAN_LITTLE */
 
Index: src/types.h
===================================================================
RCS file: /cvs/kseries/kseries/sosse/src/types.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -p -r1.1.1.1 -r1.2
--- src/types.h	8 Nov 2004 11:59:25 -0000	1.1.1.1
+++ src/types.h	24 Nov 2004 15:19:31 -0000	1.2
@@ -30,7 +30,7 @@
 #define TRUE	!FALSE
 
 #ifdef __AVR__
-#include <pgmspace.h>
+#include <avr/pgmspace.h>
 //! Variable is in code space. Be carfull with pointers to this space.
 #define	CODE	__ATTR_PROGMEM__
 #else
