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