Imported gammu 0.90.7
[gammu.git] / common / gsmstate.c
blobe30267e2e8b9930b0cfa0c1696bdad88c06cf4d9
2 #include <stdarg.h>
3 #include <string.h>
4 #include <errno.h>
6 #include "gsmcomon.h"
7 #include "gsmstate.h"
8 #include "misc/cfg.h"
9 #include "misc/coding/coding.h"
10 #include "device/devfunc.h"
12 static void GSM_RegisterConnection(GSM_StateMachine *s, unsigned int connection,
13 GSM_Device_Functions *device, GSM_Protocol_Functions *protocol)
15 if ((unsigned int)s->ConnectionType == connection) {
16 s->Device.Functions = device;
17 s->Protocol.Functions = protocol;
21 static GSM_Error GSM_RegisterAllConnections(GSM_StateMachine *s, char *connection)
23 /* We check here is used connection string type is correct for ANY
24 * OS. If not, we return with error, that string is incorrect at all
26 s->ConnectionType = 0;
27 if (mystrncasecmp("mbus" ,connection,0)) s->ConnectionType = GCT_MBUS2;
28 if (mystrncasecmp("fbus" ,connection,0)) s->ConnectionType = GCT_FBUS2;
29 if (mystrncasecmp("fbusdlr3" ,connection,0)) s->ConnectionType = GCT_FBUS2DLR3;
30 if (mystrncasecmp("fbusdku5" ,connection,0)) s->ConnectionType = GCT_FBUS2DKU5;
31 if (mystrncasecmp("fbusblue" ,connection,0)) s->ConnectionType = GCT_FBUS2BLUE;
32 if (mystrncasecmp("fbusirda" ,connection,0)) s->ConnectionType = GCT_FBUS2IRDA;
33 if (mystrncasecmp("phonetblue" ,connection,0)) s->ConnectionType = GCT_PHONETBLUE;
34 if (mystrncasecmp("mrouterblue" ,connection,0)) s->ConnectionType = GCT_MROUTERBLUE;
35 if (mystrncasecmp("irdaphonet" ,connection,0)) s->ConnectionType = GCT_IRDAPHONET;
36 if (mystrncasecmp("irdaat" ,connection,0)) s->ConnectionType = GCT_IRDAAT;
37 if (mystrncasecmp("irdaobex" ,connection,0)) s->ConnectionType = GCT_IRDAOBEX;
38 if (mystrncasecmp("blueobex" ,connection,0)) s->ConnectionType = GCT_BLUEOBEX;
39 if (mystrncasecmp("bluefbus" ,connection,0)) s->ConnectionType = GCT_BLUEFBUS2;
40 if (mystrncasecmp("bluephonet" ,connection,0)) s->ConnectionType = GCT_BLUEPHONET;
41 if (mystrncasecmp("blueat" ,connection,0)) s->ConnectionType = GCT_BLUEAT;
43 /* These are for compatibility only */
44 if (mystrncasecmp("atblue" ,connection,0)) s->ConnectionType = GCT_BLUEAT;
45 if (mystrncasecmp("dlr3blue" ,connection,0)) s->ConnectionType = GCT_BLUEFBUS2;
46 if (mystrncasecmp("irda" ,connection,0)) s->ConnectionType = GCT_IRDAPHONET;
47 if (mystrncasecmp("dlr3" ,connection,0)) s->ConnectionType = GCT_FBUS2DLR3;
48 if (mystrncasecmp("infrared" ,connection,0)) s->ConnectionType = GCT_FBUS2IRDA;
50 if (mystrncasecmp("at" ,connection,2)) {
51 /* Use some resonable default, when no speed defined */
52 if (strlen(connection) == 2) {
53 s->Speed = 19200;
54 } else {
55 s->Speed = FindSerialSpeed(connection+2);
57 if (s->Speed != 0) s->ConnectionType = GCT_AT;
59 if (s->ConnectionType==0) return GE_UNKNOWNCONNECTIONTYPESTRING;
61 /* We check now if user gave connection type compiled & available
62 * for used OS (if not, we return, that source not available)
64 s->Device.Functions = NULL;
65 s->Protocol.Functions = NULL;
66 #ifdef GSM_ENABLE_MBUS2
67 GSM_RegisterConnection(s, GCT_MBUS2, &SerialDevice, &MBUS2Protocol);
68 #endif
69 #ifdef GSM_ENABLE_FBUS2
70 GSM_RegisterConnection(s, GCT_FBUS2, &SerialDevice, &FBUS2Protocol);
71 #endif
72 #ifdef GSM_ENABLE_FBUS2DLR3
73 GSM_RegisterConnection(s, GCT_FBUS2DLR3, &SerialDevice, &FBUS2Protocol);
74 #endif
75 #ifdef GSM_ENABLE_FBUS2DKU5
76 GSM_RegisterConnection(s, GCT_FBUS2DKU5, &SerialDevice, &FBUS2Protocol);
77 #endif
78 #ifdef GSM_ENABLE_FBUS2BLUE
79 GSM_RegisterConnection(s, GCT_FBUS2BLUE, &SerialDevice, &FBUS2Protocol);
80 #endif
81 #ifdef GSM_ENABLE_FBUS2IRDA
82 GSM_RegisterConnection(s, GCT_FBUS2IRDA, &SerialDevice, &FBUS2Protocol);
83 #endif
84 #ifdef GSM_ENABLE_PHONETBLUE
85 GSM_RegisterConnection(s, GCT_PHONETBLUE,&SerialDevice, &PHONETProtocol);
86 #endif
87 #ifdef GSM_ENABLE_MROUTERBLUE
88 GSM_RegisterConnection(s, GCT_MROUTERBLUE,&SerialDevice, &MROUTERProtocol);
89 #endif
90 #ifdef GSM_ENABLE_IRDAPHONET
91 GSM_RegisterConnection(s, GCT_IRDAPHONET,&IrdaDevice, &PHONETProtocol);
92 #endif
93 #ifdef GSM_ENABLE_BLUEFBUS2
94 GSM_RegisterConnection(s, GCT_BLUEFBUS2, &BlueToothDevice,&FBUS2Protocol);
95 #endif
96 #ifdef GSM_ENABLE_BLUEPHONET
97 GSM_RegisterConnection(s, GCT_BLUEPHONET,&BlueToothDevice,&PHONETProtocol);
98 #endif
99 #ifdef GSM_ENABLE_BLUEAT
100 GSM_RegisterConnection(s, GCT_BLUEAT, &BlueToothDevice,&ATProtocol);
101 #endif
102 #ifdef GSM_ENABLE_AT
103 GSM_RegisterConnection(s, GCT_AT, &SerialDevice, &ATProtocol);
104 #endif
105 #ifdef GSM_ENABLE_IRDAAT
106 GSM_RegisterConnection(s, GCT_IRDAAT, &IrdaDevice, &ATProtocol);
107 #endif
108 #ifdef GSM_ENABLE_IRDAOBEX
109 GSM_RegisterConnection(s, GCT_IRDAOBEX, &IrdaDevice, &OBEXProtocol);
110 #endif
111 #ifdef GSM_ENABLE_BLUEOBEX
112 GSM_RegisterConnection(s, GCT_BLUEOBEX, &BlueToothDevice,&OBEXProtocol);
113 #endif
114 if (s->Device.Functions==NULL || s->Protocol.Functions==NULL)
115 return GE_SOURCENOTAVAILABLE;
116 return GE_NONE;
119 static void GSM_RegisterModule(GSM_StateMachine *s,GSM_Phone_Functions *phone)
121 /* Auto model */
122 if (s->CurrentConfig->Model[0] == 0) {
123 if (strstr(phone->models,GetModelData(NULL,s->Phone.Data.Model,NULL)->model) != NULL) {
124 smprintf(s,"[Module - \"%s\"]\n",phone->models);
125 s->Phone.Functions = phone;
127 } else {
128 if (strstr(phone->models,s->CurrentConfig->Model) != NULL) {
129 smprintf(s,"[Module - \"%s\"]\n",phone->models);
130 s->Phone.Functions = phone;
135 GSM_Error GSM_RegisterAllPhoneModules(GSM_StateMachine *s)
137 /* Auto model */
138 if (s->CurrentConfig->Model[0] == 0) {
139 #ifdef GSM_ENABLE_ATGEN
140 /* With ATgen and auto model we can work with unknown models too */
141 if (s->ConnectionType==GCT_AT || s->ConnectionType==GCT_BLUEAT || s->ConnectionType==GCT_IRDAAT) {
142 smprintf(s,"[Module - \"%s\"]\n",ATGENPhone.models);
143 s->Phone.Functions = &ATGENPhone;
144 return GE_NONE;
146 #endif
147 if (GetModelData(NULL,s->Phone.Data.Model,NULL)->model[0] == 0) return GE_UNKNOWNMODELSTRING;
149 s->Phone.Functions=NULL;
150 #ifdef GSM_ENABLE_ATGEN
151 /* AT module can have the same models ID to "normal" Nokia modules */
152 if (s->ConnectionType==GCT_AT || s->ConnectionType==GCT_BLUEAT || s->ConnectionType==GCT_IRDAAT) {
153 GSM_RegisterModule(s,&ATGENPhone);
154 if (s->Phone.Functions!=NULL) return GE_NONE;
156 #endif
157 #ifdef GSM_ENABLE_OBEXGEN
158 GSM_RegisterModule(s,&OBEXGENPhone);
159 #endif
160 #ifdef GSM_ENABLE_MROUTERGEN
161 GSM_RegisterModule(s,&MROUTERGENPhone);
162 #endif
163 #ifdef GSM_ENABLE_NOKIA3650
164 GSM_RegisterModule(s,&N3650Phone);
165 #endif
166 #ifdef GSM_ENABLE_NOKIA6110
167 GSM_RegisterModule(s,&N6110Phone);
168 #endif
169 #ifdef GSM_ENABLE_NOKIA6510
170 GSM_RegisterModule(s,&N6510Phone);
171 #endif
172 #ifdef GSM_ENABLE_NOKIA7110
173 GSM_RegisterModule(s,&N7110Phone);
174 #endif
175 #ifdef GSM_ENABLE_NOKIA9210
176 GSM_RegisterModule(s,&N9210Phone);
177 #endif
178 #ifdef GSM_ENABLE_ALCATEL
179 GSM_RegisterModule(s,&ALCATELPhone);
180 #endif
181 if (s->Phone.Functions==NULL) return GE_UNKNOWNMODELSTRING;
182 return GE_NONE;
185 GSM_Error GSM_InitConnection(GSM_StateMachine *s, int ReplyNum)
187 GSM_Error error;
188 GSM_DateTime time;
189 int i;
191 for (i=0;i<s->ConfigNum;i++) {
192 s->CurrentConfig = &s->Config[i];
194 s->Speed = 0;
195 s->ReplyNum = ReplyNum;
196 s->Phone.Data.ModelInfo = GetModelData("unknown",NULL,NULL);
197 s->Phone.Data.Manufacturer[0] = 0;
198 s->Phone.Data.Model[0] = 0;
199 s->Phone.Data.Version[0] = 0;
200 s->Phone.Data.VerDate[0] = 0;
201 s->Phone.Data.VerNum = 0;
202 s->Phone.Data.StartInfoCounter = 0;
203 s->Phone.Data.SentMsg = NULL;
205 s->Phone.Data.HardwareCache[0] = 0;
206 s->Phone.Data.ProductCodeCache[0] = 0;
207 s->Phone.Data.EnableIncomingCall = false;
208 s->Phone.Data.EnableIncomingSMS = false;
209 s->Phone.Data.EnableIncomingCB = false;
210 s->Phone.Data.EnableIncomingUSSD = false;
211 s->User.UserReplyFunctions = NULL;
212 s->User.IncomingCall = NULL;
213 s->User.IncomingSMS = NULL;
214 s->User.IncomingCB = NULL;
215 s->User.IncomingUSSD = NULL;
216 s->User.SendSMSStatus = NULL;
217 s->LockFile = NULL;
218 s->opened = false;
219 s->Phone.Functions = NULL;
221 s->di = di;
222 s->di.use_global = s->CurrentConfig->UseGlobalDebugFile;
223 GSM_SetDebugLevel(s->CurrentConfig->DebugLevel, &s->di);
224 error=GSM_SetDebugFile(s->CurrentConfig->DebugFile, &s->di);
225 if (error != GE_NONE) return error;
227 if (s->di.dl == DL_TEXTALL || s->di.dl == DL_TEXT || s->di.dl == DL_TEXTERROR ||
228 s->di.dl == DL_TEXTALLDATE || s->di.dl == DL_TEXTDATE || s->di.dl == DL_TEXTERRORDATE)
230 smprintf(s,"[Gammu - version %s built %s %s]\n",VERSION,__TIME__,__DATE__);
231 smprintf(s,"[Connection - \"%s\"]\n",s->CurrentConfig->Connection);
232 smprintf(s,"[Model type - \"%s\"]\n",s->CurrentConfig->Model);
233 smprintf(s,"[Device - \"%s\"]\n",s->CurrentConfig->Device);
234 #ifdef WIN32
235 # ifdef _MSC_VER
236 smprintf(s,"[OS/compiler - Windows %i.%i.%i, MS VC version %i]\n",_winmajor,_winminor,_osver,_MSC_VER);
237 # else
238 smprintf(s,"[OS/compiler - win32]\n");
239 # endif
240 #elif defined(DJGPP)
241 smprintf(s,"[OS/compiler - djgpp]\n");
242 #else
243 smprintf(s,"[OS/compiler - "
244 // Detect some Unix-like OSes:
245 # if defined(linux) || defined(__linux) || defined(__linux__)
246 "Linux"
247 # elif defined(__FreeBSD__)
248 "FreeBSD"
249 # elif defined(__NetBSD__)
250 "NetBSD"
251 # elif defined(__OpenBSD__)
252 "OpenBSD"
253 # elif defined(__GNU__)
254 "GNU/Hurd"
255 # elif defined(sun) || defined(__sun) || defined(__sun__)
256 # if defined(__SVR4)
257 "Sun Solaris"
258 # else
259 "SunOS"
260 # endif
261 # elif defined(hpux) || defined(__hpux) || defined(__hpux__)
262 "HP-UX"
263 # elif defined(ultrix) || defined(__ultrix) || defined(__ultrix__)
264 "DEC Ultrix"
265 # elif defined(sgi) || defined(__sgi)
266 "SGI Irix"
267 # elif defined(__osf__)
268 "OSF Unix"
269 # elif defined(bsdi) || defined(__bsdi__)
270 "BSDI Unix"
271 # elif defined(_AIX)
272 "AIX Unix"
273 # elif defined(_UNIXWARE)
274 "SCO Unixware"
275 # elif defined(DGUX)
276 "DG Unix"
277 # elif defined(__QNX__)
278 "QNX"
279 # else
280 "Unknown"
281 #endif
282 // Show info for some compilers:
283 # if defined(__GNUC__)
284 ", gcc %i.%i]\n", __GNUC__, __GNUC_MINOR__
285 # elif defined(__SUNPRO_CC)
286 ", Sun C++ %x]\n", __SUNPRO_CC
287 # else
288 "]\n"
289 # endif
291 #endif
293 if (s->di.dl==DL_BINARY) {
294 smprintf(s,"%c",((unsigned char)strlen(VERSION)));
295 smprintf(s,"%s",VERSION);
298 error=GSM_RegisterAllConnections(s, s->CurrentConfig->Connection);
299 if (error!=GE_NONE) return error;
301 /* Model auto */
302 if (s->CurrentConfig->Model[0]==0) {
303 if (mystrncasecmp(s->CurrentConfig->LockDevice,"yes",0)) {
304 error = lock_device(s->CurrentConfig->Device, &(s->LockFile));
305 if (error != GE_NONE) return error;
308 /* Irda devices can set now model to some specific and
309 * we don't have to make auto detection later */
310 error=s->Device.Functions->OpenDevice(s);
311 if (i != s->ConfigNum - 1) {
312 if (error == GE_DEVICEOPENERROR) continue;
313 if (error == GE_DEVICELOCKED) continue;
314 if (error == GE_DEVICENOTEXIST) continue;
315 if (error == GE_DEVICEBUSY) continue;
316 if (error == GE_DEVICENOPERMISSION) continue;
317 if (error == GE_DEVICENODRIVER) continue;
318 if (error == GE_DEVICENOTWORK) continue;
320 if (error!=GE_NONE) return error;
322 s->opened = true;
324 error=s->Protocol.Functions->Initialise(s);
325 if (error!=GE_NONE) return error;
327 /* If still auto model, try to get model by asking phone for it */
328 if (s->Phone.Data.Model[0]==0) {
329 smprintf(s,"[Module - \"auto\"]\n");
330 switch (s->ConnectionType) {
331 #ifdef GSM_ENABLE_ATGEN
332 case GCT_AT:
333 case GCT_BLUEAT:
334 case GCT_IRDAAT:
335 s->Phone.Functions = &ATGENPhone;
336 break;
337 #endif
338 #ifdef GSM_ENABLE_OBEXGEN
339 case GCT_IRDAOBEX:
340 case GCT_BLUEOBEX:
341 s->Phone.Functions = &OBEXGENPhone;
342 break;
343 #endif
344 #ifdef GSM_ENABLE_MROUTERGEN
345 case GCT_MROUTERBLUE:
346 s->Phone.Functions = &MROUTERGENPhone;
347 break;
348 #endif
349 #if defined(GSM_ENABLE_NOKIA_DCT3) || defined(GSM_ENABLE_NOKIA_DCT4)
350 case GCT_MBUS2:
351 case GCT_FBUS2:
352 case GCT_FBUS2DLR3:
353 case GCT_FBUS2DKU5:
354 case GCT_FBUS2BLUE:
355 case GCT_FBUS2IRDA:
356 case GCT_PHONETBLUE:
357 case GCT_IRDAPHONET:
358 case GCT_BLUEFBUS2:
359 case GCT_BLUEPHONET:
360 s->Phone.Functions = &NAUTOPhone;
361 break;
362 #endif
363 default:
364 s->Phone.Functions = NULL;
366 if (s->Phone.Functions == NULL) return GE_UNKNOWN;
368 /* Please note, that AT module need to send first
369 * command for enabling echo
371 error=s->Phone.Functions->Initialise(s);
372 if (error == GE_TIMEOUT && i != s->ConfigNum - 1) continue;
373 if (error!=GE_NONE) return error;
375 error=s->Phone.Functions->GetModel(s);
376 if (error == GE_TIMEOUT && i != s->ConfigNum - 1) continue;
377 if (error!=GE_NONE) return error;
381 /* Switching to "correct" module */
382 error=GSM_RegisterAllPhoneModules(s);
383 if (error!=GE_NONE) return error;
385 /* We didn't open device earlier ? Make it now */
386 if (!s->opened) {
387 if (mystrncasecmp(s->CurrentConfig->LockDevice,"yes",0)) {
388 error = lock_device(s->CurrentConfig->Device, &(s->LockFile));
389 if (error != GE_NONE) return error;
392 error=s->Device.Functions->OpenDevice(s);
393 if (i != s->ConfigNum - 1) {
394 if (error == GE_DEVICEOPENERROR) continue;
395 if (error == GE_DEVICELOCKED) continue;
396 if (error == GE_DEVICENOTEXIST) continue;
397 if (error == GE_DEVICEBUSY) continue;
398 if (error == GE_DEVICENOPERMISSION) continue;
399 if (error == GE_DEVICENODRIVER) continue;
400 if (error == GE_DEVICENOTWORK) continue;
402 if (error!=GE_NONE) return error;
404 s->opened = true;
406 error=s->Protocol.Functions->Initialise(s);
407 if (error!=GE_NONE) return error;
410 error=s->Phone.Functions->Initialise(s);
411 if (error == GE_TIMEOUT && i != s->ConfigNum - 1) continue;
412 if (error!=GE_NONE) return error;
414 if (mystrncasecmp(s->CurrentConfig->StartInfo,"yes",0)) {
415 s->Phone.Functions->ShowStartInfo(s,true);
416 s->Phone.Data.StartInfoCounter = 30;
419 if (mystrncasecmp(s->CurrentConfig->SyncTime,"yes",0)) {
420 GSM_GetCurrentDateTime (&time);
421 s->Phone.Functions->SetDateTime(s,&time);
424 /* For debug it's good to have firmware and real model version and manufacturer */
425 error=s->Phone.Functions->GetManufacturer(s);
426 if (error == GE_TIMEOUT && i != s->ConfigNum - 1) continue;
427 if (error!=GE_NONE) return error;
428 error=s->Phone.Functions->GetModel(s);
429 if (error!=GE_NONE) return error;
430 error=s->Phone.Functions->GetFirmware(s);
431 if (error!=GE_NONE) return error;
432 return GE_NONE;
434 return GE_UNKNOWN;
437 int GSM_ReadDevice (GSM_StateMachine *s, bool wait)
439 unsigned char buff[255];
440 int res = 0, count;
442 unsigned int i;
443 GSM_DateTime Date;
445 GSM_GetCurrentDateTime (&Date);
446 i=Date.Second;
447 while (i==Date.Second) {
448 res = s->Device.Functions->ReadDevice(s, buff, 255);
449 if (!wait) break;
450 if (res > 0) break;
451 my_sleep(5);
452 GSM_GetCurrentDateTime(&Date);
455 for (count = 0; count < res; count++)
456 s->Protocol.Functions->StateMachine(s,buff[count]);
458 return res;
461 GSM_Error GSM_TerminateConnection(GSM_StateMachine *s)
463 GSM_Error error;
465 if (!s->opened) return GE_UNKNOWN;
467 smprintf(s,"[Closing]\n");
469 if (mystrncasecmp(s->CurrentConfig->StartInfo,"yes",0)) {
470 if (s->Phone.Data.StartInfoCounter > 0) s->Phone.Functions->ShowStartInfo(s,false);
473 if (s->Phone.Functions != NULL) {
474 error=s->Phone.Functions->Terminate(s);
475 if (error!=GE_NONE) return error;
478 error=s->Protocol.Functions->Terminate(s);
479 if (error!=GE_NONE) return error;
481 error = s->Device.Functions->CloseDevice(s);
482 if (error!=GE_NONE) return error;
484 s->Phone.Data.ModelInfo = NULL;
485 s->Phone.Data.Manufacturer[0] = 0;
486 s->Phone.Data.Model[0] = 0;
487 s->Phone.Data.Version[0] = 0;
488 s->Phone.Data.VerDate[0] = 0;
489 s->Phone.Data.VerNum = 0;
491 if (s->LockFile!=NULL) unlock_device(&(s->LockFile));
493 if (!s->di.use_global && s->di.dl!=0 && s->di.df!=stdout) fclose(s->di.df);
495 s->opened = false;
497 return GE_NONE;
500 GSM_Error GSM_WaitForOnce(GSM_StateMachine *s, unsigned char *buffer,
501 int length, unsigned char type, int time)
503 GSM_Phone_Data *Phone = &s->Phone.Data;
504 GSM_Protocol_Message sentmsg;
505 int i;
507 i=0;
508 do {
509 if (length != 0) {
510 sentmsg.Length = length;
511 sentmsg.Type = type;
512 sentmsg.Buffer = (unsigned char *)malloc(length);
513 memcpy(sentmsg.Buffer,buffer,length);
514 Phone->SentMsg = &sentmsg;
517 /* Some data received. Reset timer */
518 if (GSM_ReadDevice(s,true)!=0) i=0;
520 if (length != 0) {
521 free (sentmsg.Buffer);
522 Phone->SentMsg = NULL;
525 /* Request completed */
526 if (Phone->RequestID==ID_None) return Phone->DispatchError;
528 i++;
529 } while (i<time);
531 return GE_TIMEOUT;
534 GSM_Error GSM_WaitFor (GSM_StateMachine *s, unsigned char *buffer,
535 int length, unsigned char type, int time,
536 GSM_Phone_RequestID request)
538 GSM_Phone_Data *Phone = &s->Phone.Data;
539 GSM_Error error;
540 int reply;
542 if (mystrncasecmp(s->CurrentConfig->StartInfo,"yes",0)) {
543 if (Phone->StartInfoCounter > 0) {
544 Phone->StartInfoCounter--;
545 if (Phone->StartInfoCounter == 0) s->Phone.Functions->ShowStartInfo(s,false);
549 Phone->RequestID = request;
550 Phone->DispatchError = GE_TIMEOUT;
552 for (reply=0;reply<s->ReplyNum;reply++) {
553 if (reply!=0) {
554 if (s->di.dl==DL_TEXT || s->di.dl==DL_TEXTALL || s->di.dl == DL_TEXTERROR ||
555 s->di.dl==DL_TEXTDATE || s->di.dl==DL_TEXTALLDATE || s->di.dl == DL_TEXTERRORDATE)
557 smprintf(s, "[Retrying %i type 0x%02x]\n", reply, type);
560 error = s->Protocol.Functions->WriteMessage(s, buffer, length, type);
561 if (error!=GE_NONE) return error;
563 error = GSM_WaitForOnce(s, buffer, length, type, time);
564 if (error != GE_TIMEOUT) return error;
567 return Phone->DispatchError;
570 static GSM_Error CheckReplyFunctions(GSM_StateMachine *s, GSM_Reply_Function *Reply, int *reply)
572 GSM_Phone_Data *Data = &s->Phone.Data;
573 GSM_Protocol_Message *msg = s->Phone.Data.RequestMsg;
574 bool execute;
575 bool available = false;
576 int i = 0;
578 while (Reply[i].requestID!=ID_None) {
579 execute=false;
580 /* Binary frames like in Nokia */
581 if (strlen(Reply[i].msgtype) < 2) {
582 if (Reply[i].msgtype[0]==msg->Type) {
583 if (Reply[i].subtypechar!=0) {
584 if (Reply[i].subtypechar<=msg->Length) {
585 if (msg->Buffer[Reply[i].subtypechar]==Reply[i].subtype)
586 execute=true;
588 } else execute=true;
590 } else {
591 if (strncmp(Reply[i].msgtype,msg->Buffer,strlen(Reply[i].msgtype))==0) {
592 execute=true;
596 if (execute) {
597 *reply=i;
598 if ((unsigned int)Reply[i].requestID == ID_IncomingFrame ||
599 (unsigned int)Reply[i].requestID == Data->RequestID ||
600 Data->RequestID == ID_EachFrame) {
601 return GE_NONE;
603 available=true;
605 i++;
608 if (available) {
609 return GE_FRAMENOTREQUESTED;
610 } else {
611 return GE_UNKNOWNFRAME;
615 GSM_Error GSM_DispatchMessage(GSM_StateMachine *s)
617 GSM_Error error = GE_UNKNOWNFRAME;
618 GSM_Protocol_Message *msg = s->Phone.Data.RequestMsg;
619 GSM_Phone_Data *Phone = &s->Phone.Data;
620 bool disp = false;
621 GSM_Reply_Function *Reply;
622 int reply, i;
624 if (s->di.dl==DL_TEXT || s->di.dl==DL_TEXTALL ||
625 s->di.dl==DL_TEXTDATE || s->di.dl==DL_TEXTALLDATE) {
626 smprintf(s, "Received frame ");
627 smprintf(s, "0x%02x / 0x%04x", msg->Type, msg->Length);
628 DumpMessage(s->di.df, msg->Buffer, msg->Length);
629 if (msg->Length == 0) smprintf(s, "\n");
630 fflush(s->di.df);
632 if (s->di.dl==DL_BINARY) {
633 smprintf(s,"%c",0x02); /* Receiving */
634 smprintf(s,"%c",msg->Type);
635 smprintf(s,"%c",msg->Length/256);
636 smprintf(s,"%c",msg->Length%256);
637 for (i=0;i<msg->Length;i++) {
638 smprintf(s,"%c",msg->Buffer[i]);
642 Reply=s->User.UserReplyFunctions;
643 if (Reply!=NULL) error=CheckReplyFunctions(s,Reply,&reply);
645 if (error==GE_UNKNOWNFRAME) {
646 Reply=s->Phone.Functions->ReplyFunctions;
647 error=CheckReplyFunctions(s,Reply,&reply);
650 if (error==GE_NONE) {
651 error=Reply[reply].Function(*msg, s);
652 if ((unsigned int)Reply[reply].requestID==Phone->RequestID) {
653 if (error == GE_NEEDANOTHERANSWER) {
654 error = GE_NONE;
655 } else {
656 Phone->RequestID=ID_None;
661 if (strcmp(s->Phone.Functions->models,"NAUTO")) {
662 if (s->di.dl==DL_TEXT || s->di.dl==DL_TEXTALL || s->di.dl==DL_TEXTERROR ||
663 s->di.dl==DL_TEXTDATE || s->di.dl==DL_TEXTALLDATE || s->di.dl==DL_TEXTERRORDATE)
665 disp = true;
666 switch (error) {
667 case GE_UNKNOWNRESPONSE:
668 smprintf(s, "\nUNKNOWN response");
669 break;
670 case GE_UNKNOWNFRAME:
671 smprintf(s, "\nUNKNOWN frame");
672 break;
673 case GE_FRAMENOTREQUESTED:
674 smprintf(s, "\nFrame not request now");
675 break;
676 default:
677 disp = false;
681 if (error == GE_UNKNOWNFRAME || error == GE_FRAMENOTREQUESTED) {
682 error = GE_TIMEOUT;
686 if (disp) {
687 smprintf(s,". If you can, PLEASE report it (see readme.txt). THANK YOU\n");
688 if (Phone->SentMsg != NULL) {
689 smprintf(s,"Last sent message ");
690 smprintf(s, "0x%02x / 0x%04x", Phone->SentMsg->Type, Phone->SentMsg->Length);
691 DumpMessage(s->di.df, Phone->SentMsg->Buffer, Phone->SentMsg->Length);
693 smprintf(s, "Received frame ");
694 smprintf(s, "0x%02x / 0x%04x", msg->Type, msg->Length);
695 DumpMessage(s->di.df, msg->Buffer, msg->Length);
696 smprintf(s, "\n");
699 return error;
702 INI_Section *GSM_FindGammuRC(void)
704 INI_Section *ini_file;
705 char *HomeDrive,*HomePath,*FileName=malloc(1);
706 int FileNameUsed=1;
708 FileName[0] = 0;
709 #if defined(WIN32) || defined(DJGPP)
710 HomeDrive = getenv("HOMEDRIVE");
711 if (HomeDrive) {
712 FileName = realloc(FileName,FileNameUsed+strlen(HomeDrive)+1);
713 FileName = strcat(FileName, HomeDrive);
714 FileNameUsed += strlen(HomeDrive)+1;
716 HomePath = getenv("HOMEPATH");
717 if (HomePath) {
718 FileName = realloc(FileName,FileNameUsed+strlen(HomePath)+1);
719 FileName = strcat(FileName, HomePath);
720 FileNameUsed += strlen(HomePath)+1;
722 FileName = realloc(FileName,FileNameUsed+8+1);
723 strcat(FileName, "\\gammurc");
724 #else
725 HomeDrive = NULL;
726 HomePath = getenv("HOME");
727 if (HomePath) {
728 FileName = realloc(FileName,FileNameUsed+strlen(HomePath)+1);
729 FileName = strcat(FileName, HomePath);
730 FileNameUsed += strlen(HomePath)+1;
732 FileName = realloc(FileName,FileNameUsed+9+1);
733 strcat(FileName, "/.gammurc");
734 #endif
735 // dbgprintf("\"%s\"\n",FileName);
737 ini_file = INI_ReadFile(FileName, false);
738 free(FileName);
739 if (ini_file == NULL) {
740 #if defined(WIN32) || defined(DJGPP)
741 ini_file = INI_ReadFile("gammurc", false);
742 if (ini_file == NULL) return NULL;
743 #else
744 ini_file = INI_ReadFile("/etc/gammurc", false);
745 if (ini_file == NULL) return NULL;
746 #endif
749 return ini_file;
752 bool GSM_ReadConfig(INI_Section *cfg_info, GSM_Config *cfg, int num)
754 INI_Section *h;
755 unsigned char section[50];
756 bool found = false;
758 #if defined(WIN32) || defined(DJGPP)
759 char *DefaultPort = "com2:";
760 #else
761 char *DefaultPort = "/dev/ttyS1";
762 #endif
763 char *DefaultModel = "";
764 char *DefaultConnection = "fbus";
765 char *DefaultSynchronizeTime = "no";
766 char *DefaultDebugFile = "";
767 char *DefaultDebugLevel = "";
768 char *DefaultLockDevice = "no";
769 char *DefaultStartInfo = "no";
770 char *Temp;
772 /* By default all debug output will go to one filedescriptor */
773 bool DefaultUseGlobalDebugFile = true;
775 cfg->Device = DefaultPort;
776 cfg->Connection = DefaultConnection;
777 cfg->SyncTime = DefaultSynchronizeTime;
778 cfg->DebugFile = DefaultDebugFile;
779 strcpy(cfg->Model,DefaultModel);
780 strcpy(cfg->DebugLevel,DefaultDebugLevel);
781 cfg->LockDevice = DefaultLockDevice;
782 cfg->StartInfo = DefaultStartInfo;
783 cfg->DefaultDevice = true;
784 cfg->DefaultModel = true;
785 cfg->DefaultConnection = true;
786 cfg->DefaultSyncTime = true;
787 cfg->DefaultDebugFile = true;
788 cfg->DefaultDebugLevel = true;
789 cfg->DefaultLockDevice = true;
790 cfg->DefaultStartInfo = true;
792 cfg->UseGlobalDebugFile = DefaultUseGlobalDebugFile;
794 if (cfg_info==NULL) return false;
796 if (num == 0) {
797 sprintf(section,"gammu");
798 } else {
799 sprintf(section,"gammu%i",num);
801 for (h = cfg_info; h != NULL; h = h->Next) {
802 if (mystrncasecmp(section, h->SectionName, strlen(section))) {
803 found = true;
804 break;
807 if (!found) return false;
809 cfg->Device = INI_GetValue(cfg_info, section, "port", false);
810 if (!cfg->Device) {
811 cfg->Device = DefaultPort;
812 } else {
813 cfg->DefaultDevice = false;
815 cfg->Connection = INI_GetValue(cfg_info, section, "connection", false);
816 if (!cfg->Connection) {
817 cfg->Connection = DefaultConnection;
818 } else {
819 cfg->DefaultConnection = false;
821 cfg->SyncTime = INI_GetValue(cfg_info, section, "synchronizetime", false);
822 if (!cfg->SyncTime) {
823 cfg->SyncTime = DefaultSynchronizeTime;
824 } else {
825 cfg->DefaultSyncTime = false;
827 cfg->DebugFile = INI_GetValue(cfg_info, section, "logfile", false);
828 if (!cfg->DebugFile) {
829 cfg->DebugFile = DefaultDebugFile;
830 } else {
831 cfg->DefaultDebugFile = false;
833 cfg->LockDevice = INI_GetValue(cfg_info, section, "use_locking", false);
834 if (!cfg->LockDevice) {
835 cfg->LockDevice = DefaultLockDevice;
836 } else {
837 cfg->DefaultLockDevice = false;
839 Temp = INI_GetValue(cfg_info, section, "model", false);
840 if (!Temp) {
841 strcpy(cfg->Model,DefaultModel);
842 } else {
843 cfg->DefaultModel = false;
844 strcpy(cfg->Model,Temp);
846 Temp = INI_GetValue(cfg_info, section, "logformat", false);
847 if (!Temp) {
848 strcpy(cfg->DebugLevel,DefaultDebugLevel);
849 } else {
850 cfg->DefaultDebugLevel = false;
851 strcpy(cfg->DebugLevel,Temp);
853 cfg->StartInfo = INI_GetValue(cfg_info, section, "startinfo", false);
854 if (!cfg->StartInfo) {
855 cfg->StartInfo = DefaultStartInfo;
856 } else {
857 cfg->DefaultStartInfo = false;
859 return true;
862 static OnePhoneModel allmodels[] = {
863 #ifdef GSM_ENABLE_NOKIA6510
864 {"1100", "RH-18" ,"", {0}},
865 {"1100a","RH-38" ,"", {0}},
866 {"1100b","RH-36" ,"", {0}},
867 #endif
868 #ifdef GSM_ENABLE_NOKIA6110
869 {"2100" ,"NAM-2" ,"", {F_NOWAP,F_NOCALLER,F_RING_SM,F_CAL33,F_POWER_BATT,F_PROFILES33,F_NOCALLINFO,F_NODTMF,0}},//quess
870 #endif
871 #ifdef GSM_ENABLE_NOKIA6510
872 {"3100" ,"RH-19" ,"", {0}},
873 {"3100b","RH-50" ,"", {0}},
874 {"3200", "RH-30" ,"Nokia 3200", {0}},
875 {"3200a","RH-31" ,"Nokia 3200", {0}},
876 #endif
877 #ifdef GSM_ENABLE_NOKIA6110
878 {"3210" ,"NSE-8" ,"", {F_NOWAP,F_NOCALLER,F_NOCALENDAR,F_NOPBKUNICODE,F_POWER_BATT,F_PROFILES51,F_NOPICTUREUNI,F_NOCALLINFO,F_NODTMF,0}},
879 {"3210" ,"NSE-9" ,"", {F_NOWAP,F_NOCALLER,F_NOCALENDAR,F_NOPBKUNICODE,F_POWER_BATT,F_PROFILES51,F_NOPICTUREUNI,F_NOCALLINFO,F_NODTMF,0}},
880 #endif
881 #ifdef GSM_ENABLE_NOKIA6510
882 {"3300" ,"NEM-1" ,"Nokia 3300", {0}},
883 {"3300" ,"NEM-2" ,"Nokia 3300", {0}},
884 #endif
885 #ifdef GSM_ENABLE_NOKIA6110
886 {"3310" ,"NHM-5" ,"", {F_NOWAP,F_NOCALLER,F_RING_SM,F_CAL33,F_POWER_BATT,F_PROFILES33,F_NOCALLINFO,F_NODTMF,0}},
887 {"3330" ,"NHM-6" ,"", {F_NOCALLER,F_RING_SM,F_CAL33,F_PROFILES33,F_NOPICTUREUNI,F_NOCALLINFO,F_NODTMF,0}},
888 {"3390" ,"NPB-1" ,"", {F_NOWAP,F_NOCALLER,F_RING_SM,F_CAL33,F_PROFILES33,F_NOPICTUREUNI,F_NOCALLINFO,F_NODTMF,0}},
889 {"3410" ,"NHM-2" ,"", {F_RING_SM,F_CAL33,F_PROFILES33,F_NOCALLINFO,F_NODTMF,0}},
890 #endif
891 #ifdef GSM_ENABLE_NOKIA6510
892 {"3510" ,"NHM-8" ,"", {F_CAL35,F_PBK35,F_NOGPRSPOINT,F_VOICETAGS,0}},
893 {"3510i","RH-9" ,"", {F_CAL35,F_PBK35,F_NOGPRSPOINT,F_VOICETAGS,0}},
894 {"3530" ,"RH-9" ,"", {F_CAL35,F_PBK35,F_NOGPRSPOINT,F_VOICETAGS,0}},
895 {"3590" ,"NPM-8" ,"", {0}},//irda?
896 {"3595" ,"NPM-10" ,"", {0}},//irda?
897 #endif
898 #ifdef GSM_ENABLE_NOKIA6110
899 {"3610" ,"NAM-1" ,"", {F_NOCALLER,F_RING_SM,F_CAL33,F_POWER_BATT,F_PROFILES33,F_NOCALLINFO,F_NODTMF,0}},//quess
900 #endif
901 #if defined(GSM_ENABLE_ATGEN) || defined(GSM_ENABLE_NOKIA6510)
902 {"3650" ,"NHL-8" ,"Nokia 3650", {F_RADIO,0}},
903 {"5100" ,"NPM-6" ,"Nokia 5100", {F_TODO66,F_RADIO,0}},
904 {"5100" ,"NPM-6U","Nokia 5100", {F_TODO66,F_RADIO,0}},
905 {"5100" ,"NPM-6X","Nokia 5100", {F_TODO66,F_RADIO,0}},
906 #endif
907 #ifdef GSM_ENABLE_NOKIA6110
908 {"5110" ,"NSE-1" ,"", {F_NOWAP,F_NOCALLER,F_NORING,F_NOPICTURE,F_NOSTARTUP,F_NOCALENDAR,F_NOPBKUNICODE,F_PROFILES51,F_MAGICBYTES,F_DISPSTATUS,0}},
909 {"5110i","NSE-2" ,"", {F_NOWAP,F_NOCALLER,F_NORING,F_NOPICTURE,F_NOSTARTUP,F_NOCALENDAR,F_NOPBKUNICODE,F_PROFILES51,F_MAGICBYTES,F_DISPSTATUS,0}},
910 {"5130" ,"NSK-1" ,"", {F_NOWAP,F_NOCALLER,F_NORING,F_NOPICTURE,F_NOSTARTUP,F_NOCALENDAR,F_NOPBKUNICODE,F_PROFILES51,F_MAGICBYTES,F_DISPSTATUS,0}},
911 {"5190" ,"NSB-1" ,"", {F_NOWAP,F_NOCALLER,F_NORING,F_NOPICTURE,F_NOSTARTUP,F_NOCALENDAR,F_NOPBKUNICODE,F_PROFILES51,F_MAGICBYTES,F_DISPSTATUS,0}},
912 #endif
913 #if defined(GSM_ENABLE_ATGEN) || defined(GSM_ENABLE_NOKIA6110)
914 {"5210" ,"NSM-5" ,"Nokia 5210", {F_CAL52,F_NOSTARTANI,F_NOPICTUREUNI,F_NODTMF,0}},
915 #endif
916 #ifdef GSM_ENABLE_NOKIA6110
917 {"5510" ,"NPM-5" ,"", {F_NOCALLER,F_PROFILES33,F_NOPICTUREUNI,0}},
918 #endif
919 #if defined(GSM_ENABLE_ATGEN) || defined(GSM_ENABLE_NOKIA6510)
920 {"6100" ,"NPL-2" ,"Nokia 6100", {F_TODO66,0}},
921 #endif
922 #ifdef GSM_ENABLE_NOKIA6110
923 {"6110" ,"NSE-3" ,"", {F_NOWAP,F_NOPICTURE,F_NOSTARTANI,F_NOPBKUNICODE,F_MAGICBYTES,F_DISPSTATUS,0}},
924 {"6130" ,"NSK-3" ,"", {F_NOWAP,F_NOPICTURE,F_NOSTARTANI,F_NOPBKUNICODE,F_MAGICBYTES,F_DISPSTATUS,0}},
925 {"6150" ,"NSM-1" ,"", {F_NOWAP,F_NOSTARTANI,F_NOPBKUNICODE,F_MAGICBYTES,F_DISPSTATUS,F_NOPICTUREUNI,0}},
926 {"6190" ,"NSB-3" ,"", {F_NOWAP,F_NOPICTURE,F_NOSTARTANI,F_NOPBKUNICODE,F_MAGICBYTES,F_DISPSTATUS,0}},
927 #endif
928 #if defined(GSM_ENABLE_ATGEN) || defined(GSM_ENABLE_NOKIA6510)
929 {"6200" ,"NPL-3" ,"Nokia 6200", {0}},
930 {"6220" ,"RH-20" ,"Nokia 6220", {F_TODO66,0}},
931 #endif
932 #if defined(GSM_ENABLE_ATGEN) || defined(GSM_ENABLE_NOKIA7110)
933 {"6210" ,"NPE-3" ,"Nokia 6210", {F_VOICETAGS,F_CAL62,0}},
934 {"6250" ,"NHM-3" ,"Nokia 6250", {F_VOICETAGS,F_CAL62,0}},
935 #endif
936 #if defined(GSM_ENABLE_ATGEN) || defined(GSM_ENABLE_NOKIA6510)
937 {"6310" ,"NPE-4" ,"Nokia 6310", {F_TODO63,F_CAL65,F_NOMIDI,F_NOMMS,F_VOICETAGS,0}},
938 {"6310i","NPL-1" ,"Nokia 6310i",{F_TODO63,F_CAL65,F_NOMIDI,F_BLUETOOTH,F_NOMMS,F_VOICETAGS,0}},
939 {"6510" ,"NPM-9" ,"Nokia 6510", {F_TODO63,F_CAL65,F_NOMIDI,F_RADIO,F_NOFILESYSTEM,F_NOMMS,F_VOICETAGS,0}},
940 {"6610" ,"NHL-4U","Nokia 6610", {F_TODO66,F_RADIO,0}},
941 {"6800" ,"NSB-9" ,"Nokia 6800", {F_TODO66,F_RADIO,0}},
942 {"6800" ,"NHL-6" ,"Nokia 6800", {F_TODO66,F_RADIO,0}},
943 #endif
944 #if defined(GSM_ENABLE_ATGEN) || defined(GSM_ENABLE_NOKIA7110)
945 {"7110" ,"NSE-5" ,"Nokia 7110", {F_CAL62,0}},
946 {"7190" ,"NSB-5" ,"Nokia 7190", {F_CAL62,0}},
947 #endif
948 #if defined(GSM_ENABLE_ATGEN) || defined(GSM_ENABLE_NOKIA6510)
949 {"7210" ,"NHL-4" ,"Nokia 7210", {F_TODO66,F_RADIO,0}},
950 {"7250" ,"NHL-4J","Nokia 7250", {F_TODO66,F_RADIO,0}},
951 {"7250i","NHL-4JX","Nokia 7250i",{F_TODO66,F_RADIO,0}},
952 #endif
953 #if defined(GSM_ENABLE_ATGEN)
954 {"7650" ,"NHL-2" ,"Nokia 7650", {0}},
955 #endif
956 #if defined(GSM_ENABLE_ATGEN) || defined(GSM_ENABLE_NOKIA6110)
957 {"8210" ,"NSM-3" ,"Nokia 8210", {F_NOWAP,F_NOSTARTANI,F_NOPBKUNICODE,F_NOPICTUREUNI,0}},
958 {"8250" ,"NSM-3D","Nokia 8250", {F_NOWAP,F_NOSTARTANI,F_CAL82,F_NOPICTUREUNI,0}},
959 {"8290" ,"NSB-7" ,"Nokia 8290", {F_NOWAP,F_NOSTARTANI,F_NOPBKUNICODE,F_NOPICTUREUNI,0}},
960 #endif
961 #if defined(GSM_ENABLE_ATGEN) || defined(GSM_ENABLE_NOKIA6510)
962 {"8310" ,"NHM-7" ,"Nokia 8310", {F_CAL62,F_NOMIDI,F_RADIO,F_NOFILESYSTEM,F_NOMMS,F_VOICETAGS,0}},
963 {"8390" ,"NSB-8" ,"Nokia 8390", {F_CAL62,F_NOMIDI,F_RADIO,F_NOFILESYSTEM,F_NOMMS,F_VOICETAGS,0}},
964 #endif
965 #if defined(GSM_ENABLE_ATGEN) || defined(GSM_ENABLE_NOKIA6110)
966 {"8850" ,"NSM-2" ,"Nokia 8850", {0}},
967 {"8855" ,"NSM-4" ,"Nokia 8855", {0}},
968 {"8890" ,"NSB-6" ,"Nokia 8890", {0}},
969 #endif
970 #if defined(GSM_ENABLE_ATGEN) || defined(GSM_ENABLE_NOKIA6510)
971 {"8910" ,"NHM-4" ,"Nokia 8910", {F_CAL62,F_NOMIDI,F_NOFILESYSTEM,F_NOMMS,0}},
972 {"8910i","NHM-4" ,"Nokia 8910i",{F_CAL62,F_NOMIDI,F_NOFILESYSTEM,F_NOMMS,0}},
973 #endif
974 #ifdef GSM_ENABLE_NOKIA9210
975 {"9210" ,"RAE-3" ,"", {0}},
976 {"9210i","RAE-5" ,"", {0}},
977 #endif
978 #ifdef GSM_ENABLE_ATGEN
979 {"at" , "at", "", {0}},
980 {"M20" , "M20", "", {F_M20SMS,F_SLOWWRITE,0}},
981 {"MC35" , "MC35", "", {0}},
982 {"S25", "S25", "SIEMENS S25", {0}},
983 {"C35i" , "C35i", "", {0}},
984 {"S35i" , "S35i", "", {0}},
985 {"M35i" , "M35i", "", {0}},
986 {"S40" , "Siemens S40", "", {0}},
987 {"C45" , "C45", "", {0}},
988 {"S45" , "S45", "", {0}},
989 {"ME45" , "ME45", "", {0}},
990 {"SL45" , "SL45", "", {0}},
991 {"SL45i" , "SL45i", "", {0}},
992 {"M50" , "M50", "", {0}},
993 {"S45" , "6618" , "", {0}},
994 {"ME45" , "3618" , "", {0}},
995 {"S55" , "S55" , "", {0}},
996 {"T28s", "1101101-BVT28s","", {0}},
997 {"R320s" , "1101201-BV R320s","", {0}},
998 {"R380s", "7100101-BVR380s" ,"", {0}},
999 {"R520m", "1130101-BVR520m" ,"", {0}},
1000 {"T39m", "1130102-BVT39m" ,"", {0}},
1001 {"T65", "1101901-BVT65" , "", {0}},
1002 {"T68", "1130201-BVT68" , "", {0}},
1003 {"T68i", "1130202-BVT68" , "", {0}},
1004 {"R600", "102001-BVR600" , "", {0}},
1005 {"T200", "1130501-BVT200" ,"", {0}},
1006 {"T300", "1130601-BVT300" ,"T300", {0}},
1007 {"T310", "1130602-BVT310" ,"", {0}},
1008 {"P800", "7130501-BVP800" ,"", {0}},
1009 {"iPAQ" , "iPAQ" , "" , {0}},
1010 {"A2D" , "A2D" , "" , {0}},
1011 {"9210" , "RAE-3", "Nokia Communicator GSM900/1800",{0}},
1012 #endif
1013 #if defined(GSM_ENABLE_ATGEN) || defined(GSM_ENABLE_ALCATEL)
1014 {"BE5", "ONE TOUCH 500","", {F_SMSONLYSENT,F_BROKENCPBS,0}},
1015 {"BH4", "ONE TOUCH 535","ALCATEL OT535", {0}},
1016 {"BF5", "ONE TOUCH 715","ALCATEL OT715", {0}},
1017 #endif
1018 {"unknown", "" ,"", {0}}
1021 OnePhoneModel *GetModelData(char *model, char *number, char *irdamodel)
1023 int i = 0;
1025 while (strcmp(allmodels[i].number,"") != 0) {
1026 if (model !=NULL) {
1027 if (strcmp (model, allmodels[i].model) == 0) {
1028 return (&allmodels[i]);
1031 if (number !=NULL) {
1032 if (strcmp (number, allmodels[i].number) == 0) {
1033 return (&allmodels[i]);
1036 if (irdamodel !=NULL) {
1037 if (strcmp (irdamodel, allmodels[i].irdamodel) == 0) {
1038 return (&allmodels[i]);
1041 i++;
1043 return (&allmodels[i]);
1046 bool IsPhoneFeatureAvailable(OnePhoneModel *model, int feature)
1048 int i = 0;
1049 bool retval = false;
1051 while (model->features[i] != 0) {
1052 if (model->features[i] == feature) {
1053 retval = true;
1054 break;
1056 i++;
1058 return retval;
1061 void GSM_DumpMessageLevel2(GSM_StateMachine *s, unsigned char *message, int messagesize, int type)
1063 if (s->di.dl==DL_TEXT || s->di.dl==DL_TEXTALL ||
1064 s->di.dl==DL_TEXTDATE || s->di.dl==DL_TEXTALLDATE) {
1065 smprintf(s,"Sending frame ");
1066 smprintf(s,"0x%02x / 0x%04x", type, messagesize);
1067 DumpMessage(s->di.df, message, messagesize);
1068 if (messagesize == 0) smprintf(s,"\n");
1069 if (s->di.df) fflush(s->di.df);
1073 void GSM_DumpMessageLevel3(GSM_StateMachine *s, unsigned char *message, int messagesize, int type)
1075 int i;
1077 if (s->di.dl==DL_BINARY) {
1078 smprintf(s,"%c",0x01); /* Sending */
1079 smprintf(s,"%c",type);
1080 smprintf(s,"%c",messagesize/256);
1081 smprintf(s,"%c",messagesize%256);
1082 for (i=0;i<messagesize;i++) smprintf(s,"%c",message[i]);
1086 int smprintf(GSM_StateMachine *s, const char *format, ...)
1088 va_list argp;
1089 int result=0;
1090 unsigned char buffer[2000];
1092 va_start(argp, format);
1093 if (s == NULL) {
1094 if (di.dl != 0 && di.df) {
1095 result = vsprintf(buffer, format, argp);
1096 result = smfprintf(di.df, buffer);
1098 } else {
1099 if (s->di.dl != 0 && s->di.df) {
1100 result = vsprintf(buffer, format, argp);
1101 result = smfprintf(s->di.df, buffer);
1104 va_end(argp);
1105 return result;
1108 void GSM_OSErrorInfo(GSM_StateMachine *s, char *description)
1110 #ifdef WIN32
1111 int i;
1112 unsigned char *lpMsgBuf;
1114 /* We don't use errno in win32 - GetLastError gives better info */
1115 if (GetLastError()!=-1) {
1116 if (s->di.dl == DL_TEXTERROR || s->di.dl == DL_TEXT || s->di.dl == DL_TEXTALL ||
1117 s->di.dl == DL_TEXTERRORDATE || s->di.dl == DL_TEXTDATE || s->di.dl == DL_TEXTALLDATE) {
1118 FormatMessage(
1119 FORMAT_MESSAGE_ALLOCATE_BUFFER |
1120 FORMAT_MESSAGE_FROM_SYSTEM |
1121 FORMAT_MESSAGE_IGNORE_INSERTS,
1122 NULL,
1123 GetLastError(),
1124 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
1125 (LPTSTR) &lpMsgBuf,
1127 NULL
1129 for (i=0;i<(int)strlen(lpMsgBuf);i++) {
1130 if (lpMsgBuf[i] == 13 || lpMsgBuf[i] == 10) {
1131 lpMsgBuf[i] = ' ';
1134 smprintf(s,"[System error - %s, %i, \"%s\"]\n",description,GetLastError(),(LPCTSTR)lpMsgBuf);
1135 LocalFree(lpMsgBuf);
1138 return;
1139 #endif
1141 if (errno!=-1) {
1142 if (s->di.dl == DL_TEXTERROR || s->di.dl == DL_TEXT || s->di.dl == DL_TEXTALL ||
1143 s->di.dl == DL_TEXTERRORDATE || s->di.dl == DL_TEXTDATE || s->di.dl == DL_TEXTALLDATE) {
1144 smprintf(s,"[System error - %s, %i, \"%s\"]\n",description,errno,strerror(errno));
1149 /* How should editor hadle tabs in this file? Add editor commands here.
1150 * vim: noexpandtab sw=8 ts=8 sts=8: