This commit was generated by cvs2svn to compensate for changes in r164,
[gnokii.git] / include / gsm-common.h
1 /*
2
3   $Id$
4
5   G N O K I I
6
7   A Linux/Unix toolset and driver for Nokia mobile phones.
8
9   Copyright (C) 1999, 2000 Hugh Blemings & Pavel Janík ml.
10
11   Released under the terms of the GNU GPL, see file COPYING for more details.
12         
13   Header file for the definitions, enums etc. that are used by all models of
14   handset.
15
16   $Log$
17   Revision 1.1.1.10  2002/04/03 01:44:15  short
18   Implemented connection type "tcp" (GCT_TCP), use <hostname>:<port> as "port"
19
20   Revision 1.1.1.9  2002/04/03 00:08:19  short
21   Found in "gnokii-working" directory, some November-patches version
22
23   Revision 1.80  2001/08/20 23:36:27  pkot
24   More cleanup in AT code (Manfred Jonsson)
25
26   Revision 1.79  2001/07/27 00:02:22  pkot
27   Generic AT support for the new structure (Manfred Jonsson)
28
29   Revision 1.78  2001/06/28 00:28:45  pkot
30   Small docs updates (Pawel Kot)
31
32
33 */
34
35 #ifndef __gsm_common_h
36 #define __gsm_common_h
37
38 #include <stdlib.h>
39
40 #include "gsm-common.h"
41 #include "data/rlp-common.h"
42
43 /* Type of connection. Now we support serial connection with FBUS cable and
44    IR (only with 61x0 models) */
45
46 typedef enum {
47   GCT_Serial,   /* Serial connection. */
48   GCT_Infrared, /* Infrared connection. */
49   GCT_Tekram,   /* Tekram Ir-Dongle */
50   GCT_Irda,
51   GCT_TCP,      /* TCP network connection */
52 } GSM_ConnectionType;
53
54 /* Maximum length of device name for serial port */
55
56 #define GSM_MAX_DEVICE_NAME_LENGTH (100)
57
58 /* Define an enum for specifying memory types for retrieving phonebook
59    entries, SMS messages etc. This type is not mobile specific - the model
60    code should take care of translation to mobile specific numbers - see 6110
61    code.
62    01/07/99:  Two letter codes follow GSM 07.07 release 6.2.0
63 */
64
65 typedef enum {
66   GMT_ME, /* Internal memory of the mobile equipment */
67   GMT_SM, /* SIM card memory */
68   GMT_FD, /* Fixed dial numbers */
69   GMT_ON, /* Own numbers */
70   GMT_EN, /* Emergency numbers */
71   GMT_DC, /* Dialled numbers */
72   GMT_RC, /* Received numbers */
73   GMT_MC, /* Missed numbers */
74   GMT_LD, /* Last dialed */
75   GMT_MT, /* combined ME and SIM phonebook */
76   GMT_TA, /* for compatibility only: TA=computer memory */
77   GMT_CB, /* Currently selected memory */
78   GMT_XX = 0xff /* Error code for unknown memory type (returned by fbus-xxxx functions). */
79 } GSM_MemoryType;
80
81 /* Power source types */
82
83 typedef enum {
84   GPS_ACDC=1, /* AC/DC powered (charging) */
85   GPS_BATTERY /* Internal battery */
86 } GSM_PowerSource;
87
88 /* This data-type is used to specify the type of the number. See the official
89    GSM specification 03.40, version 5.3.0, section 9.1.2.5, page 33. */
90
91 typedef enum {
92   GNT_UNKNOWN=0x81,      /* Unknown number */
93   GNT_INTERNATIONAL=0x91 /* International number */
94 } GSM_NumberType;
95
96
97 /* Maximum length of SMS center name */
98
99 #define GSM_MAX_SMS_CENTER_NAME_LENGTH  (20)
100
101 /* Limits of SMS messages. */
102
103 #define GSM_MAX_SMS_CENTER_LENGTH  (40)
104 #define GSM_MAX_SENDER_LENGTH      (40)
105 #define GSM_MAX_DESTINATION_LENGTH (40)
106 #define GSM_MAX_SMS_LENGTH         (160)
107 #define GSM_MAX_SMS_8BIT_LENGTH    (140)
108
109 #define GSM_MAX_CB_MESSAGE         (160)
110
111 /* The maximum length of an uncompressed concatenated short message is
112    255 * 153 = 39015 default alphabet characters */
113 #define GSM_MAX_CONCATENATED_SMS_LENGTH (39015)
114
115 /* All the concatenated UDH headers may get long (at least logo+concatenation).
116  * Theoretically it can be (GSM_MAX_SMS_LENGTH*7/8).
117  */
118 #define GSM_MAX_USER_DATA_HEADER_LENGTH (256)
119
120 /* types of User Data Header */
121 typedef enum {
122   GSM_NoUDH,
123   GSM_ConcatenatedMessages,
124   GSM_OpLogo,
125   GSM_CallerIDLogo,
126   GSM_RingtoneUDH
127 } GSM_UDH;
128
129 /* Define datatype for SMS Message Type */
130
131 typedef enum {
132   GST_MO, /* Mobile Originated (MO) message - Outbox message */
133   GST_MT, /* Mobile Terminated (MT) message - Inbox message */
134   GST_DR, /* Delivery Report */
135   GST_UN  /* Unknown */
136 } GSM_SMSMessageType;
137
138 /* Datatype for SMS status */
139 /* FIXME - This needs to be made clearer and or turned into a 
140    bitfield to allow compound values (read | sent etc.) */
141
142 typedef enum {
143   GSS_SENTREAD    = true, /* Sent or read message */
144   GSS_NOTSENTREAD = false /* Not sent or not read message */
145 } GSM_SMSMessageStatus;
146
147 /* SMS Messages sent as... */
148
149 typedef enum {
150   GSMF_Text   = 0x00, /* Plain text message. */
151   GSMF_Fax    = 0x22, /* Fax message. */
152   GSMF_Voice  = 0x24, /* Voice mail message. */
153   GSMF_ERMES  = 0x25, /* ERMES message. */
154   GSMF_Paging = 0x26, /* Paging. */
155   GSMF_UCI    = 0x2d, /* Email message in 8110i. */
156   GSMF_Email  = 0x32, /* Email message. */
157   GSMF_X400   = 0x31  /* X.400 message. */
158 } GSM_SMSMessageFormat;
159
160 /* Validity of SMS Messages. */
161
162 typedef enum {
163   GSMV_1_Hour   = 0x0b,
164   GSMV_6_Hours  = 0x47,
165   GSMV_24_Hours = 0xa7,
166   GSMV_72_Hours = 0xa9,
167   GSMV_1_Week   = 0xad,
168   GSMV_Max_Time = 0xff
169 } GSM_SMSMessageValidity;
170
171 /* Define datatype for SMS Message Center */
172
173 typedef struct {
174         int                     No;                                     /* Number of the SMSC in the phone memory. */
175         char                    Name[GSM_MAX_SMS_CENTER_NAME_LENGTH];   /* Name of the SMSC. */
176         GSM_SMSMessageFormat    Format;                                 /* SMS is sent as text/fax/paging/email. */
177         GSM_SMSMessageValidity  Validity;                               /* Validity of SMS Message. */
178         char                    Number[GSM_MAX_SMS_CENTER_LENGTH];      /* Number of the SMSC. */
179         char                    Recipient[GSM_MAX_SMS_CENTER_LENGTH];   /* Number of the default recipient. */
180 } GSM_MessageCenter;
181
182 /* Define datatype for Cell Broadcast message */
183 typedef struct {
184   int Channel;                                      /* channel number */
185   char Message[GSM_MAX_CB_MESSAGE + 1];
186   int New;
187 } GSM_CBMessage;
188
189
190
191 /* Definition of security codes. */
192
193 typedef enum {
194   GSCT_SecurityCode = 0x01, /* Security code. */
195   GSCT_Pin,                 /* PIN. */
196   GSCT_Pin2,                /* PIN 2. */
197   GSCT_Puk,                 /* PUK. */
198   GSCT_Puk2,                /* PUK 2. */
199   GSCT_None                 /* Code not needed. */
200 } GSM_SecurityCodeType;
201
202 /* Security code definition. */
203
204 typedef struct {
205   GSM_SecurityCodeType Type; /* Type of the code. */
206   char Code[10];             /* Actual code. */
207 } GSM_SecurityCode;
208
209 /* Structure used for passing dates/times to date/time functions such as
210    GSM_GetTime and GSM_GetAlarm etc. */
211
212 typedef struct {
213   bool AlarmEnabled; /* Is the alarm set? */
214   int Year;          /* The complete year specification - e.g. 1999. Y2K :-) */
215   int Month;         /* January = 1 */
216   int Day;
217   int Hour;
218   int Minute;
219   int Second;
220   int Timezone;      /* The difference between local time and GMT, FIXME: WHICH UNITS? --- FIX THE CODE! */
221 } GSM_DateTime;
222
223 /* Define datatype for SMS messages, used for getting SMS messages from the
224    phones memory. */
225
226 typedef struct {
227   GSM_DateTime Time;                        /* Date of reception/response of messages. */
228   GSM_DateTime SMSCTime;                    /* Date of SMSC response if DeliveryReport messages. */
229   int Validity;                             /* Validity Period of the SMS message (unit is minutes). */
230   bool UDHPresent;                          /* If UDH is present */
231   unsigned char UDH[GSM_MAX_USER_DATA_HEADER_LENGTH]; /* If UDH is present - content of UDH, UDH[0] specifies length */
232   char MessageText[GSM_MAX_SMS_LENGTH + 1]; /* (+1) is room for null term, sized by GSM_SMSMessage.MessageTextLength
233                                              * GSM_SMSMessage.EightBit==false => MessageText is also '\0'-terminated
234                                              */
235   int MessageTextLength;                    /* Unit is determined by GSM_SMSMessage.EightBit */
236   GSM_MessageCenter MessageCenter;          /* SMS Center. */
237   char Sender[GSM_MAX_SENDER_LENGTH + 1];   /* Sender of the SMS message. */
238   char Destination[GSM_MAX_DESTINATION_LENGTH + 1]; /* Destination of the message. */
239   int MessageNumber;                        /* Location in the memory (output argument). */
240   GSM_MemoryType MemoryType;                /* Type of memory message is stored in. */
241   GSM_SMSMessageType Type;                  /* Type of the SMS message */
242   GSM_SMSMessageStatus Status;              /* Status of the SMS message */
243   int Class;                                /* Class Message: 0, 1, 2, 3 or none (value -1 !); see GSM 03.38 */
244   bool EightBit;                            /* Indicates whether SMS contains 8 bit data */
245   bool Compression;                         /* Indicates whether SMS contains compressed data */
246   int Location;                             /* Location in the memory (input argument). */
247   bool ReplyViaSameSMSC;                    /* Indicates whether "Reply via same center" is set */
248 } GSM_SMSMessage;
249
250 /* This structure is used to get the current network status */
251
252 typedef struct {
253   char NetworkCode[10]; /* GSM network code */
254   char CellID[10];      /* CellID */
255   char LAC[10];         /* LAC */
256 } GSM_NetworkInfo;
257
258 /* Limits for sizing of array in GSM_PhonebookEntry. Individual handsets may
259    not support these lengths so they have their own limits set. */
260
261 #define GSM_MAX_PHONEBOOK_NAME_LENGTH   (50)   /* For 7110 */
262 #define GSM_MAX_PHONEBOOK_NUMBER_LENGTH (48)   /* For 7110 */
263 #define GSM_MAX_PHONEBOOK_TEXT_LENGTH   (60)   /* For 7110 */
264 #define GSM_MAX_PHONEBOOK_SUB_ENTRIES   (8)    /* For 7110 */
265                                                /* 7110 is able to in one
266                                                 * entry 5 numbers and 2
267                                                 * texts [email,notice,postal] */
268
269 /* Here is a macro for models that do not support caller groups. */
270
271 #define GSM_GROUPS_NOT_SUPPORTED -1
272
273 /* This data type is used to report the number of used and free positions in
274    memory (sim or internal). */
275
276 typedef struct {
277   GSM_MemoryType MemoryType; /* Type of the memory */
278   int Used;                  /* Number of used positions */
279   int Free;                  /* Number of free positions */
280 } GSM_MemoryStatus;
281
282 /* This data type is used to hold the current SMS status. */
283
284 typedef struct {
285   int UnRead; /* The number of unread messages (currently not used) */
286   int Used;   /* The number of currently stored messages */
287   int Slots;  /* Reading will try all 1..Slots locations */
288 } GSM_SMSStatus;
289
290
291
292 /* Some phones (at the moment 6210/7110) supports extended phonebook
293    with additional data.  Here we have structures for them */
294
295 typedef enum
296 {
297   GSM_General = 0x0a,
298   GSM_Mobile  = 0x03,
299   GSM_Work    = 0x06,
300   GSM_Fax     = 0x04,
301   GSM_Home    = 0x02
302 } GSM_Number_Type;
303
304 typedef enum
305 {
306   GSM_Number  = 0x0b,
307   GSM_Note    = 0x0a,
308   GSM_Postal  = 0x09,
309   GSM_Email   = 0x08,
310   GSM_Name    = 0x07,
311   GSM_Date    = 0x13   /* Date is used for DC,RC,etc (last calls) */
312 } GSM_EntryType;
313
314 typedef struct {
315   GSM_EntryType   EntryType;
316   GSM_Number_Type NumberType;
317   union {
318     char Number[GSM_MAX_PHONEBOOK_TEXT_LENGTH + 1]; /* Number */
319     GSM_DateTime Date;                         /* or the last calls list */
320   } data;
321   int             BlockNumber;
322 } GSM_SubPhonebookEntry;
323
324 /* Define datatype for phonebook entry, used for getting/writing phonebook
325    entries. */
326
327 typedef struct {
328   bool Empty;                                       /* Is this entry empty? */
329   char Name[GSM_MAX_PHONEBOOK_NAME_LENGTH + 1];     /* Plus 1 for
330                                                        nullterminator. */
331   char Number[GSM_MAX_PHONEBOOK_NUMBER_LENGTH + 1]; /* Number */
332   GSM_MemoryType MemoryType;                        /* Type of memory */
333   int Group;                                        /* Group */
334   int Location;                                     /* Location */
335   GSM_DateTime Date;                                /* The record date and time
336                                                        of the number. */
337   GSM_SubPhonebookEntry SubEntries[GSM_MAX_PHONEBOOK_SUB_ENTRIES];
338                                                     /* For phones with
339                                                      * additional phonebook
340                                                      * entries */
341   int SubEntriesCount;                              /* Should be 0, if extended
342                                                        phonebook is not used */
343 } GSM_PhonebookEntry;
344
345
346
347 /* This define speed dialing entries. */
348
349 typedef struct {
350   int Number;                /* Which number is used to dialing? */
351   GSM_MemoryType MemoryType; /* Memory type of the number. */
352   int Location;              /* Location of the number in MemoryType. */
353 } GSM_SpeedDial;
354
355 /* Define enum used to describe what sort of date/time support is
356    available. */
357
358 typedef enum {
359   GDT_None,     /* The mobile phone doesn't support time and date. */
360   GDT_TimeOnly, /* The mobile phone supports only time. */
361   GDT_DateOnly, /* The mobile phone supports only date. */
362   GDT_DateTime  /* Wonderful phone - it supports date and time. */
363 } GSM_DateTimeSupport;
364
365 /* Define enums for RF units.  GRF_CSQ asks for units in form used
366    in AT+CSQ command as defined by GSM 07.07 */
367
368 typedef enum {
369   GRF_Arbitrary,
370   GRF_dBm,
371   GRF_mV,
372   GRF_uV,
373   GRF_CSQ,
374   GRF_Percentage
375 } GSM_RFUnits;
376
377 /* Define enums for Battery units. */
378
379 typedef enum {
380   GBU_Arbitrary,
381   GBU_Volts,
382   GBU_Minutes,
383   GBU_Percentage
384 } GSM_BatteryUnits;
385
386 /* Define enums for Calendar Note types */
387
388 typedef enum {
389   GCN_REMINDER=1, /* Reminder */
390   GCN_CALL,       /* Call */
391   GCN_MEETING,    /* Meeting */
392   GCN_BIRTHDAY    /* Birthday */
393 } GSM_CalendarNoteType;
394
395 /* Calendar note type */
396
397 typedef struct {
398   int Location;                 /* The number of the note in the phone memory */
399   GSM_CalendarNoteType Type;    /* The type of the note */
400   GSM_DateTime Time;            /* The time of the note */
401   GSM_DateTime Alarm;           /* The alarm of the note */
402   char Text[20];                /* The text of the note */
403   char Phone[20];               /* For Call only: the phone number */
404   double Recurance;             /* Recurance of the note */
405 } GSM_CalendarNote;
406
407 /* This structure is provided to allow common information about the particular
408    model to be looked up in a model independant way. Some of the values here
409    define minimum and maximum levels for values retrieved by the various Get
410    functions for example battery level. They are not defined as constants to
411    allow model specific code to set them during initialisation */
412
413 typedef struct {
414                 
415   char *Models; /* Models covered by this type, pipe '|' delimited. */
416
417 /* Minimum and maximum levels for RF signal strength. Units are as per the
418    setting of RFLevelUnits.  The setting of RFLevelUnits indicates the 
419    default or "native" units used.  In the case of the 3110 and 6110 series
420    these are arbitrary, ranging from 0 to 4. */
421
422   float MaxRFLevel;
423   float MinRFLevel;
424   GSM_RFUnits RFLevelUnits;
425
426 /* Minimum and maximum levels for battery level. Again, units are as per the
427    setting of GSM_BatteryLevelUnits.  The value that BatteryLevelUnits is set
428    to indicates the "native" or default value that the phone supports.  In the
429    case of the 3110 and 6110 series these are arbitrary, ranging from 0 to 4. */
430
431   float MaxBatteryLevel;
432   float MinBatteryLevel;
433   GSM_BatteryUnits BatteryLevelUnits;
434
435 /* FIXME: some very similar code is in common/misc.c */
436
437 /* Information about date, time and alarm support. In case of alarm
438    information we provide value for the number of alarms supported. */
439
440   GSM_DateTimeSupport DateTimeSupport;
441   GSM_DateTimeSupport AlarmSupport;
442   int MaximumAlarms;
443   u8 StartupLogoH;   /* Logo Widths and Heights - if supported */
444   u8 StartupLogoW;
445   u8 OpLogoH;
446   u8 OpLogoW;
447   u8 CallerLogoH;
448   u8 CallerLogoW;
449 } GSM_Information;
450
451 /* Define standard GSM error/return code values. These codes are also used for
452    some internal functions such as SIM read/write in the model specific code. */
453
454 typedef enum {
455   GE_NONE = 0,              /* No error. */
456   GE_DEVICEOPENFAILED,      /* Couldn't open specified serial device. */
457   GE_UNKNOWNMODEL,          /* Model specified isn't known/supported. */
458   GE_NOLINK,                /* Couldn't establish link with phone. */
459   GE_TIMEOUT,               /* Command timed out. */
460   GE_TRYAGAIN,              /* Try again. */
461   GE_INVALIDSECURITYCODE,   /* Invalid Security code. */
462   GE_NOTIMPLEMENTED,        /* Command called isn't implemented in model. */
463   GE_INVALIDSMSLOCATION,    /* Invalid SMS location. */
464   GE_INVALIDPHBOOKLOCATION, /* Invalid phonebook location. */
465   GE_INVALIDMEMORYTYPE,     /* Invalid type of memory. */
466   GE_INVALIDSPEEDDIALLOCATION, /* Invalid speed dial location. */
467   GE_INVALIDCALNOTELOCATION,/* Invalid calendar note location. */
468   GE_INVALIDDATETIME,       /* Invalid date, time or alarm specification. */
469   GE_EMPTYSMSLOCATION,      /* SMS location is empty. */
470   GE_PHBOOKNAMETOOLONG,     /* Phonebook name is too long. */
471   GE_PHBOOKNUMBERTOOLONG,   /* Phonebook number is too long. */
472   GE_PHBOOKWRITEFAILED,     /* Phonebook write failed. */
473   GE_SMSSENDOK,             /* SMS was send correctly. */
474   GE_SMSSENDFAILED,         /* SMS send fail. */
475   GE_SMSWAITING,            /* Waiting for the next part of SMS. */
476   GE_SMSTOOLONG,            /* SMS message too long. */
477   GE_NONEWCBRECEIVED,       /* Attempt to read CB when no new CB received */
478   GE_INTERNALERROR,         /* Problem occured internal to model specific code. */
479   GE_CANTOPENFILE,          /* Can't open file with bitmap/ringtone */
480   GE_WRONGNUMBEROFCOLORS,   /* Wrong number of colors in specified bitmap file */
481   GE_WRONGCOLORS,           /* Wrong colors in bitmap file */
482   GE_INVALIDFILEFORMAT,     /* Invalid format of file */
483   GE_SUBFORMATNOTSUPPORTED, /* Subformat of file not supported */
484   GE_FILETOOSHORT,          /* Too short file to read */
485   GE_FILETOOLONG,           /* Too long file to read */
486   GE_INVALIDIMAGESIZE,      /* Invalid size of bitmap (in file, sms etc.) */
487   GE_NOTSUPPORTED,          /* Function not supported by the phone */
488   GE_BUSY,                  /* Command is still being executed. */
489   GE_USERCANCELED,
490   GE_UNKNOWN,               /* Unknown error - well better than nothing!! */
491   GE_MEMORYFULL,
492   GE_NOTWAITING,            /* Not waiting for a response from the phone */
493   GE_NOTREADY,
494
495   /* The following are here in anticipation of data call requirements. */
496
497   GE_LINEBUSY,              /* Outgoing call requested reported line busy */
498   GE_NOCARRIER              /* No Carrier error during data call setup ? */
499 } GSM_Error;
500
501
502 /* This enum is used for display status. */
503
504 typedef enum {
505   DS_Call_In_Progress, /* Call in progress. */
506   DS_Unknown,          /* The meaning is unknown now :-( */
507   DS_Unread_SMS,       /* There is Unread SMS. */
508   DS_Voice_Call,       /* Voice call active. */
509   DS_Fax_Call,         /* Fax call active. */
510   DS_Data_Call,        /* Data call active. */
511   DS_Keyboard_Lock,    /* Keyboard lock status. */
512   DS_SMS_Storage_Full  /* Full SMS Memory. */
513 } DisplayStatusEntity;
514
515 /* Bitmap types. */
516
517 typedef enum {
518   GSM_None=0,
519   GSM_StartupLogo,
520   GSM_OperatorLogo,
521   GSM_CallerLogo,
522   GSM_PictureImage,
523   GSM_WelcomeNoteText,
524   GSM_DealerNoteText
525 } GSM_Bitmap_Types;
526
527 #define GSM_MAX_BITMAP_SIZE 864
528
529 /* Structure to hold incoming/outgoing bitmaps (and welcome-notes). */
530
531 typedef struct {
532   u8 height;               /* Bitmap height (pixels) */
533   u8 width;                /* Bitmap width (pixels) */
534   u16 size;                /* Bitmap size (bytes) */
535   GSM_Bitmap_Types type;   /* Bitmap type */
536   char netcode[7];         /* Network operator code */
537   char text[256];          /* Text used for welcome-note or callergroup name */
538   char dealertext[256];    /* Text used for dealer welcome-note */
539   bool dealerset;          /* Is dealer welcome-note set now ? */
540   unsigned char bitmap[GSM_MAX_BITMAP_SIZE]; /* Actual Bitmap */ 
541   char number;             /* Caller group number */
542   char ringtone;           /* Ringtone no sent with caller group */
543 } GSM_Bitmap;
544
545
546 /* NoteValue is encoded as octave(scale)*14 + note */
547 /* where for note: c=0, d=2, e=4 .... */
548 /* ie. c#=1 and 5 and 13 are invalid */
549 /* note=255 means a pause */
550
551 #define MAX_RINGTONE_NOTES 256
552
553 /* Structure to hold note of ringtone. */
554
555 typedef struct {
556   u8 duration;
557   u8 note;
558 } GSM_RingtoneNote;
559
560 /* Structure to hold ringtones. */
561
562 typedef struct {
563   char name[20];
564   u8 tempo;
565   u8 NrNotes;
566   GSM_RingtoneNote notes[MAX_RINGTONE_NOTES];
567 } GSM_Ringtone;
568   
569 /* Structure to hold profile entries. */
570
571 typedef struct {
572   int Number;          /* The number of the profile. */
573   char Name[40];       /* The name of the profile. */
574   int DefaultName;     /* 0-6, when default name is used, -1, when not. */
575   int KeypadTone;      /* Volume level for keypad tones. */
576   int Lights;          /* Lights on/off. */
577   int CallAlert;       /* Incoming call alert. */
578   int Ringtone;        /* Ringtone for incoming call alert. */
579   int Volume;          /* Volume of the ringing. */
580   int MessageTone;     /* The tone for message indication. */
581   int WarningTone;     /* The tone for warning messages. */
582   int Vibration;       /* Vibration? */
583   int CallerGroups;    /* CallerGroups. */
584   int AutomaticAnswer; /* Does the phone auto-answer incoming call? */
585 } GSM_Profile;
586
587
588 #define FO_SUBMIT       0x01
589 #define FO_RD           0x40
590 #define FO_VPF_NONE     0x00
591 #define FO_VPF_REL      0x10
592 #define FO_VPF_ABS      0x18
593 #define FO_VPF_ENH      0x08
594 #define FO_SRR          0x20
595 #define FO_UDHI         0x40
596 #define FO_RP           0x80
597 #define FO_DEFAULT      (FO_SUBMIT | FO_VPF_REL | FO_SRR)
598
599 #define PID_DEFAULT     0x00
600 #define PID_TYPE0       0x40
601 #define PID_REPLACE1    0x41
602 #define PID_REPLACE2    0x42
603 #define PID_REPLACE3    0x43
604 #define PID_REPLACE4    0x44
605 #define PID_REPLACE5    0x45
606 #define PID_REPLACE6    0x46
607 #define PID_REPLACE7    0x47
608 #define PID_RETURN_CALL 0x5f
609
610 #define DCS_DEFAULT     0x00
611 #define DCS_MSG_WAIT_VOICE_DISCARD      0xc8
612 #define DCS_MSG_WAIT_VOICE_OFF          0xc0
613 #define DCS_MSG_WAIT_VOICE_STORE        0xd8
614 #define DCS_DATA        0xf4
615 #define DCS_CLASS0      0xf0
616 #define DCS_CLASS1      0xf1
617 #define DCS_CLASS2      0xf2
618 #define DCS_CLASS3      0xf3
619
620 /* Limits for IMEI, Revision and Model string storage. */
621
622 #define GSM_MAX_IMEI_LENGTH     (20)
623 #define GSM_MAX_REVISION_LENGTH (16)
624 #define GSM_MAX_MODEL_LENGTH    (64)
625 #define GSM_MAX_MANUFACTURER_LENGTH (36)
626
627
628
629 /* This is a generic holder for high level information - eg a GSM_Bitmap */
630
631 typedef struct {
632         GSM_SMSMessage *SMSMessage;
633         GSM_PhonebookEntry *PhonebookEntry;
634         GSM_SpeedDial *SpeedDial;
635         GSM_MemoryStatus *MemoryStatus;
636         GSM_SMSStatus *SMSStatus;
637         GSM_MessageCenter *MessageCenter;
638         char *Imei;
639         char *Revision;
640         char *Model;
641         char *Manufacturer;
642         GSM_NetworkInfo *NetworkInfo;
643         GSM_CalendarNote *CalendarNote;
644         GSM_Bitmap *Bitmap;
645         char *BitmapDest;
646         GSM_Ringtone *Ringtone;
647         char *RingtoneDest;
648         GSM_Profile *Profile;
649         GSM_BatteryUnits *BatteryUnits;
650         float *BatteryLevel;
651         GSM_RFUnits *RFUnits;
652         float *RFLevel;
653         GSM_Error (*OutputFn)(char *Display, char *Indicators);
654         char *IncomingCallNr;
655         GSM_PowerSource *PowerSource;
656         GSM_SecurityCode *SecurityCode;
657         GSM_SecurityCodeType *SecurityCodeStatus;
658         GSM_DateTime *DateTime;
659         int *AlarmNumber;
660         GSM_DateTime *AlarmDateTime;
661         char *VoiceNumber;
662         char *DataNumber;
663         char *DataType;
664         void (*DataCallPassUp)(char c);
665         unsigned char *NetMonitorMode;
666         char *NetMonitorScreen;
667         char *DTMF;
668         char *ResetType;
669         RLP_F96Frame *RLPFrame;
670         bool *RLPFrame_out_dtx;
671         GSM_CBMessage *CBMessage;
672         int *SetKeyKey;
673         int *SetKeyUp;
674         char *HandleString;
675         char *CallNo;
676         int *DisplayStatus;
677 } GSM_Data;
678
679
680 /* Global structures intended to be independant of phone etc */
681 /* Obviously currently rather Nokia biased but I think most things */
682 /* (eg at commands) can be enumerated */
683
684
685 /* A structure to hold information about the particular link */
686 /* The link comes 'under' the phone */
687 typedef struct {
688   char PortDevice[20];   /* The port device */
689   int InitLength;        /* Number of chars sent to sync the serial port */
690   GSM_ConnectionType ConnectionType;   /* Connection type, serial, ir etc */
691
692   /* A regularly called loop function */
693   /* timeout can be used to make the function block or not */
694   GSM_Error (*Loop)(struct timeval *timeout);
695
696   /* A pointer to the function used to send out a message */
697   /* This is used by the phone specific code to send a message over the link */
698   GSM_Error (*SendMessage)(u16 messagesize, u8 messagetype, void *message);
699
700 } GSM_Link;
701
702
703 /* Small structure used in GSM_Phone */
704 /* Messagetype is passed to the function in case it is a 'generic' one */
705 typedef struct {
706   u8 MessageType;
707   GSM_Error (*Functions)(int messagetype, unsigned char *buffer, int length, GSM_Data *data);
708 } GSM_IncomingFunctionType;
709
710 typedef enum {
711         GOP_Init,
712         GOP_Terminate,
713         GOP_GetModel,
714         GOP_GetRevision,
715         GOP_GetImei,
716         GOP_GetManufacturer,
717         GOP_Identify,
718         GOP_GetBitmap,
719         GOP_SetBitmap,
720         GOP_SetRingtone,
721         GOP_GetBatteryLevel,
722         GOP_GetRFLevel,
723         GOP_DisplayOutput,
724         GOP_GetMemoryStatus,
725         GOP_ReadPhonebook,
726         GOP_WritePhonebook,
727         GOP_GetPowersource,
728         GOP_GetDisplayStatus,
729         GOP_EnterSecurityCode,
730         GOP_GetSecurityCodeStatus,
731         GOP_GetAlarm,
732         GOP_SetAlarm,
733         GOP_DialVoice,
734         GOP_DialData,
735         GOP_GetSMSStatus,
736         GOP_SetSMSStatus,
737         GOP_GetIncomingCallNr,
738         GOP_GetNetworkInfo,
739         GOP_GetSMS,
740         GOP_DeleteSMS,
741         GOP_SendSMS,
742         GOP_SaveSMS,
743         GOP_GetSpeedDial,
744         GOP_SetSpeedDial,
745         GOP_GetSMSCenter,
746         GOP_SetSMSCenter,
747         GOP_GetDateTime,
748         GOP_SetDateTime,
749         GOP_GetCalendarNote,
750         GOP_WriteCalendarNote,
751         GOP_DeleteCalendarNote,
752         GOP_NetMonitor,
753         GOP_SendDTMF,
754         GOP_Reset,
755         GOP_GetProfile,
756         GOP_SetProfile,
757         GOP_SendRLPFrame,
758         GOP_CancelCall,
759         GOP_EnableDisplayOutput,
760         GOP_DisableDisplayOutput,
761         GOP_EnableCellBroadcast,
762         GOP_DisableCellBroadcast,
763         GOP_ReadCellBroadcast,
764         GOP_SetKey,
765         GOP_HandleString,
766         GOP_AnswerCall,
767         GOP_Max         /* don't append anything after this entry */
768 } GSM_Operation;
769
770 /* This structure contains the 'callups' needed by the statemachine */
771 /* to deal with messages from the phone and other information */
772
773 typedef struct _GSM_Statemachine GSM_Statemachine; 
774
775 typedef struct {
776   /* These make up a list of functions, one for each message type and NULL terminated */
777   GSM_IncomingFunctionType *IncomingFunctions;
778   GSM_Error (*DefaultFunction)(int messagetype, unsigned char *buffer, int length);
779   GSM_Information Info;
780   GSM_Error (*Functions)(GSM_Operation op, GSM_Data *data, GSM_Statemachine *state);
781 } GSM_Phone;
782
783
784 /* The states the statemachine can take */
785
786 typedef enum {
787         Startup,            /* Not yet initialised */
788         Initialised,        /* Ready! */
789         MessageSent,        /* A command has been sent to the link(phone) */ 
790         WaitingForResponse, /* We are waiting for a response from the link(phone) */
791         ResponseReceived    /* A response has been received - waiting for the phone layer to collect it */
792 } GSM_State;
793
794 /* How many message types we can wait for at one */
795 #define SM_MAXWAITINGFOR 3
796
797
798 /* All properties of the state machine */
799
800 struct _GSM_Statemachine{
801         GSM_State CurrentState;
802         GSM_Link Link;
803         GSM_Phone Phone;
804         
805         /* Store last message for resend purposes */
806         u8 LastMsgType;
807         u16 LastMsgSize;
808         void *LastMsg;
809
810         /* The responses we are waiting for */
811         unsigned char NumWaitingFor;
812         unsigned char NumReceived;
813         unsigned char WaitingFor[SM_MAXWAITINGFOR];
814         GSM_Error ResponseError[SM_MAXWAITINGFOR];
815         /* Data structure to be filled in with the response */
816         GSM_Data *Data[SM_MAXWAITINGFOR];
817 };
818
819
820  
821 /* Define the structure used to hold pointers to the various API functions.
822    This is in effect the master list of functions provided by the gnokii API.
823    Modules containing the model specific code each contain one of these
824    structures which is "filled in" with the corresponding function within the
825    model specific code.  If a function is not supported or not implemented, a
826    generic not implemented function is used to return a GE_NOTIMPLEMENTED
827    error code. */
828
829 typedef struct {
830
831   /* FIXME: comment this. */
832
833   GSM_Error (*Initialise)( char *port_device, char *initlength,
834                            GSM_ConnectionType connection,
835                            void (*rlp_callback)(RLP_F96Frame *frame));
836
837   void (*Terminate)(void);      
838
839   GSM_Error (*GetMemoryLocation)( GSM_PhonebookEntry *entry );
840
841   GSM_Error (*WritePhonebookLocation)( GSM_PhonebookEntry *entry );
842
843   GSM_Error (*GetSpeedDial)( GSM_SpeedDial *entry);
844
845   GSM_Error (*SetSpeedDial)( GSM_SpeedDial *entry);
846
847   GSM_Error (*GetMemoryStatus)( GSM_MemoryStatus *Status);
848
849   GSM_Error (*GetSMSStatus)( GSM_SMSStatus *Status);
850
851   GSM_Error (*GetSMSCenter)( GSM_MessageCenter *MessageCenter );
852
853   GSM_Error (*SetSMSCenter)( GSM_MessageCenter *MessageCenter );
854
855   GSM_Error (*GetSMSMessage)( GSM_SMSMessage *Message );
856
857   GSM_Error (*DeleteSMSMessage)( GSM_SMSMessage *Message );
858
859   GSM_Error (*SendSMSMessage)( GSM_SMSMessage *Message );
860
861   GSM_Error (*SaveSMSMessage)( GSM_SMSMessage *Message );
862
863     /* If units is set to a valid GSM_RFUnits value, the code
864        will return level in these units if it is able.  Otherwise
865        value will be returned as GRF_Arbitary.  If phone doesn't
866        support GetRFLevel, function returns GE_NOTSUPPORTED */
867   GSM_Error (*GetRFLevel)( GSM_RFUnits *units, float *level );
868
869     /* Works the same as GetRFLevel, except returns battery
870        level if known. */
871   GSM_Error (*GetBatteryLevel)( GSM_BatteryUnits *units, float *level );
872
873   GSM_Error (*GetPowerSource)( GSM_PowerSource *source);
874
875   GSM_Error (*GetDisplayStatus)( int *Status);
876
877   GSM_Error (*EnterSecurityCode)( GSM_SecurityCode Code);
878
879   GSM_Error (*GetSecurityCodeStatus)( int *Status );
880
881   GSM_Error (*GetIMEI)( char *imei );
882
883   GSM_Error (*GetRevision)( char *revision );
884
885   GSM_Error (*GetModel)( char *model );
886
887   GSM_Error (*GetManufacturer)( char *manufacturer );
888
889   GSM_Error (*GetDateTime)( GSM_DateTime *date_time);
890
891   GSM_Error (*SetDateTime)( GSM_DateTime *date_time);
892
893   GSM_Error (*GetAlarm)( int alarm_number, GSM_DateTime *date_time );
894
895   GSM_Error (*SetAlarm)( int alarm_number, GSM_DateTime *date_time );
896
897   GSM_Error (*DialVoice)( char *Number);
898
899   GSM_Error (*DialData)( char *Number, char type, void (* callpassup)(char c));
900
901   GSM_Error (*GetIncomingCallNr)( char *Number );
902
903   GSM_Error (*GetNetworkInfo) ( GSM_NetworkInfo *NetworkInfo );
904
905   GSM_Error (*GetCalendarNote) ( GSM_CalendarNote *CalendarNote);
906
907   GSM_Error (*WriteCalendarNote) ( GSM_CalendarNote *CalendarNote);
908
909   GSM_Error (*DeleteCalendarNote) ( GSM_CalendarNote *CalendarNote);
910
911   GSM_Error (*NetMonitor) ( unsigned char mode, char *Screen );
912
913   GSM_Error (*SendDTMF) ( char *String );
914
915   GSM_Error (*GetBitmap) ( GSM_Bitmap *Bitmap );
916   
917   GSM_Error (*SetBitmap) ( GSM_Bitmap *Bitmap );
918
919   GSM_Error (*SetRingtone) ( GSM_Ringtone *ringtone );
920
921   GSM_Error (*Reset) ( unsigned char type );
922
923   GSM_Error (*GetProfile) ( GSM_Profile *Profile );
924
925   GSM_Error (*SetProfile) ( GSM_Profile *Profile );
926   
927   bool      (*SendRLPFrame) ( RLP_F96Frame *frame, bool out_dtx );
928
929   GSM_Error (*CancelCall) ();
930   
931   GSM_Error (*EnableDisplayOutput) ();
932   
933   GSM_Error (*DisableDisplayOutput) ();
934  
935   GSM_Error (*EnableCellBroadcast) ();
936
937   GSM_Error (*DisableCellBroadcast) ();
938
939   GSM_Error (*ReadCellBroadcast) ( GSM_CBMessage *Message );
940   
941   GSM_Error (*SetKey) (int c, int up);
942   
943   GSM_Error (*HandleString) (char *s);
944         
945   GSM_Error (*AnswerCall) (char s);
946
947 } GSM_Functions;
948
949 typedef struct {
950   bool first;           /* MUST be set to "true" during the first call of SMS_Deconcatenate() */
951   bool singleshot;      /* no concatenation wrapping was needed */
952   unsigned sequence;    /* =1 for the first part etc. */
953   u8 *sequencep;        /* For updating inside-PDU header sequence number */
954   size_t cargoitems;    /* How many items of MessageText fit in one SMS part */
955   } GSM_Deconcatenate_state;
956
957 /* Undefined functions in fbus/mbus files */
958 extern GSM_Error Unimplemented(void);
959 #define UNIMPLEMENTED (void *) Unimplemented
960
961 extern unsigned char GSM_Default_Alphabet[];
962
963 /* Coding functions */
964 extern void EncodeAscii (unsigned char* dest, const unsigned char* src, int len);
965 extern void DecodeAscii (unsigned char* dest, const unsigned char* src, int len);
966 extern void EncodeUnicode (unsigned char* dest, const unsigned char* src, int len);
967 extern void DecodeUnicode (unsigned char* dest, const unsigned char* src, int len);
968
969 extern unsigned char EncodeWithDefaultAlphabet(unsigned char);
970 extern unsigned char DecodeWithDefaultAlphabet(unsigned char);
971 extern wchar_t EncodeWithUnicodeAlphabet(unsigned char);
972 extern unsigned char DecodeWithUnicodeAlphabet(wchar_t);
973 extern GSM_MemoryType StrToMemoryType (const char *s);
974 extern unsigned char SMS_Validity_to_VP(int Validity);
975 extern int SMS_VP_to_Validity(GSM_SMSMessageValidity Validity);
976 extern int SemiOctetPack(char *Number, unsigned char *Output);
977 extern char *SemiOctetUnpack(char *dest,size_t destlen,u8 *Number,size_t nibbles);
978 extern char *SemiOctetUnpack_static(u8 *Number,size_t nibbles);
979 #define SEMIOCTETUNPACK_STATIC_BYTES(Number)   (SemiOctetUnpack_static((Number)+1,*(Number)*2))
980 #define SEMIOCTETUNPACK_STATIC_NIBBLES(Number) (SemiOctetUnpack_static((Number)+1,*(Number)  ))
981 extern int PackSevenBitsToEight(int UsedBits, unsigned char *input, unsigned char *output);
982 extern int UnpackEightBitsToSeven(int offset, int in_length, int out_length,
983                                   unsigned char *input, unsigned char *output);
984 extern GSM_Error SMS_SetupUDH(GSM_SMSMessage *sms,GSM_UDH UDHType);
985 extern GSM_UDH SMS_DetectUDH(GSM_SMSMessage *sms);
986 extern bool SMS_Deconcatenate(GSM_Deconcatenate_state *state,GSM_SMSMessage *sms,char *buf,size_t buflen,bool useudh);
987 extern u8 *SMS_BlockFromHex(u8 *d,const char *s,size_t len);
988 extern char *SMS_BlockToHex(char *d,const u8 *s,size_t len);
989
990 inline void GSM_DataClear(GSM_Data *data);
991
992 #endif  /* __gsm_common_h */