The apo files format
====================

Since the S55, somewhere in the flexmem you have an apo/ directory somewhere.
It contains several sub-directories which define the file type.
Each of those contains a file named "main" (except the index dir) and
8bit hex numbered directories with the actual data files.

The following file types exist:
app:  appointments
note: notes
addr: address book (empty on S55)
rem:  reminders
task: tasks
cal:  call records (actually calrec)
The idx (could mean index) subdir contains files in another (still unknown) format.

The "main" file
===============

The main files states what files are present in sub-directories.

Header: <format(8)> <htype(8)>
	format: the data format
		0x61  S55/S65/M65
		0x62  SL75
	htype:  the header type
                0x31  S55: 2 bytes
                0x32  S65/M65: 4 bytes
	                 additional header: 0x00 0x00
		0x33  SL75: 6 bytes
                         additional header: 0x88 0x13 <maximum(16)>
			                     maximum: maximum entry bit ever used

S55/S65: bitfield (32 chunks: 1bit for each entry in a numbered subdir (count from 0)
		Example (first bitfield):
			 little endian bytes: FF F7 0F 00
			 32bit integer: 0x000FF7FF
			 Bits:  0000 0000 0000 1111 1111 0111 1111 1111
			 minor: FEDC BA98 7654 3210 FEDC BA98 7654 3210
			 major: <--------1--------> <--------0-------->
			 meaning: 19 entries, entries 00/0B and 00/xx with xx>13 missing
	 (132-hsize)*8=512 entries seem to be possible (S65) but the phone may limit it to 500?

SL75: The data is located in data/<level1>/<level2>/<entry>
      After the header follows a continuous bistream, each representing an entry. If the bit is
        set then the entry is present. Bitstreams do not have any endianess.
      Each level2 directory contains 41 entries (00-40 in decimal notation).
      Each level1 directory contains ?? level2 directories (00-?? in ?? notation).
      There can be ?? level1 directories (00-?? in ?? notation).
      Note: level1_max * level2_max * 41 cannot be more that 65535.
        Example: hex:    0xFF 0x7E 0x70 0xFF 0xFF 0xFF 0xEF 0xFF 0xFF
                 bin:    1111111101111110011100001111111111111111111111111110111111111111
                 level1: <--------------------------------- 00/ -------------------------
                 level2: <------------ 00/ ---------------------><------------ 01/ ------
                 entry:  ^00.................^20..............40^^00.....................


The data files
==============
"aligned" means 2byte-alignment on S55 and 4byte-alignment else.

Header (S55/S65): The header has a fixed size of 6 bytes
                    <serial(16)> 0x?? 0x?? 0x?? <entry_count(8)>
                    Serial: serial of entries on the phone
		    Entry_Count: number of entries in the file

Header (SL75): The header has a fixed size of 10 bytes
                    <serial(16)> 0x?? 0x?? 0x?? 0x?? 0x?? 0x?? 0x?? <entry_count(8)>

Data: <entry>*
      Entry: <type(16)> <data(*)>
             Type: 16bit little-endian
	           See entry type table below.
	     Data: aligned, content dependent on type
	           See data type list below.



Entry type table:
-----------------
value format  meaning
--------------------------------------------------------------------
0x00  date    rem:alarm time
0x01  date    rem:start time
0x02  date    rem:end time
0x0a  date    note:creation date
0x0b  date    note:modification date
0x0c          note:??? (2byte)
0x0d  text    notetext (UCS-2)

0x10  apptype app,task:type
0x11  text    app:description
0x12  prio    task:priority
0x13  status  task:status
0x14  date    task:due time
0x15  date    app,task:alarm time
0x16  date    app:start time
0x17  task    date    task:closed at time
0x18  text    app:voice memo filename
0x19  text    app:location
0x1a  date    app:end time
0x1b  text    app:reoccurrence
0x1d  number  app/cal:tel num for call type
0x1e  link    app/cal:pointer to addr entry

0x20  link    rem:appointment reference
0x21  alarm   app,task:alarm
0x23  text    addr:family name
0x24  text    addr:given name
0x25  text    addr:street
0x26  text    addr:postal code
0x27  text    addr:city
0x28  text    addr:country
0x29  text    addr:company
0x2a  number  addr:tel num (office)
0x2b  number  addr:tel num (fax 1)
0x2c  number  addr:tel num (mobile)
0x2d  number  addr:tel num (home)
0x2e  text    addr:e-mail
0x2f  text    addr:URL

0x30  date    addr:birthday (in 01/12, 02/06, 02/10)
0x31  link    addr:birthday app pointer
0x32  group   addr:group
0x33  text    addr:picture file address
0x35  text    addr:title [SL75]
0x3e  text    addr:Wv user id [S65]
0x3f  text    addr:nickname [S65]

0x41  text    addr:ICQ number [S65]
0x46  text    addr:AIM buddy name [S65]
0x4d  atype   app,task:alarm type
0x4e  ???     app:??? (4byte: 0x01 0x00 0x00 0x00, 0x00 0x00 0x00 0x00)
0x4f  ???     app,task,note:??? (2byte: 0x21 0x00(cal), 0x23 0x00(app), 0x27 0x00(app))

0x50  text    cal:???
0x51  date    cal:???
0x52  ???     cal:duration??? (2byte)
0x53  ???     cal:??? (2byte: 0x06 0x00)
0x54  ???     cal:??? (4byte: 0x01 0x00 0x00 0x00)
0x55  ???     cal:??? (4byte: 0x00 0x00 0x00 0x00)
0x56  ???     cal:??? (4byte: 0x01 0x00 0x00 0x00)
0x57  ???     cal:??? (4byte: 0x00 0x00 0x00 0x00)
0x58  ???     cal:??? (4byte: 0x00 0x00 0x00 0x00)
0x59  ???     cal:??? (4byte: 0x00 0x00 0x00 0x00)
0x5a  ???     cal:??? (4byte: 0x00 0x00 0x00 0x00)
0x5d  text    addr:e-mail 2
0x5e  number  addr:fax 2

0x60  text    addr:visible name [SL75]
0x62  number  addr:number (private) [SL75]
0x63  number  addr:number (office) [SL75]
0x64  number  addr:number (mobile,private) [SL75]
0x65  number  addr:number (mobile,office) [SL75]
0x66  text    addr:ring tone file address [SL75]
0x67  text    addr:ring video file address [SL75]
0x68  text    addr:short message tone file address [SL75]
0x69  ???     addr:??? (4byte: 0x00 0x00 0x00 0x00)
0x6a  number  addr:number (fax,private) [SL75]
0x6b  text    addr:e-mail (private) [SL75]
0x6c  text    addr:note (private) [SL75]
0x6d  text    addr:Push-To-Talk ID [SL75]
0x6e  ???     addr:???
0x6f  text    addr:profession [SL75]
0x6f  date    app:??? (in type=birthday)

0x70  date    app:??? (in type=birthday)
0x71  text    addr:e-mail (office) [SL75]
0x72  text    addr:e-mail 2 (office) [SL75]
0x73  text    addr:URL (office) [SL75]
0x74  text    addr:street (office) [SL75]
0x75  text    addr:city (office) [SL75]
0x76  text    addr:postal code (office) [SL75]
0x77  text    addr:sub-state (office) [SL75]
0x78  text    addr:country (office) [SL75]
0x79  text    addr:note (office) [SL75]
0x7a  text    addr:wireless village ID [SL75]
0x7e  text    addr:note (person) [SL75]
0x7f  text    addr:sub-state (private) [SL75]

0x91  number  addr:number (fax,office) [SL75]


Data type list:
---------------
date: On S55: <year(16)> <month(8)> <day(8)> <hour(8)> <minute(8)> <second(8)> <rweek(8)> <(8)> <(8)>
	      fixed length (10 bytes)
	      rweek: repeation in weeks, 0xFF=forever, 0x37=55=1year
      On S65: <year(16)> <(16)> <month(8)> <day(8)> <(16)> <hour(8)> <minute(8)> <second(8)> <(8)> <(32)>
	      fixed length (16 bytes)

text: <len(16)> [<count(16)>] <text(*)>
      len: number of bytes following for this field (rest of header + data)
      count: number of characters in data -> (len - 2)/count == sizeof(char)
      text: UCS-2LE data, padding value is 0xff

number: On S55 and S65: <flags?(8)> <numtype(8)> <numlen(8)> <(8)> <textlen(8)> <number(*)> <text(*)> <(32)>
	On SL75: <numlen(16)> {<numtext(*)> 0x00} <align(*)> <textlen(16)> {<text(*)> 0xff} <align(*)> \
                 <flen(16)> <ffield(*)> <flags?(8)> 0x00 0x00 0x00 <numtype(8)> 0x00 (6x 0x00)
	flags: 0x06 ???
	       0x1d ???
	numtype: ETSI 23.040 number type field
	numlen: number of bytes that contain valid digits
	number: semi-octet-encoded digits (fix size of 21 bytes)
	numtext: digits in text representation
	textlen: length of text
	text: padding value is 0xff
	align: fill bytes (0x00) to align the following bytes to a 2byte boundry
	flen: length of the ffield
	ffield: bytes with 0xff

group: <value(16)>
       value (S65): 0x01 VIP
                    0x02 office
		    0x03 family
		    0x04 individual
		    0x05 leisure
		    0x06 private
		    0x07 business
		    0x08 received
		    0x09 no group

apptype: <type(16)>
	 type: 0x01 memo
	       0x02 speech memo
	       0x04 meeting
	       0x08 holiday
	       0x10 birthday
	       0x20 call
	
prio: <value(16)>
      value: 0x01 highest
             0x02 high
	     0x03 normal
	     0x04 low
	     0x05 lowest

status: <value(16)>
	value: 0x00 outstanding
	       0x02 done

alarm: <value(16)>
       value: 0x00 disabled
              0x10 enabled (S65)
	      0x19 enabled (S55)

atype: <value(16)> <(16)>
       value: 0x00 normal
	      0x01 silent	

link: <???(1)><addr(15)> <0x??(8)> <type(8)>
      ???: the MSB has an unknown meaning (maybe: 0=master, 1=slave)
      addr: serial of a corresponding addr entry (but seems to be something else on S55)
      type: the type of the link destination:
	    0x0a  addr
	    0xcc  app
