This commit was generated by cvs2svn to compensate for changes in r164,
[gnokii.git] / common / gsm-api.c
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   Provides a generic API for accessing functions on the phone, wherever
14   possible hiding the model specific details.
15
16   The underlying code should run in it's own thread to allow communications to
17   the phone to be run independantly of mailing code that calls these API
18   functions.
19
20   Unless otherwise noted, all functions herein block until they complete.  The
21   functions themselves are defined in a structure in gsm-common.h.
22
23   $Log$
24   Revision 1.1.1.5  2002/04/03 00:07:54  short
25   Found in "gnokii-working" directory, some November-patches version
26
27   Revision 1.31  2001/11/08 16:45:58  pkot
28   Obsolete old structure, kill treads where possible and make shared library
29
30   Revision 1.30  2001/08/09 11:51:38  pkot
31   Generic AT support updates and cleanup (Manfred Jonsson)
32
33   Revision 1.29  2001/07/27 00:02:20  pkot
34   Generic AT support for the new structure (Manfred Jonsson)
35
36   Revision 1.28  2001/06/06 09:05:56  machek
37   Convert Grab/Release display to new structure.
38
39   Revision 1.27  2001/05/07 14:13:06  machek
40   nokia-2110 module converted to suit new API better. --identify now works.
41
42   Revision 1.26  2001/04/25 12:54:47  machek
43   Partly converted nokia 2110 to "new" form, and moved it to phone
44   directory.
45
46   Revision 1.25  2001/03/26 23:39:21  pkot
47   Minor updates:
48    - Windows INLINE patch (Manfred Jonsson)
49    - patch to configure.in to compile under FreeBSD (Panagiotis Astithas)
50    - other cleanups (me)
51
52   
53 */
54
55 #include <stdio.h>
56 #include <string.h>
57
58 #include "misc.h"
59 #include "gsm-common.h"
60 #include "data/rlp-common.h"
61 #include "gsm-statemachine.h"
62 #include "phones/nk7110.h"
63 #include "phones/nk6100.h"
64 #include "phones/nk3110.h"
65 #include "phones/nk2110.h"
66
67
68 /* GSM_LinkOK is set to true once normal communications with the phone have
69    been established. */
70
71 bool *GSM_LinkOK;
72 bool LinkAlwaysOK = true;
73
74 /* Define pointer to the GSM_Functions structure used by external code to call
75    relevant API functions. This structure is defined in gsm-common.h. */
76
77 GSM_Functions *GSM;
78
79 /* Define pointer to the GSM_Information structure used by external code to
80    obtain information that varies from model to model. This structure is also
81    defined in gsm-common.h */
82
83 GSM_Information         *GSM_Info;
84
85
86
87 /* From here starts the ugly compatibility cludge to complete WIPE OUT the
88  * insane "Sorry, phone has not yet been converted to new style.
89  * Phone.Functions == NULL!" message out of the Earth surface to make the world
90  * a happy place back again! Wiping out, wiping out, wiping out!
91  * The most World's evil GSM_Error code: GE_NOTIMPLEMENTED
92  * Completely non-systematic naming is not my souvenir - it is just copied
93  * from the existing include files. (Jan Kratochvil)
94  */
95
96 static GSM_Statemachine *compat_Functions_Statemachine;
97
98 #define INVOKE_COMPAT_FUNCTIONS_SM(gop) \
99         (compat_Functions_Statemachine->Phone.Functions((gop),&data,compat_Functions_Statemachine))
100 #define RETURN_COMPAT_FUNCTIONS_SM(gop) \
101         return((INVOKE_COMPAT_FUNCTIONS_SM((gop))))
102 #define BODY_COMPAT_FUNCTIONS_SM_CORE(core,gop) \
103         GSM_Data data; \
104         core \
105         RETURN_COMPAT_FUNCTIONS_SM((gop));
106 #define BODY_COMPAT_FUNCTIONS_SM0(gop) \
107         BODY_COMPAT_FUNCTIONS_SM_CORE(  ,(gop))
108 #define BODY_COMPAT_FUNCTIONS_SM1(field1,arg1,gop) \
109         BODY_COMPAT_FUNCTIONS_SM_CORE( data.field1=(arg1); ,(gop))
110 #define BODY_COMPAT_FUNCTIONS_SM2(field1,arg1,field2,arg2,gop) \
111         BODY_COMPAT_FUNCTIONS_SM_CORE( data.field1=(arg1);data.field2=(arg2); ,(gop))
112 #define BODY_COMPAT_FUNCTIONS_SM3(field1,arg1,field2,arg2,field3,arg3,gop) \
113         BODY_COMPAT_FUNCTIONS_SM_CORE( data.field1=(arg1);data.field2=(arg2);data.field3=(arg3); ,(gop))
114
115 static GSM_Error compat_Functions_Initialise
116         (char *port_device, char *initlength, GSM_ConnectionType connection, void (*rlp_callback)(RLP_F96Frame *frame))
117 {
118         fprintf(stderr,"FATAL: GSM->Initialise called for new style phone implementation!\n");
119         return(GE_NOTIMPLEMENTED);
120 }
121
122 static void compat_Functions_Terminate(void)
123 {
124 GSM_Data data;  /* void */
125
126         INVOKE_COMPAT_FUNCTIONS_SM(GOP_Terminate);
127 }
128
129 static GSM_Error compat_Functions_GetMemoryLocation( GSM_PhonebookEntry *entry )
130 {
131         BODY_COMPAT_FUNCTIONS_SM1(PhonebookEntry,entry,GOP_ReadPhonebook);
132 }
133
134 static GSM_Error compat_Functions_WritePhonebookLocation( GSM_PhonebookEntry *entry )
135 {
136         BODY_COMPAT_FUNCTIONS_SM1(PhonebookEntry,entry,GOP_WritePhonebook);
137 }
138
139 static GSM_Error compat_Functions_GetSpeedDial( GSM_SpeedDial *entry )
140 {
141         BODY_COMPAT_FUNCTIONS_SM1(SpeedDial,entry,GOP_GetSpeedDial);
142 }
143
144 static GSM_Error compat_Functions_SetSpeedDial( GSM_SpeedDial *entry )
145 {
146         BODY_COMPAT_FUNCTIONS_SM1(SpeedDial,entry,GOP_SetSpeedDial);
147 }
148
149 static GSM_Error compat_Functions_GetMemoryStatus( GSM_MemoryStatus *Status )
150 {
151         BODY_COMPAT_FUNCTIONS_SM1(MemoryStatus,Status,GOP_GetMemoryStatus);
152 }
153
154 static GSM_Error compat_Functions_GetSMSStatus( GSM_SMSStatus *Status )
155 {
156         BODY_COMPAT_FUNCTIONS_SM1(SMSStatus,Status,GOP_GetSMSStatus);
157 }
158
159 static GSM_Error compat_Functions_GetSMSCenter( GSM_MessageCenter *MessageCenter )
160 {
161         BODY_COMPAT_FUNCTIONS_SM1(MessageCenter,MessageCenter,GOP_GetSMSCenter);
162 }
163
164 static GSM_Error compat_Functions_SetSMSCenter( GSM_MessageCenter *MessageCenter )
165 {
166         BODY_COMPAT_FUNCTIONS_SM1(MessageCenter,MessageCenter,GOP_SetSMSCenter);
167 }
168
169 static GSM_Error compat_Functions_GetSMSMessage( GSM_SMSMessage *Message )
170 {
171         BODY_COMPAT_FUNCTIONS_SM1(SMSMessage,Message,GOP_GetSMS);
172 }
173
174 static GSM_Error compat_Functions_DeleteSMSMessage( GSM_SMSMessage *Message )
175 {
176         BODY_COMPAT_FUNCTIONS_SM1(SMSMessage,Message,GOP_DeleteSMS);
177 }
178
179 static GSM_Error compat_Functions_SendSMSMessage( GSM_SMSMessage *Message )
180 {
181         BODY_COMPAT_FUNCTIONS_SM1(SMSMessage,Message,GOP_SendSMS);
182 }
183
184 static GSM_Error compat_Functions_SaveSMSMessage( GSM_SMSMessage *Message )
185 {
186         BODY_COMPAT_FUNCTIONS_SM1(SMSMessage,Message,GOP_SaveSMS);
187 }
188
189 static GSM_Error compat_Functions_GetRFLevel( GSM_RFUnits *units, float *level )
190 {
191         BODY_COMPAT_FUNCTIONS_SM2(RFUnits,units,RFLevel,level,GOP_GetRFLevel);
192 }
193
194 static GSM_Error compat_Functions_GetBatteryLevel( GSM_BatteryUnits *units, float *level )
195 {
196         BODY_COMPAT_FUNCTIONS_SM2(BatteryUnits,units,BatteryLevel,level,GOP_GetBatteryLevel);
197 }
198
199 static GSM_Error compat_Functions_GetPowerSource( GSM_PowerSource *source )
200 {
201         BODY_COMPAT_FUNCTIONS_SM1(PowerSource,source,GOP_GetPowersource);
202 }
203
204 static GSM_Error compat_Functions_GetDisplayStatus( int *Status )
205 {
206         BODY_COMPAT_FUNCTIONS_SM1(DisplayStatus,Status,GOP_GetDisplayStatus);
207 }
208
209 static GSM_Error compat_Functions_EnterSecurityCode( GSM_SecurityCode Code )
210 {
211         BODY_COMPAT_FUNCTIONS_SM1(SecurityCode,&Code,GOP_EnterSecurityCode);
212 }
213
214 /* FIXME: GetSecurityCodeStatus() should have GSM_SecurityCodeType as its argument!
215  */
216 static GSM_Error compat_Functions_GetSecurityCodeStatus( int *Status )
217 {
218 GSM_SecurityCodeType status_local;
219 GSM_Data data;
220 GSM_Error err;
221
222         data.SecurityCodeStatus=&status_local;
223         err=INVOKE_COMPAT_FUNCTIONS_SM(GOP_GetSecurityCodeStatus);
224         *Status=status_local;
225         return(err);
226 }
227
228 static GSM_Error compat_Functions_GetIMEI( char *imei )
229 {
230         BODY_COMPAT_FUNCTIONS_SM1(Imei,imei,GOP_GetImei);
231 }
232
233 static GSM_Error compat_Functions_GetRevision( char *revision )
234 {
235         BODY_COMPAT_FUNCTIONS_SM1(Revision,revision,GOP_GetRevision);
236 }
237
238 static GSM_Error compat_Functions_GetModel( char *model )
239 {
240         BODY_COMPAT_FUNCTIONS_SM1(Model,model,GOP_GetModel);
241 }
242
243 static GSM_Error compat_Functions_GetManufacturer( char *manufacturer )
244 {
245         BODY_COMPAT_FUNCTIONS_SM1(Manufacturer,manufacturer,GOP_GetManufacturer);
246 }
247
248 static GSM_Error compat_Functions_GetDateTime( GSM_DateTime *date_time)
249 {
250         BODY_COMPAT_FUNCTIONS_SM1(DateTime,date_time,GOP_GetDateTime);
251 }
252
253 static GSM_Error compat_Functions_SetDateTime( GSM_DateTime *date_time)
254 {
255         BODY_COMPAT_FUNCTIONS_SM1(DateTime,date_time,GOP_SetDateTime);
256 }
257
258 static GSM_Error compat_Functions_GetAlarm( int alarm_number, GSM_DateTime *date_time )
259 {
260         BODY_COMPAT_FUNCTIONS_SM2(AlarmNumber,&alarm_number,AlarmDateTime,date_time,GOP_GetAlarm);
261 }
262
263 static GSM_Error compat_Functions_SetAlarm( int alarm_number, GSM_DateTime *date_time )
264 {
265         BODY_COMPAT_FUNCTIONS_SM2(AlarmNumber,&alarm_number,AlarmDateTime,date_time,GOP_SetAlarm);
266 }
267
268 static GSM_Error compat_Functions_DialVoice( char *Number )
269 {
270         BODY_COMPAT_FUNCTIONS_SM1(VoiceNumber,Number,GOP_DialVoice);
271 }
272
273 static GSM_Error compat_Functions_DialData( char *Number, char type, void (* callpassup)(char c) )
274 {
275         BODY_COMPAT_FUNCTIONS_SM3(DataNumber,Number,DataType,&type,DataCallPassUp,callpassup,GOP_DialData);
276 }
277
278 static GSM_Error compat_Functions_GetIncomingCallNr( char *Number )
279 {
280         BODY_COMPAT_FUNCTIONS_SM1(IncomingCallNr,Number,GOP_GetIncomingCallNr);
281 }
282
283 static GSM_Error compat_Functions_GetNetworkInfo ( GSM_NetworkInfo *NetworkInfo )
284 {
285         BODY_COMPAT_FUNCTIONS_SM1(NetworkInfo,NetworkInfo,GOP_GetNetworkInfo);
286 }
287
288 static GSM_Error compat_Functions_GetCalendarNote ( GSM_CalendarNote *CalendarNote)
289 {
290         BODY_COMPAT_FUNCTIONS_SM1(CalendarNote,CalendarNote,GOP_GetCalendarNote);
291 }
292
293 static GSM_Error compat_Functions_WriteCalendarNote ( GSM_CalendarNote *CalendarNote)
294 {
295         BODY_COMPAT_FUNCTIONS_SM1(CalendarNote,CalendarNote,GOP_WriteCalendarNote);
296 }
297
298 static GSM_Error compat_Functions_DeleteCalendarNote ( GSM_CalendarNote *CalendarNote)
299 {
300         BODY_COMPAT_FUNCTIONS_SM1(CalendarNote,CalendarNote,GOP_DeleteCalendarNote);
301 }
302
303 static GSM_Error compat_Functions_NetMonitor ( unsigned char mode, char *Screen )
304 {
305         BODY_COMPAT_FUNCTIONS_SM2(NetMonitorMode,&mode,NetMonitorScreen,Screen,GOP_NetMonitor);
306 }
307
308 static GSM_Error compat_Functions_SendDTMF ( char *String )
309 {
310         BODY_COMPAT_FUNCTIONS_SM1(DTMF,String,GOP_SendDTMF);
311 }
312
313 static GSM_Error compat_Functions_GetBitmap ( GSM_Bitmap *Bitmap )
314 {
315         BODY_COMPAT_FUNCTIONS_SM1(Bitmap,Bitmap,GOP_GetBitmap);
316 }
317   
318 static GSM_Error compat_Functions_SetBitmap ( GSM_Bitmap *Bitmap )
319 {
320         BODY_COMPAT_FUNCTIONS_SM1(Bitmap,Bitmap,GOP_SetBitmap);
321 }
322
323 static GSM_Error compat_Functions_SetRingtone ( GSM_Ringtone *ringtone )
324 {
325         BODY_COMPAT_FUNCTIONS_SM1(Ringtone,ringtone,GOP_SetRingtone);
326 }
327
328 static GSM_Error compat_Functions_Reset ( unsigned char type )
329 {
330         BODY_COMPAT_FUNCTIONS_SM1(ResetType,&type,GOP_Reset);
331 }
332
333 static GSM_Error compat_Functions_GetProfile ( GSM_Profile *Profile )
334 {
335         BODY_COMPAT_FUNCTIONS_SM1(Profile,Profile,GOP_GetProfile);
336 }
337
338 static GSM_Error compat_Functions_SetProfile ( GSM_Profile *Profile )
339 {
340         BODY_COMPAT_FUNCTIONS_SM1(Profile,Profile,GOP_SetProfile);
341 }
342
343 /* return type "bool" is fortunately compatible with "GSM_Error"
344  */
345 static bool      compat_Functions_SendRLPFrame ( RLP_F96Frame *frame, bool out_dtx )
346 {
347         BODY_COMPAT_FUNCTIONS_SM2(RLPFrame,frame,RLPFrame_out_dtx,&out_dtx,GOP_SendRLPFrame);
348 }
349
350 static GSM_Error compat_Functions_CancelCall ( void )
351 {
352         BODY_COMPAT_FUNCTIONS_SM0(GOP_CancelCall);
353 }
354   
355 static GSM_Error compat_Functions_EnableDisplayOutput ( void )
356 {
357         BODY_COMPAT_FUNCTIONS_SM0(GOP_EnableDisplayOutput);
358 }
359   
360 static GSM_Error compat_Functions_DisableDisplayOutput ( void )
361 {
362         BODY_COMPAT_FUNCTIONS_SM0(GOP_DisableDisplayOutput);
363 }
364  
365 static GSM_Error compat_Functions_EnableCellBroadcast ( void )
366 {
367         BODY_COMPAT_FUNCTIONS_SM0(GOP_EnableCellBroadcast);
368 }
369
370 static GSM_Error compat_Functions_DisableCellBroadcast ( void )
371 {
372         BODY_COMPAT_FUNCTIONS_SM0(GOP_DisableCellBroadcast);
373 }
374
375 static GSM_Error compat_Functions_ReadCellBroadcast ( GSM_CBMessage *Message )
376 {
377         BODY_COMPAT_FUNCTIONS_SM1(CBMessage,Message,GOP_ReadCellBroadcast);
378 }
379   
380 static GSM_Error compat_Functions_SetKey (int c, int up)
381 {
382         BODY_COMPAT_FUNCTIONS_SM2(SetKeyKey,&c,SetKeyUp,&up,GOP_SetKey);
383 }
384   
385 static GSM_Error compat_Functions_HandleString (char *s)
386 {
387         BODY_COMPAT_FUNCTIONS_SM1(HandleString,s,GOP_HandleString);
388 }
389         
390 static GSM_Error compat_Functions_AnswerCall (char s)
391 {
392         BODY_COMPAT_FUNCTIONS_SM1(CallNo,&s,GOP_AnswerCall);
393 }
394
395 static GSM_Functions compat_Functions={
396         compat_Functions_Initialise,
397         compat_Functions_Terminate,
398         compat_Functions_GetMemoryLocation,
399         compat_Functions_WritePhonebookLocation,
400         compat_Functions_GetSpeedDial,
401         compat_Functions_SetSpeedDial,
402         compat_Functions_GetMemoryStatus,
403         compat_Functions_GetSMSStatus,
404         compat_Functions_GetSMSCenter,
405         compat_Functions_SetSMSCenter,
406         compat_Functions_GetSMSMessage,
407         compat_Functions_DeleteSMSMessage,
408         compat_Functions_SendSMSMessage,
409         compat_Functions_SaveSMSMessage,
410         compat_Functions_GetRFLevel,
411         compat_Functions_GetBatteryLevel,
412         compat_Functions_GetPowerSource,
413         compat_Functions_GetDisplayStatus,
414         compat_Functions_EnterSecurityCode,
415         compat_Functions_GetSecurityCodeStatus,
416         compat_Functions_GetIMEI,
417         compat_Functions_GetRevision,
418         compat_Functions_GetModel,
419         compat_Functions_GetManufacturer,
420         compat_Functions_GetDateTime,
421         compat_Functions_SetDateTime,
422         compat_Functions_GetAlarm,
423         compat_Functions_SetAlarm,
424         compat_Functions_DialVoice,
425         compat_Functions_DialData,
426         compat_Functions_GetIncomingCallNr,
427         compat_Functions_GetNetworkInfo,
428         compat_Functions_GetCalendarNote,
429         compat_Functions_WriteCalendarNote,
430         compat_Functions_DeleteCalendarNote,
431         compat_Functions_NetMonitor,
432         compat_Functions_SendDTMF,
433         compat_Functions_GetBitmap,
434         compat_Functions_SetBitmap,
435         compat_Functions_SetRingtone,
436         compat_Functions_Reset,
437         compat_Functions_GetProfile,
438         compat_Functions_SetProfile,
439         compat_Functions_SendRLPFrame,
440         compat_Functions_CancelCall,
441         compat_Functions_EnableDisplayOutput,
442         compat_Functions_DisableDisplayOutput,
443         compat_Functions_EnableCellBroadcast,
444         compat_Functions_DisableCellBroadcast,
445         compat_Functions_ReadCellBroadcast,
446         compat_Functions_SetKey,
447         compat_Functions_HandleString,
448         compat_Functions_AnswerCall,
449         };
450
451 GSM_Error compat_Phone_Functions(GSM_Operation op, GSM_Data *data, GSM_Statemachine *state)
452 {
453         switch (op) {
454         
455         case GOP_Init:
456                 fprintf(stderr,"FATAL: compat_Phone_Functions(GOP_Init) called for old style phone implementation!\n");
457                 return(GE_NOTIMPLEMENTED);
458
459         case GOP_Terminate:
460                 GSM->Terminate();
461                 return(GE_NONE);
462
463         case GOP_ReadPhonebook:
464                 return(GSM->GetMemoryLocation(data->PhonebookEntry/*entry*/));
465
466         case GOP_WritePhonebook:
467                 return(GSM->WritePhonebookLocation(data->PhonebookEntry/*entry*/));
468
469         case GOP_GetSpeedDial:
470                 return(GSM->GetSpeedDial(data->SpeedDial/*entry*/));
471
472         case GOP_SetSpeedDial:
473                 return(GSM->SetSpeedDial(data->SpeedDial/*entry*/));
474
475         case GOP_GetMemoryStatus:
476                 return(GSM->GetMemoryStatus(data->MemoryStatus/*Status*/));
477
478         case GOP_GetSMSStatus:
479                 return(GSM->GetSMSStatus(data->SMSStatus/*Status*/));
480
481         case GOP_GetSMSCenter:
482                 return(GSM->GetSMSCenter(data->MessageCenter/*MessageCenter*/));
483
484         case GOP_SetSMSCenter:
485                 return(GSM->SetSMSCenter(data->MessageCenter/*MessageCenter*/));
486
487         case GOP_GetSMS:
488                 return(GSM->GetSMSMessage(data->SMSMessage/*Message*/));
489
490         case GOP_DeleteSMS:
491                 return(GSM->DeleteSMSMessage(data->SMSMessage/*Message*/));
492
493         case GOP_SendSMS:
494                 return(GSM->SendSMSMessage(data->SMSMessage/*Message*/));
495
496         case GOP_SaveSMS:
497                 return(GSM->SaveSMSMessage(data->SMSMessage/*Message*/));
498
499         case GOP_GetRFLevel:
500                 return(GSM->GetRFLevel(data->RFUnits/*units*/,data->RFLevel/*level*/));
501
502         case GOP_GetBatteryLevel:
503                 return(GSM->GetBatteryLevel(data->BatteryUnits/*units*/,data->BatteryLevel/*level*/));
504
505         case GOP_GetPowersource:
506                 return(GSM->GetPowerSource(data->PowerSource/*source*/));
507
508         case GOP_GetDisplayStatus:
509                 return(GSM->GetDisplayStatus(data->DisplayStatus/*Status*/));
510
511         case GOP_EnterSecurityCode:
512                 return(GSM->EnterSecurityCode(*data->SecurityCode/*Code*/));
513
514         case GOP_GetSecurityCodeStatus: {
515 int status_local=*data->SecurityCodeStatus;
516 GSM_Error err;
517
518                 err=GSM->GetSecurityCodeStatus(&status_local);
519                 *data->SecurityCodeStatus=status_local;
520                 return(err);
521                 }
522
523         case GOP_GetImei:
524                 return(GSM->GetIMEI(data->Imei/*imei*/));
525
526         case GOP_GetRevision:
527                 return(GSM->GetRevision(data->Revision/*revision*/));
528
529         case GOP_GetModel:
530                 return(GSM->GetModel(data->Model/*model*/));
531
532         case GOP_GetManufacturer:
533                 return(GSM->GetManufacturer(data->Manufacturer/*manufacturer*/));
534
535         case GOP_GetDateTime:
536                 return(GSM->GetDateTime(data->DateTime/*date_time*/));
537
538         case GOP_SetDateTime:
539                 return(GSM->SetDateTime(data->DateTime/*date_time*/));
540
541         case GOP_GetAlarm:
542                 return(GSM->GetAlarm((!data->AlarmNumber ? 0 : *data->AlarmNumber)/*alarm_number*/,
543                                 data->AlarmDateTime/*date_time*/));
544
545         case GOP_SetAlarm:
546                 return(GSM->SetAlarm((!data->AlarmNumber ? 0 : *data->AlarmNumber)/*alarm_number*/,
547                                 data->AlarmDateTime/*date_time*/));
548
549         case GOP_DialVoice:
550                 return(GSM->DialVoice(data->VoiceNumber/*Number*/));
551
552         case GOP_DialData:
553                 return(GSM->DialData(data->DataNumber/*Number*/,
554                                 (!data->DataType ? -1 : *data->DataType)/*type*/,
555                                 data->DataCallPassUp/*callpassup*/));
556
557         case GOP_GetIncomingCallNr:
558                 return(GSM->GetIncomingCallNr(data->IncomingCallNr/*Number*/));
559
560         case GOP_GetNetworkInfo:
561                 return(GSM->GetNetworkInfo(data->NetworkInfo/*NetworkInfo*/));
562
563         case GOP_GetCalendarNote:
564                 return(GSM->GetCalendarNote(data->CalendarNote/*CalendarNote*/));
565
566         case GOP_WriteCalendarNote:
567                 return(GSM->WriteCalendarNote(data->CalendarNote/*CalendarNote*/));
568
569         case GOP_DeleteCalendarNote:
570                 return(GSM->DeleteCalendarNote(data->CalendarNote/*CalendarNote*/));
571
572         case GOP_NetMonitor:
573                 return(GSM->NetMonitor((!data->NetMonitorMode ? 0 : *data->NetMonitorMode)/*mode*/,
574                                 data->NetMonitorScreen/*Screen*/));
575
576         case GOP_SendDTMF:
577                 return(GSM->SendDTMF(data->DTMF/*String*/));
578
579         case GOP_GetBitmap:
580                 return(GSM->GetBitmap(data->Bitmap/*Bitmap*/));
581
582         case GOP_SetBitmap:
583                 return(GSM->SetBitmap(data->Bitmap/*Bitmap*/));
584
585         case GOP_SetRingtone:
586                 return(GSM->SetRingtone(data->Ringtone/*ringtone*/));
587
588         case GOP_Reset:
589                 return(GSM->Reset((!data->ResetType ? 0x03 : *data->ResetType)/*type*/));
590
591         case GOP_GetProfile:
592                 return(GSM->GetProfile(data->Profile/*Profile*/));
593
594         case GOP_SetProfile:
595                 return(GSM->SetProfile(data->Profile/*Profile*/));
596
597         /* return type "bool" is fortunately compatible with "GSM_Error"
598          */
599         case GOP_SendRLPFrame:
600                 return(GSM->SendRLPFrame(data->RLPFrame/*frame*/,
601                                 (!data->RLPFrame_out_dtx ? 0 : *data->RLPFrame_out_dtx)/*out_dtx*/));
602
603         case GOP_CancelCall:
604                 return(GSM->CancelCall());
605
606         case GOP_EnableDisplayOutput:
607                 return(GSM->EnableDisplayOutput());
608
609         case GOP_DisableDisplayOutput:
610                 return(GSM->DisableDisplayOutput());
611
612         case GOP_EnableCellBroadcast:
613                 return(GSM->EnableCellBroadcast());
614
615         case GOP_DisableCellBroadcast:
616                 return(GSM->DisableCellBroadcast());
617
618         case GOP_ReadCellBroadcast:
619                 return(GSM->ReadCellBroadcast(data->CBMessage/*Message*/));
620
621         case GOP_SetKey:
622                 return(GSM->SetKey(*data->SetKeyKey/*c*/,
623                                 (!data->SetKeyUp ? 0 : *data->SetKeyUp)/*up*/));
624
625         case GOP_HandleString:
626                 return(GSM->HandleString(data->HandleString/*s*/));
627
628         case GOP_AnswerCall:
629                 return(GSM->AnswerCall((!data->CallNo ? 0 : *data->CallNo)/*s*/));
630
631
632         default:
633                 return(GE_NOTIMPLEMENTED);
634         }
635 }
636
637 /* Initialise interface to the phone. Model number should be a string such as
638    3810, 5110, 6110 etc. Device is the serial port to use e.g. /dev/ttyS0, the
639    user must have write permission to the device. */
640
641 static GSM_Error register_phone(GSM_Phone *phone, char *model, char *setupmodel, GSM_Statemachine *sm)
642 {
643         GSM_Data data;
644         GSM_Data *p_data;
645         if (setupmodel) {
646                 GSM_DataClear(&data);
647                 data.Model = setupmodel;
648                 p_data = &data;
649         } else {
650                 p_data = NULL;
651         }
652         sm->Phone=*phone;
653         if (strstr(phone->Info.Models, model) != NULL)
654                 return phone->Functions(GOP_Init, p_data, sm);
655         return GE_UNKNOWNMODEL;
656 }
657
658 #define MODULE(x) { \
659         extern GSM_Functions x##_Functions; \
660         extern GSM_Information x##_Information; \
661         extern bool x##_LinkOK; \
662         if (strstr(x##_Information.Models, model) != NULL) { \
663                 GSM = & x##_Functions; \
664                 GSM_Info = & x##_Information; \
665                 GSM_LinkOK = & x##_LinkOK; \
666                 return (GSM->Initialise(device, initlength, connection, rlp_callback)); \
667         } \
668 }
669
670 #define REGISTER_PHONE(x, y) { \
671         extern GSM_Phone phone_##x; \
672         if ((ret = register_phone(&phone_##x, model, y, sm)) != GE_UNKNOWNMODEL) \
673                 return ret; \
674  } 
675  
676 GSM_Error GSM_Initialise(char *model, char *device, char *initlength, GSM_ConnectionType connection, void (*rlp_callback)(RLP_F96Frame *frame), GSM_Statemachine *sm)
677 {
678         GSM_Error ret;
679         compat_Functions_Statemachine=sm;
680 #ifndef WIN32  /* MB21 not supported in win32 */
681         if (strstr("2110", model)) {
682                 extern GSM_Phone phone_nokia_2110;
683                 memcpy(&(sm->Phone), &phone_nokia_2110, sizeof(GSM_Phone));
684                 sm->Phone.Functions(GOP_Init, NULL, sm);
685         }
686         MODULE(N2110);
687  
688         GSM_LinkOK = &LinkAlwaysOK;
689         sm->Link.ConnectionType=connection;
690         sm->Link.InitLength=atoi(initlength);
691         strcpy(sm->Link.PortDevice,device);
692         GSM=&compat_Functions;
693  
694         REGISTER_PHONE(nokia_7110, NULL);
695         REGISTER_PHONE(at_hw, model);   /* FIXME: why 7110 does not to set sm->Model? */
696         REGISTER_PHONE(cimd, model);    /* FIXME: why 7110 does not to set sm->Model? */
697 #if 0
698         REGISTER_PHONE(nokia_3110, NULL);
699 #endif
700
701 #endif /* WIN32 */ 
702         return (GE_UNKNOWNMODEL);
703 }