Siemens .adr file format
========================

Author: Hendrik Sattler <post@hendrik-sattler.de>

Location of .adr files:
.adr files can be found in the "/Address book" directory of
the FlexMem (accessible by obexftp protocl) or MMC.
Only phones manufactured by Siemens that have an address book may
have such a file (with exception to phones with SymbianOS).
The known phones are: S45, ME45, SL42, SL45, SL45i, S55 and SL55

File name explanation: the ?? seem to indicate the file version as
the number increases with newer models.
Known versions are (and thus supported):
02: SL42, SL45, S45, ME45
03: S45, ME45
07: S55
08: SL55

Endianness is little-endian (except when stated otherwise).

the 9F??.adr file
====================
Header:
List count (1 byte): the number of lists
                     v02 and v03: 6
		     v07: 7
		     v08: ???
0x04: unknown meaning
#(list count)*1byte: the meaning of each of the lists, represented
                     by an 8bit number. The number is the field number
		     from the 5F??.adr file (counted from 1), thus
		     last name, index and the telephone numbers.
Then follow some other unknown bytes that always end in the sequence:
0x02 0x04 0xc3 0x05 0xc3 0x05

After that follow #(list count) lists of 16bit integers.
The numbers are all index numbers from the 7F??.adr file, counting
from 0. The list order depends on the type of the field.
Entries that are marked deleted in the 7F??.adr are omitted.

It is unclear, though, what this file is actually used for.
It is not necessary for decoding.

the 7F??.adr file
====================
This file contains a simple list of 16bit integers that mark the
offset in the 5F??.adr file (see below). The MSB marks deleted
entries:
   1: deleted
   0: not deleted

the 5F??.adr file
====================
The file has the following format:
5x 16bit integers file header:
   1: number of fields per entry:
      v02=19, v03=20, v07=28, v08=29
   2: number of undeleted entries
   3: unknown (always 0x0000)
   4: number of deleted entries
   5: unknown (always 0x0001)

   Example: 13 00 | 2a 00 | 00 00 | 01 00 | 01 00

Now come #(number of fields) 16bit integers that specify the
entry limits. These are joined values with the following decoding rule:
   bits 15..3 (upper 13bits)
     maximum field size in bits (including the end-of-field element)
     or in bytes if you shift 3 bits to the right.

   bits  2..0 (lower 3 bits)
     field format:
       0x0: 8bit integer values
            end-of-field element: none
       0x1: semi-octet string as defined in ETSI 23.040 (*)
            end-of-field element: >=0xf0 (includes data if <=0xfd)
       0x2: ISO-8859-1 string
            end-of-field element: 0x00
       0x3: UCS-2 unicode string
            end-of-field element: 0x0000
       0x4: 16bit integer values
            end-of-field element: none
       0x5: 16bit integers used for date
            end-of-field element: none

    (*)  with additional elements:
         A='*'
	 B='#'
	 C='+'  (not, if leading plus)
	 D='?'  (marks a variable part of a number)
	 E is unknown
         F is reserved for padding

   Examples:
       SL42:       13 01 93 01 13 01 93 02 13 01 13 01 93 00
             4a 01 0a 02 4a 00 a9 00 a9 00 a9 00 a9 00 08 00
             08 00 08 00 08 00 82 00
       S55:        13 01 93 01 13 01 93 02 13 01 13 01 13 08
             93 00 9a 01 9a 01 0a 02 4a 00 a9 00 a9 00 a9 00
             a9 00 a9 00 08 00 08 00 08 00 08 00 08 00 82 00
             14 00 24 00 35 00 08 00 08 00
       SL55:       13 01 93 01 13 01 93 02 13 01 13 01 13 08
             93 00 9a 01 9a 01 0a 02 4a 00 a9 00 a9 00 a9 00
             a9 00 a9 00 08 00 08 00 08 00 08 00 08 00 82 00
             14 00 24 00 35 00 08 00 08 00 07 00
       See description of fields at end of file.

It may happen that the entry limit description is followed by
some bytes of value 0xdd.

Now the entries begin:
Empty entries:
begin with 0xee which is followed by an unknown number of bytes
of value 0xdd.

