7 A Linux/Unix toolset and driver for Nokia mobile phones.
9 Copyright (C) 1999, 2000 Hugh Blemings & Pavel JanÃk ml.
11 Released under the terms of the GNU GPL, see file COPYING for more details.
13 Header file for the definitions, enums etc. that are used by all models of
18 #ifndef __gsm_common_h
19 #define __gsm_common_h
23 #include "data/rlp-common.h"
26 /* Type of connection. Now we support serial connection with FBUS cable and
27 IR (only with 61x0 models) */
30 GCT_Serial, /* Serial connection. */
31 GCT_DAU9P, /* Serial connection using DAU9P cable; use only with 6210/7110 if you want faster initialization */
32 GCT_Infrared, /* Infrared connection. */
33 GCT_Tekram, /* Tekram Ir-Dongle */
37 /* Maximum length of device name for serial port */
39 #define GSM_MAX_DEVICE_NAME_LENGTH (100)
41 /* Define an enum for specifying memory types for retrieving phonebook
42 entries, SMS messages etc. This type is not mobile specific - the model
43 code should take care of translation to mobile specific numbers - see 6110
45 01/07/99: Two letter codes follow GSM 07.07 release 6.2.0
49 GMT_ME, /* Internal memory of the mobile equipment */
50 GMT_SM, /* SIM card memory */
51 GMT_FD, /* Fixed dial numbers */
52 GMT_ON, /* Own numbers */
53 GMT_EN, /* Emergency numbers */
54 GMT_DC, /* Dialled numbers */
55 GMT_RC, /* Received numbers */
56 GMT_MC, /* Missed numbers */
57 GMT_LD, /* Last dialed */
58 GMT_MT, /* combined ME and SIM phonebook */
59 GMT_TA, /* for compatibility only: TA=computer memory */
60 GMT_CB, /* Currently selected memory */
61 GMT_XX = 0xff /* Error code for unknown memory type (returned by fbus-xxxx functions). */
64 /* Power source types */
67 GPS_ACDC=1, /* AC/DC powered (charging) */
68 GPS_BATTERY /* Internal battery */
71 /* Definition of security codes. */
74 GSCT_SecurityCode = 0x01, /* Security code. */
76 GSCT_Pin2, /* PIN 2. */
78 GSCT_Puk2, /* PUK 2. */
79 GSCT_None /* Code not needed. */
80 } GSM_SecurityCodeType;
82 /* Security code definition. */
85 GSM_SecurityCodeType Type; /* Type of the code. */
86 char Code[10]; /* Actual code. */
89 /* This structure is used to get the current network status */
92 char NetworkCode[10]; /* GSM network code */
93 char CellID[10]; /* CellID */
94 char LAC[10]; /* LAC */
97 /* Limits for sizing of array in GSM_PhonebookEntry. Individual handsets may
98 not support these lengths so they have their own limits set. */
100 #define GSM_MAX_PHONEBOOK_NAME_LENGTH (50) /* For 7110 */
101 #define GSM_MAX_PHONEBOOK_NUMBER_LENGTH (48) /* For 7110 */
102 #define GSM_MAX_PHONEBOOK_TEXT_LENGTH (60) /* For 7110 */
103 #define GSM_MAX_PHONEBOOK_SUB_ENTRIES (8) /* For 7110 */
104 /* 7110 is able to in one
105 * entry 5 numbers and 2
106 * texts [email,notice,postal] */
108 /* Here is a macro for models that do not support caller groups. */
110 #define GSM_GROUPS_NOT_SUPPORTED -1
112 /* This data type is used to report the number of used and free positions in
113 memory (sim or internal). */
116 GSM_MemoryType MemoryType; /* Type of the memory */
117 int Used; /* Number of used positions */
118 int Free; /* Number of free positions */
121 /* Some phones (at the moment 6210/7110) supports extended phonebook
122 with additional data. Here we have structures for them */
138 GSM_Date = 0x13 /* Date is used for DC,RC,etc (last calls) */
142 bool AlarmEnabled; /* Is alarm set ? */
143 int Year; /* The complete year specification - e.g. 1999. Y2K :-) */
144 int Month; /* January = 1 */
149 int Timezone; /* The difference between local time and GMT */
153 GSM_EntryType EntryType;
154 GSM_Number_Type NumberType;
156 char Number[GSM_MAX_PHONEBOOK_TEXT_LENGTH + 1]; /* Number */
157 GSM_DateTime Date; /* or the last calls list */
160 } GSM_SubPhonebookEntry;
162 /* Define datatype for phonebook entry, used for getting/writing phonebook
166 bool Empty; /* Is this entry empty? */
167 char Name[GSM_MAX_PHONEBOOK_NAME_LENGTH + 1]; /* Plus 1 for
169 char Number[GSM_MAX_PHONEBOOK_NUMBER_LENGTH + 1]; /* Number */
170 GSM_MemoryType MemoryType; /* Type of memory */
171 int Group; /* Group */
172 int Location; /* Location */
173 GSM_DateTime Date; /* The record date and time
175 GSM_SubPhonebookEntry SubEntries[GSM_MAX_PHONEBOOK_SUB_ENTRIES];
177 * additional phonebook
179 int SubEntriesCount; /* Should be 0, if extended
180 phonebook is not used */
181 } GSM_PhonebookEntry;
183 /* This define speed dialing entries. */
186 int Number; /* Which number is used to dialing? */
187 GSM_MemoryType MemoryType; /* Memory type of the number. */
188 int Location; /* Location of the number in MemoryType. */
191 /* Define enum used to describe what sort of date/time support is
195 GDT_None, /* The mobile phone doesn't support time and date. */
196 GDT_TimeOnly, /* The mobile phone supports only time. */
197 GDT_DateOnly, /* The mobile phone supports only date. */
198 GDT_DateTime /* Wonderful phone - it supports date and time. */
199 } GSM_DateTimeSupport;
201 /* Define enums for RF units. GRF_CSQ asks for units in form used
202 in AT+CSQ command as defined by GSM 07.07 */
213 /* Define enums for Battery units. */
222 /* Define enums for Calendar Note types */
225 GCN_REMINDER=1, /* Reminder */
227 GCN_MEETING, /* Meeting */
228 GCN_BIRTHDAY /* Birthday */
229 } GSM_CalendarNoteType;
231 /* Calendar note type */
234 int Location; /* The number of the note in the phone memory */
235 GSM_CalendarNoteType Type; /* The type of the note */
236 GSM_DateTime Time; /* The time of the note */
237 GSM_DateTime Alarm; /* The alarm of the note */
238 char Text[20]; /* The text of the note */
239 char Phone[20]; /* For Call only: the phone number */
240 double Recurance; /* Recurance of the note */
243 /* This structure is provided to allow common information about the particular
244 model to be looked up in a model independant way. Some of the values here
245 define minimum and maximum levels for values retrieved by the various Get
246 functions for example battery level. They are not defined as constants to
247 allow model specific code to set them during initialisation */
251 char *Models; /* Models covered by this type, pipe '|' delimited. */
253 /* Minimum and maximum levels for RF signal strength. Units are as per the
254 setting of RFLevelUnits. The setting of RFLevelUnits indicates the
255 default or "native" units used. In the case of the 3110 and 6110 series
256 these are arbitrary, ranging from 0 to 4. */
260 GSM_RFUnits RFLevelUnits;
262 /* Minimum and maximum levels for battery level. Again, units are as per the
263 setting of GSM_BatteryLevelUnits. The value that BatteryLevelUnits is set
264 to indicates the "native" or default value that the phone supports. In the
265 case of the 3110 and 6110 series these are arbitrary, ranging from 0 to 4. */
267 float MaxBatteryLevel;
268 float MinBatteryLevel;
269 GSM_BatteryUnits BatteryLevelUnits;
271 /* FIXME: some very similar code is in common/misc.c */
273 /* Information about date, time and alarm support. In case of alarm
274 information we provide value for the number of alarms supported. */
276 GSM_DateTimeSupport DateTimeSupport;
277 GSM_DateTimeSupport AlarmSupport;
279 u8 StartupLogoH; /* Logo Widths and Heights - if supported */
287 /* This enum is used for display status. */
290 DS_Call_In_Progress, /* Call in progress. */
291 DS_Unknown, /* The meaning is unknown now :-( */
292 DS_Unread_SMS, /* There is Unread SMS. */
293 DS_Voice_Call, /* Voice call active. */
294 DS_Fax_Call, /* Fax call active. */
295 DS_Data_Call, /* Data call active. */
296 DS_Keyboard_Lock, /* Keyboard lock status. */
297 DS_SMS_Storage_Full /* Full SMS Memory. */
298 } DisplayStatusEntity;
312 #define GSM_MAX_BITMAP_SIZE 864
314 /* Structure to hold incoming/outgoing bitmaps (and welcome-notes). */
317 u8 height; /* Bitmap height (pixels) */
318 u8 width; /* Bitmap width (pixels) */
319 u16 size; /* Bitmap size (bytes) */
320 GSM_Bitmap_Types type; /* Bitmap type */
321 char netcode[7]; /* Network operator code */
322 char text[256]; /* Text used for welcome-note or callergroup name */
323 char dealertext[256]; /* Text used for dealer welcome-note */
324 bool dealerset; /* Is dealer welcome-note set now ? */
325 unsigned char bitmap[GSM_MAX_BITMAP_SIZE]; /* Actual Bitmap */
326 char number; /* Caller group number */
327 char ringtone; /* Ringtone no sent with caller group */
331 /* NoteValue is encoded as octave(scale)*14 + note */
332 /* where for note: c=0, d=2, e=4 .... */
333 /* ie. c#=1 and 5 and 13 are invalid */
334 /* note=255 means a pause */
336 #define MAX_RINGTONE_NOTES 256
338 /* Structure to hold note of ringtone. */
345 /* Structure to hold ringtones. */
351 GSM_RingtoneNote notes[MAX_RINGTONE_NOTES];
354 /* Structure to hold profile entries. */
357 int Number; /* The number of the profile. */
358 char Name[40]; /* The name of the profile. */
359 int DefaultName; /* 0-6, when default name is used, -1, when not. */
360 int KeypadTone; /* Volume level for keypad tones. */
361 int Lights; /* Lights on/off. */
362 int CallAlert; /* Incoming call alert. */
363 int Ringtone; /* Ringtone for incoming call alert. */
364 int Volume; /* Volume of the ringing. */
365 int MessageTone; /* The tone for message indication. */
366 int WarningTone; /* The tone for warning messages. */
367 int Vibration; /* Vibration? */
368 int CallerGroups; /* CallerGroups. */
369 int AutomaticAnswer; /* Does the phone auto-answer incoming call? */
373 #define FO_SUBMIT 0x01
375 #define FO_VPF_NONE 0x00
376 #define FO_VPF_REL 0x10
377 #define FO_VPF_ABS 0x18
378 #define FO_VPF_ENH 0x08
382 #define FO_DEFAULT (FO_SUBMIT | FO_VPF_REL | FO_SRR)
384 #define PID_DEFAULT 0x00
385 #define PID_TYPE0 0x40
386 #define PID_REPLACE1 0x41
387 #define PID_REPLACE2 0x42
388 #define PID_REPLACE3 0x43
389 #define PID_REPLACE4 0x44
390 #define PID_REPLACE5 0x45
391 #define PID_REPLACE6 0x46
392 #define PID_REPLACE7 0x47
393 #define PID_RETURN_CALL 0x5f
395 #define DCS_DEFAULT 0x00
396 #define DCS_MSG_WAIT_VOICE_DISCARD 0xc8
397 #define DCS_MSG_WAIT_VOICE_OFF 0xc0
398 #define DCS_MSG_WAIT_VOICE_STORE 0xd8
399 #define DCS_DATA 0xf4
400 #define DCS_CLASS0 0xf0
401 #define DCS_CLASS1 0xf1
402 #define DCS_CLASS2 0xf2
403 #define DCS_CLASS3 0xf3
405 /* Limits for IMEI, Revision and Model string storage. */
406 #define GSM_MAX_IMEI_LENGTH (20)
407 #define GSM_MAX_REVISION_LENGTH (6)
408 #define GSM_MAX_MODEL_LENGTH (6)
410 /* Data structures for the call divert */
415 GSM_CDV_NotAvailable,
417 } GSM_CDV_DivertTypes;
420 GSM_CDV_VoiceCalls = 0x01,
427 GSM_CDV_Disable = 0x00,
428 GSM_CDV_Enable = 0x01,
429 GSM_CDV_Query = 0x02,
430 GSM_CDV_Register = 0x03,
431 GSM_CDV_Erasure = 0x04
435 GSM_CDV_DivertTypes DType;
436 GSM_CDV_CallTypes CType;
437 GSM_CDV_Opers Operation;
439 unsigned int Timeout;
442 /* This is a generic holder for high level information - eg a GSM_Bitmap */
445 SMS_Folder *SMSFolder;
446 SMS_FolderList *SMSFolderList;
447 GSM_SMSMessage *SMSMessage;
448 GSM_PhonebookEntry *PhonebookEntry;
449 GSM_SpeedDial *SpeedDial;
450 GSM_MemoryStatus *MemoryStatus;
451 GSM_SMSMemoryStatus *SMSStatus;
452 SMS_MessageCenter *MessageCenter;
457 GSM_NetworkInfo *NetworkInfo;
458 GSM_CalendarNote *CalendarNote;
460 GSM_Ringtone *Ringtone;
461 GSM_Profile *Profile;
462 GSM_BatteryUnits *BatteryUnits;
464 GSM_RFUnits *RFUnits;
466 GSM_Error (*OutputFn)(char *Display, char *Indicators);
467 char *IncomingCallNr;
468 GSM_PowerSource *PowerSource;
469 GSM_DateTime *DateTime;
470 GSM_CallDivert *CallDivert;
474 /* Global structures intended to be independant of phone etc */
475 /* Obviously currently rather Nokia biased but I think most things */
476 /* (eg at commands) can be enumerated */
479 /* A structure to hold information about the particular link */
480 /* The link comes 'under' the phone */
482 char PortDevice[20]; /* The port device */
483 int InitLength; /* Number of chars sent to sync the serial port */
484 GSM_ConnectionType ConnectionType; /* Connection type, serial, ir etc */
486 /* A regularly called loop function */
487 /* timeout can be used to make the function block or not */
488 GSM_Error (*Loop)(struct timeval *timeout);
490 /* A pointer to the function used to send out a message */
491 /* This is used by the phone specific code to send a message over the link */
492 GSM_Error (*SendMessage)(u16 messagesize, u8 messagetype, void *message);
497 /* Small structure used in GSM_Phone */
498 /* Messagetype is passed to the function in case it is a 'generic' one */
501 GSM_Error (*Functions)(int messagetype, unsigned char *buffer, int length, GSM_Data *data);
502 } GSM_IncomingFunctionType;
522 GOP_GetIncomingCallNr,
532 GOP_Max, /* don't append anything after this entry */
535 /* This structure contains the 'callups' needed by the statemachine */
536 /* to deal with messages from the phone and other information */
538 typedef struct _GSM_Statemachine GSM_Statemachine;
541 /* These make up a list of functions, one for each message type and NULL terminated */
542 GSM_IncomingFunctionType *IncomingFunctions;
543 GSM_Error (*DefaultFunction)(int messagetype, unsigned char *buffer, int length);
544 GSM_Information Info;
545 GSM_Error (*Functions)(GSM_Operation op, GSM_Data *data, GSM_Statemachine *state);
549 /* The states the statemachine can take */
552 Startup, /* Not yet initialised */
553 Initialised, /* Ready! */
554 MessageSent, /* A command has been sent to the link(phone) */
555 WaitingForResponse, /* We are waiting for a response from the link(phone) */
556 ResponseReceived /* A response has been received - waiting for the phone layer to collect it */
559 /* How many message types we can wait for at one */
560 #define SM_MAXWAITINGFOR 3
563 /* All properties of the state machine */
565 struct _GSM_Statemachine{
566 GSM_State CurrentState;
570 /* Store last message for resend purposes */
575 /* The responses we are waiting for */
576 unsigned char NumWaitingFor;
577 unsigned char NumReceived;
578 unsigned char WaitingFor[SM_MAXWAITINGFOR];
579 GSM_Error ResponseError[SM_MAXWAITINGFOR];
580 /* Data structure to be filled in with the response */
581 GSM_Data *Data[SM_MAXWAITINGFOR];
586 /* Define the structure used to hold pointers to the various API functions.
587 This is in effect the master list of functions provided by the gnokii API.
588 Modules containing the model specific code each contain one of these
589 structures which is "filled in" with the corresponding function within the
590 model specific code. If a function is not supported or not implemented, a
591 generic not implemented function is used to return a GE_NOTIMPLEMENTED
596 /* FIXME: comment this. */
598 GSM_Error (*Initialise)( char *port_device, char *initlength,
599 GSM_ConnectionType connection,
600 void (*rlp_callback)(RLP_F96Frame *frame));
602 void (*Terminate)(void);
604 GSM_Error (*GetMemoryLocation)( GSM_PhonebookEntry *entry );
606 GSM_Error (*WritePhonebookLocation)( GSM_PhonebookEntry *entry );
608 GSM_Error (*GetSpeedDial)( GSM_SpeedDial *entry);
610 GSM_Error (*SetSpeedDial)( GSM_SpeedDial *entry);
612 GSM_Error (*GetMemoryStatus)( GSM_MemoryStatus *Status);
614 GSM_Error (*GetSMSStatus)( GSM_SMSMemoryStatus *Status);
616 GSM_Error (*GetSMSCenter)( SMS_MessageCenter *MessageCenter );
618 GSM_Error (*SetSMSCenter)( SMS_MessageCenter *MessageCenter );
620 GSM_Error (*GetSMSMessage)( GSM_SMSMessage *Message );
622 GSM_Error (*DeleteSMSMessage)( GSM_SMSMessage *Message );
624 GSM_Error (*SendSMSMessage)( GSM_SMSMessage *Message, int size );
626 GSM_Error (*SaveSMSMessage)( GSM_SMSMessage *Message );
628 /* If units is set to a valid GSM_RFUnits value, the code
629 will return level in these units if it is able. Otherwise
630 value will be returned as GRF_Arbitary. If phone doesn't
631 support GetRFLevel, function returns GE_NOTSUPPORTED */
632 GSM_Error (*GetRFLevel)( GSM_RFUnits *units, float *level );
634 /* Works the same as GetRFLevel, except returns battery
636 GSM_Error (*GetBatteryLevel)( GSM_BatteryUnits *units, float *level );
638 GSM_Error (*GetPowerSource)( GSM_PowerSource *source);
640 GSM_Error (*GetDisplayStatus)( int *Status);
642 GSM_Error (*EnterSecurityCode)( GSM_SecurityCode Code);
644 GSM_Error (*GetSecurityCodeStatus)( int *Status );
646 GSM_Error (*GetIMEI)( char *imei );
648 GSM_Error (*GetRevision)( char *revision );
650 GSM_Error (*GetModel)( char *model );
652 GSM_Error (*GetManufacturer)( char *manufacturer );
654 GSM_Error (*GetDateTime)( GSM_DateTime *date_time);
656 GSM_Error (*SetDateTime)( GSM_DateTime *date_time);
658 GSM_Error (*GetAlarm)( int alarm_number, GSM_DateTime *date_time );
660 GSM_Error (*SetAlarm)( int alarm_number, GSM_DateTime *date_time );
662 GSM_Error (*DialVoice)( char *Number);
664 GSM_Error (*DialData)( char *Number, char type, void (* callpassup)(char c));
666 GSM_Error (*GetIncomingCallNr)( char *Number );
668 GSM_Error (*GetNetworkInfo) ( GSM_NetworkInfo *NetworkInfo );
670 GSM_Error (*GetCalendarNote) ( GSM_CalendarNote *CalendarNote);
672 GSM_Error (*WriteCalendarNote) ( GSM_CalendarNote *CalendarNote);
674 GSM_Error (*DeleteCalendarNote) ( GSM_CalendarNote *CalendarNote);
676 GSM_Error (*NetMonitor) ( unsigned char mode, char *Screen );
678 GSM_Error (*SendDTMF) ( char *String );
680 GSM_Error (*GetBitmap) ( GSM_Bitmap *Bitmap );
682 GSM_Error (*SetBitmap) ( GSM_Bitmap *Bitmap );
684 GSM_Error (*SetRingtone) ( GSM_Ringtone *ringtone );
686 GSM_Error (*SendRingtone) ( GSM_Ringtone *ringtone, char *dest );
688 GSM_Error (*Reset) ( unsigned char type );
690 GSM_Error (*GetProfile) ( GSM_Profile *Profile );
692 GSM_Error (*SetProfile) ( GSM_Profile *Profile );
694 bool (*SendRLPFrame) ( RLP_F96Frame *frame, bool out_dtx );
696 GSM_Error (*CancelCall) ();
698 GSM_Error (*EnableDisplayOutput) ();
700 GSM_Error (*DisableDisplayOutput) ();
702 GSM_Error (*EnableCellBroadcast) ();
704 GSM_Error (*DisableCellBroadcast) ();
706 GSM_Error (*ReadCellBroadcast) ( GSM_CBMessage *Message );
708 GSM_Error (*SetKey) (int c, int up);
710 GSM_Error (*HandleString) (char *s);
712 GSM_Error (*AnswerCall) (char s);
716 /* Undefined functions in fbus/mbus files */
717 extern GSM_Error Unimplemented(void);
718 #define UNIMPLEMENTED (void *) Unimplemented
720 extern GSM_MemoryType StrToMemoryType (const char *s);
722 inline void GSM_DataClear(GSM_Data *data);
724 #endif /* __gsm_common_h */