Non-empty entries:
have the following format: <header><fields>
   header: begin with #(number of fields) 16bit integers that
           specify the actual length (in bytes!) of the field
           in this entry
	   Example:                    10 00  12 00 0C 00  0E 00 0C 00
                    0A 00 02 00  12 00 0B 00  0B 00 0E 00  09 00 15 00
                    15 00 15 00  15 00 15 00  01 00 01 00  01 00 01 00
                    01 00 10 00  02 00 04 00  06 00 01 00  01 00
           It is unknown what happends with field sizes of 0xdd or 0xee.

   fields: may again be followed by an unknown number of bytes of
           value 0xdd.
           Example:                                              56 00
                    6F 00 72 00  6E 00 61 00  6D 00 65 00  00 00 4E 00
                    61 00 63 00  68 00 6E 00  61 00 6D 00  65 00 00 00
                    46 00 69 00  72 00 6D 00  61 00 00 00  53 00 74 00
                    72 00 61 00  DF 00 65 00  00 00 53 00  74 00 61 00
                    64 00 74 00  00 00 4C 00  61 00 6E 00  64 00 00 00
                    00 00 34 00  4E 00 61 00  63 00 68 00  6E 00 61 00
                    00 00 00 00  65 40 6D 61  69 6C 31 2E  64 65 00 65
                    40 6D 61 69  6C 32 2E 64  65 00 68 74  74 70 3A 2F
                    2F 75 72 6C  2E 64 65 00  36 36 36 36  36 36 36 36
                    00 11 11 11  11 11 11 11  11 11 11 11  11 11 11 11
                    11 11 11 11  11 FF 22 22  22 22 22 22  22 22 22 22
                    22 22 22 22  22 22 22 22  22 22 FF 33  33 33 33 33
                    33 33 33 33  33 33 33 33  33 33 33 33  33 33 33 FF
                    44 44 44 44  44 44 44 44  44 44 44 44  44 44 44 44
                    44 44 44 44  FF 55 55 55  55 55 55 55  55 55 55 55
                    55 55 55 55  55 55 55 55  55 FF 81 81  81 81 81 32
                    30 30 34 30  32 31 38 54  30 30 32 31  35 31 00 21
                    7A 00 00 00  00 00 00 00  00 00 00 00  00


The following meanings of the fields or known:
file version 02:
================
field meaning        size    type comment
-----------------------------------------
 1.   first name     0x0110  0x3
 2.   last name      0x0190  0x3
 3.   company        0x0110  0x3
 4.   street         0x0290  0x3
 5.   city           0x0110  0x3
 6.   country        0x0110  0x3
 7.   index          0x0090  0x3  (*)
 8.   e-mail         0x0148  0x2
 9.   URL            0x0208  0x2
10.   postal code    0x0048  0x2
11.   tel/home       0x00a8  0x1
12.   tel/office     0x00a8  0x1
13.   tel/mobile     0x00a8  0x1
14.   tel/fax        0x00a8  0x1
15.   type/home      0x0008  0x0  as defined in ETSI 23.040
16.   type/office    0x0008  0x0  as defined in ETSI 23.040
17.   type/mobile    0x0008  0x0  as defined in ETSI 23.040
18.   type/fax       0x0008  0x0  as defined in ETSI 23.040
19.   mod. time      0x0080  0x2  "JJJJMMTT<T>hhmmss" (local time in ISO8601 basic format)

file version 03:
================
field meaning        size    type comment
-----------------------------------------
1.-19. like for file version 02
20.   ***unknown***  0x0020  0x4 (example: 0x4b 0x38 0x72 0x75)

file version 07:
================
field meaning        size    type comment
-----------------------------------------
 1.   first name     0x0110  0x3
 2.   last name      0x0190  0x3
 3.   company        0x0110  0x3
 4.   street         0x0290  0x3
 5.   city           0x0110  0x3
 6.   country        0x0110  0x3
 7.   picture file   0x0810  0x3  a file name with abosolute path in flexmem
 8.   index          0x0090  0x3  (*)
 9.   e-mail 1       0x0198  0x2
10.   e-mail 2       0x0198  0x2
11.   URL            0x0208  0x2
12.   postal code    0x0048  0x2
13.   tel/home       0x00a8  0x1
14.   tel/office     0x00a8  0x1
15.   tel/mobile     0x00a8  0x1
16.   tel/fax 1      0x00a8  0x1
17.   tel/fax 2      0x00a8  0x1
18.   type/home      0x0008  0x0  as defined in ETSI 23.040
19.   type/office    0x0008  0x0  as defined in ETSI 23.040
20.   type/mobile    0x0008  0x0  as defined in ETSI 23.040
21.   type/fax 1     0x0008  0x0  as defined in ETSI 23.040
22.   type/fax 2     0x0008  0x0  as defined in ETSI 23.040
23.   mod. time      0x0080  0x2  "JJJJMMTT<T>hhmmss" (local time in ISO8601 basic format)
24.   extra          0x0010  0x4  entry reference number (???)
25.   apo link       0x0020  0x4  <ref(16)> <type(16)>  (**)
26.   birthday       0x0030  0x5  order: day, month, year
27.   remember flag  0x0008  0x0  if set, an calendar entry on birthday exists
28.   ***unknown***  0x0008  0x0  (example: 0x00)

file version 08:
================
field meaning        size    type comment
-----------------------------------------
1.-28. like for file version 07
29.   Index2         0x0038  0x0

(*) the only interesting thing in this field is the first character:
      SL42: 0=business card, 1=VIP, 2=no group
      S55:  1=family, 2=friends, 3=office, 4=VIP, 5=leisure,
            6=private, 7=business, 8=received, 9=no group
    The rest of this field serves the purpose of sorting.

(**) the format is pretty unclear but it has something do
     with addressing an apo file, somehow:
     ref: apo reference number or some lookup value?
     type: byte 0: 0x00 or 0x01 (unknown meaning)
           byte 1: 0xcc (target is an apo appointment file)
