summaryrefslogtreecommitdiffabout
path: root/gammu/emb/common/gsmstate.c
authorzautrix <zautrix>2004-08-07 17:24:40 (UTC)
committer zautrix <zautrix>2004-08-07 17:24:40 (UTC)
commit88b0d33b8b0b1f6ae320cfc863ca6a47fa8fec22 (patch) (unidiff)
tree6331418973714243beb674abc87692277b83869d /gammu/emb/common/gsmstate.c
parentef8a09ce74ad3f0a51484d03fdf009bd5b3677bf (diff)
downloadkdepimpi-88b0d33b8b0b1f6ae320cfc863ca6a47fa8fec22.zip
kdepimpi-88b0d33b8b0b1f6ae320cfc863ca6a47fa8fec22.tar.gz
kdepimpi-88b0d33b8b0b1f6ae320cfc863ca6a47fa8fec22.tar.bz2
Initial revision
Diffstat (limited to 'gammu/emb/common/gsmstate.c') (more/less context) (show whitespace changes)
-rw-r--r--gammu/emb/common/gsmstate.c1246
1 files changed, 1246 insertions, 0 deletions
diff --git a/gammu/emb/common/gsmstate.c b/gammu/emb/common/gsmstate.c
new file mode 100644
index 0000000..b8f5f89
--- a/dev/null
+++ b/gammu/emb/common/gsmstate.c
@@ -0,0 +1,1246 @@
1/* (c) 2002-2004 by Marcin Wiacek */
2/* Phones ID (c) partially by Walek */
3
4#include <stdarg.h>
5#include <string.h>
6#include <errno.h>
7
8#include "gsmcomon.h"
9#include "gsmstate.h"
10#include "misc/cfg.h"
11#include "misc/coding/coding.h"
12#include "device/devfunc.h"
13
14static void GSM_RegisterConnection(GSM_StateMachine *s, unsigned int connection,
15 GSM_Device_Functions *device, GSM_Protocol_Functions *protocol)
16{
17 if ((unsigned int)s->ConnectionType == connection) {
18 s->Device.Functions = device;
19 s->Protocol.Functions= protocol;
20 }
21}
22
23static GSM_Error GSM_RegisterAllConnections(GSM_StateMachine *s, char *connection)
24{
25 /* We check here is used connection string type is correct for ANY
26 * OS. If not, we return with error, that string is incorrect at all
27 */
28 s->ConnectionType = 0;
29 if (mystrncasecmp("mbus",connection,0)) s->ConnectionType = GCT_MBUS2;
30 if (mystrncasecmp("fbus",connection,0)) s->ConnectionType = GCT_FBUS2;
31 if (mystrncasecmp("fbusdlr3",connection,0)) s->ConnectionType = GCT_FBUS2DLR3;
32 if (mystrncasecmp("fbusdku5",connection,0)) s->ConnectionType = GCT_FBUS2DKU5;
33 if (mystrncasecmp("fbuspl2303",connection,0)) s->ConnectionType = GCT_FBUS2PL2303;
34 if (mystrncasecmp("fbusblue",connection,0)) s->ConnectionType = GCT_FBUS2BLUE;
35 if (mystrncasecmp("fbusirda",connection,0)) s->ConnectionType = GCT_FBUS2IRDA;
36 if (mystrncasecmp("phonetblue",connection,0)) s->ConnectionType = GCT_PHONETBLUE;
37 if (mystrncasecmp("mrouterblue",connection,0)) s->ConnectionType = GCT_MROUTERBLUE;
38 if (mystrncasecmp("irdaphonet",connection,0)) s->ConnectionType = GCT_IRDAPHONET;
39 if (mystrncasecmp("irdaat",connection,0)) s->ConnectionType = GCT_IRDAAT;
40 if (mystrncasecmp("irdaobex",connection,0)) s->ConnectionType = GCT_IRDAOBEX;
41 if (mystrncasecmp("blueobex",connection,0)) s->ConnectionType = GCT_BLUEOBEX;
42 if (mystrncasecmp("bluefbus",connection,0)) s->ConnectionType = GCT_BLUEFBUS2;
43 if (mystrncasecmp("bluephonet",connection,0)) s->ConnectionType = GCT_BLUEPHONET;
44 if (mystrncasecmp("blueat",connection,0)) s->ConnectionType = GCT_BLUEAT;
45 if (mystrncasecmp("bluerfobex",connection,0)) s->ConnectionType = GCT_BLUEOBEX;
46 if (mystrncasecmp("bluerffbus",connection,0)) s->ConnectionType = GCT_BLUEFBUS2;
47 if (mystrncasecmp("bluerfphonet",connection,0)) s->ConnectionType = GCT_BLUEPHONET;
48 if (mystrncasecmp("bluerfat",connection,0)) s->ConnectionType = GCT_BLUEAT;
49
50 /* These are for compatibility only */
51 if (mystrncasecmp("atblue",connection,0)) s->ConnectionType = GCT_BLUEAT;
52 if (mystrncasecmp("dlr3blue",connection,0)) s->ConnectionType = GCT_BLUEFBUS2;
53 if (mystrncasecmp("irda",connection,0)) s->ConnectionType = GCT_IRDAPHONET;
54 if (mystrncasecmp("dlr3",connection,0)) s->ConnectionType = GCT_FBUS2DLR3;
55 if (mystrncasecmp("infrared",connection,0)) s->ConnectionType = GCT_FBUS2IRDA;
56
57 if (mystrncasecmp("at" ,connection,2)) {
58 /* Use some resonable default, when no speed defined */
59 if (strlen(connection) == 2) {
60 s->Speed = 19200;
61 } else {
62 s->Speed = FindSerialSpeed(connection+2);
63 }
64 if (s->Speed != 0) s->ConnectionType = GCT_AT;
65 }
66 if (s->ConnectionType==0) return ERR_UNKNOWNCONNECTIONTYPESTRING;
67
68 /* We check now if user gave connection type compiled & available
69 * for used OS (if not, we return, that source not available)
70 */
71 s->Device.Functions = NULL;
72 s->Protocol.Functions= NULL;
73#ifdef GSM_ENABLE_MBUS2
74 GSM_RegisterConnection(s, GCT_MBUS2, &SerialDevice, &MBUS2Protocol);
75#endif
76#ifdef GSM_ENABLE_FBUS2
77 GSM_RegisterConnection(s, GCT_FBUS2, &SerialDevice, &FBUS2Protocol);
78#endif
79#ifdef GSM_ENABLE_FBUS2DLR3
80 GSM_RegisterConnection(s, GCT_FBUS2DLR3, &SerialDevice, &FBUS2Protocol);
81#endif
82#ifdef GSM_ENABLE_FBUS2DKU5
83 GSM_RegisterConnection(s, GCT_FBUS2DKU5, &SerialDevice, &FBUS2Protocol);
84#endif
85#ifdef GSM_ENABLE_FBUS2PL2303
86 GSM_RegisterConnection(s, GCT_FBUS2PL2303,&SerialDevice, &FBUS2Protocol);
87#endif
88#ifdef GSM_ENABLE_FBUS2BLUE
89 GSM_RegisterConnection(s, GCT_FBUS2BLUE, &SerialDevice, &FBUS2Protocol);
90#endif
91#ifdef GSM_ENABLE_FBUS2IRDA
92 GSM_RegisterConnection(s, GCT_FBUS2IRDA, &SerialDevice, &FBUS2Protocol);
93#endif
94#ifdef GSM_ENABLE_PHONETBLUE
95 GSM_RegisterConnection(s, GCT_PHONETBLUE,&SerialDevice, &PHONETProtocol);
96#endif
97#ifdef GSM_ENABLE_MROUTERBLUE
98 GSM_RegisterConnection(s, GCT_MROUTERBLUE,&SerialDevice, &MROUTERProtocol);
99#endif
100#ifdef GSM_ENABLE_IRDAPHONET
101 GSM_RegisterConnection(s, GCT_IRDAPHONET,&IrdaDevice, &PHONETProtocol);
102#endif
103#ifdef GSM_ENABLE_BLUEFBUS2
104 GSM_RegisterConnection(s, GCT_BLUEFBUS2, &BlueToothDevice,&FBUS2Protocol);
105#endif
106#ifdef GSM_ENABLE_BLUEPHONET
107 GSM_RegisterConnection(s, GCT_BLUEPHONET,&BlueToothDevice,&PHONETProtocol);
108#endif
109#ifdef GSM_ENABLE_BLUEAT
110 GSM_RegisterConnection(s, GCT_BLUEAT, &BlueToothDevice,&ATProtocol);
111#endif
112#ifdef GSM_ENABLE_AT
113 GSM_RegisterConnection(s, GCT_AT, &SerialDevice, &ATProtocol);
114#endif
115#ifdef GSM_ENABLE_IRDAAT
116 GSM_RegisterConnection(s, GCT_IRDAAT, &IrdaDevice, &ATProtocol);
117#endif
118#ifdef GSM_ENABLE_IRDAOBEX
119 GSM_RegisterConnection(s, GCT_IRDAOBEX, &IrdaDevice, &OBEXProtocol);
120#endif
121#ifdef GSM_ENABLE_BLUEOBEX
122 GSM_RegisterConnection(s, GCT_BLUEOBEX, &BlueToothDevice,&OBEXProtocol);
123#endif
124 if (s->Device.Functions==NULL || s->Protocol.Functions==NULL)
125 return ERR_SOURCENOTAVAILABLE;
126 return ERR_NONE;
127}
128
129static void GSM_RegisterModule(GSM_StateMachine *s,GSM_Phone_Functions *phone)
130{
131 /* Auto model */
132 if (s->CurrentConfig->Model[0] == 0) {
133 if (strstr(phone->models,GetModelData(NULL,s->Phone.Data.Model,NULL)->model) != NULL) {
134 smprintf(s,"[Module - \"%s\"]\n",phone->models);
135 s->Phone.Functions = phone;
136 }
137 } else {
138 if (strstr(phone->models,s->CurrentConfig->Model) != NULL) {
139 smprintf(s,"[Module - \"%s\"]\n",phone->models);
140 s->Phone.Functions = phone;
141 }
142 }
143}
144
145GSM_Error GSM_RegisterAllPhoneModules(GSM_StateMachine *s)
146{
147 OnePhoneModel *model;
148
149 /* Auto model */
150 if (s->CurrentConfig->Model[0] == 0) {
151 model = GetModelData(NULL,s->Phone.Data.Model,NULL);
152#ifdef GSM_ENABLE_ALCATEL
153 if (model->model[0] != 0 && IsPhoneFeatureAvailable(model, F_ALCATEL)) {
154 smprintf(s,"[Module - \"%s\"]\n",ALCATELPhone.models);
155 s->Phone.Functions = &ALCATELPhone;
156 return ERR_NONE;
157 }
158#endif
159#ifdef GSM_ENABLE_ATGEN
160 /* With ATgen and auto model we can work with unknown models too */
161 if (s->ConnectionType==GCT_AT || s->ConnectionType==GCT_BLUEAT || s->ConnectionType==GCT_IRDAAT) {
162 smprintf(s,"[Module - \"%s\"]\n",ATGENPhone.models);
163 s->Phone.Functions = &ATGENPhone;
164 return ERR_NONE;
165 }
166#endif
167 if (model->model[0] == 0) return ERR_UNKNOWNMODELSTRING;
168 }
169 s->Phone.Functions=NULL;
170#ifdef GSM_ENABLE_ATGEN
171 /* AT module can have the same models ID to "normal" Nokia modules */
172 if (s->ConnectionType==GCT_AT || s->ConnectionType==GCT_BLUEAT || s->ConnectionType==GCT_IRDAAT) {
173 GSM_RegisterModule(s,&ATGENPhone);
174 if (s->Phone.Functions!=NULL) return ERR_NONE;
175 }
176#endif
177#ifdef GSM_ENABLE_OBEXGEN
178 GSM_RegisterModule(s,&OBEXGENPhone);
179#endif
180#ifdef GSM_ENABLE_MROUTERGEN
181 GSM_RegisterModule(s,&MROUTERGENPhone);
182#endif
183#ifdef GSM_ENABLE_NOKIA3320
184 GSM_RegisterModule(s,&N3320Phone);
185#endif
186#ifdef GSM_ENABLE_NOKIA3650
187 GSM_RegisterModule(s,&N3650Phone);
188#endif
189#ifdef GSM_ENABLE_NOKIA6110
190 GSM_RegisterModule(s,&N6110Phone);
191#endif
192#ifdef GSM_ENABLE_NOKIA6510
193 GSM_RegisterModule(s,&N6510Phone);
194#endif
195#ifdef GSM_ENABLE_NOKIA7110
196 GSM_RegisterModule(s,&N7110Phone);
197#endif
198#ifdef GSM_ENABLE_NOKIA9210
199 GSM_RegisterModule(s,&N9210Phone);
200#endif
201#ifdef GSM_ENABLE_ALCATEL
202 GSM_RegisterModule(s,&ALCATELPhone);
203#endif
204 if (s->Phone.Functions==NULL) return ERR_UNKNOWNMODELSTRING;
205 return ERR_NONE;
206}
207
208GSM_Error GSM_InitConnection(GSM_StateMachine *s, int ReplyNum)
209{
210 GSM_Errorerror;
211 GSM_DateTimetime;
212 int i;
213 char Buffer[80];
214
215 for (i=0;i<s->ConfigNum;i++) {
216 s->CurrentConfig = &s->Config[i];
217
218 s->Speed = 0;
219 s->ReplyNum = ReplyNum;
220 s->Phone.Data.ModelInfo = GetModelData("unknown",NULL,NULL);
221 s->Phone.Data.Manufacturer[0] = 0;
222 s->Phone.Data.Model[0] = 0;
223 s->Phone.Data.Version[0] = 0;
224 s->Phone.Data.VerDate[0] = 0;
225 s->Phone.Data.VerNum = 0;
226 s->Phone.Data.StartInfoCounter = 0;
227 s->Phone.Data.SentMsg = NULL;
228
229 s->Phone.Data.HardwareCache[0] = 0;
230 s->Phone.Data.ProductCodeCache[0] = 0;
231 s->Phone.Data.EnableIncomingCall = false;
232 s->Phone.Data.EnableIncomingSMS = false;
233 s->Phone.Data.EnableIncomingCB = false;
234 s->Phone.Data.EnableIncomingUSSD = false;
235 s->User.UserReplyFunctions = NULL;
236 s->User.IncomingCall = NULL;
237 s->User.IncomingSMS = NULL;
238 s->User.IncomingCB = NULL;
239 s->User.IncomingUSSD = NULL;
240 s->User.SendSMSStatus = NULL;
241 s->LockFile = NULL;
242 s->opened = false;
243 s->Phone.Functions = NULL;
244
245 s->di = di;
246 s->di.use_global = s->CurrentConfig->UseGlobalDebugFile;
247 GSM_SetDebugLevel(s->CurrentConfig->DebugLevel, &s->di);
248 error=GSM_SetDebugFile(s->CurrentConfig->DebugFile, &s->di);
249 if (error != ERR_NONE) return error;
250
251 if (s->di.dl == DL_TEXTALL || s->di.dl == DL_TEXT || s->di.dl == DL_TEXTERROR ||
252 s->di.dl == DL_TEXTALLDATE || s->di.dl == DL_TEXTDATE || s->di.dl == DL_TEXTERRORDATE) {
253 smprintf(s,"[Gammu - version %s built %s %s]\n",VERSION,__TIME__,__DATE__);
254 smprintf(s,"[Connection - \"%s\"]\n",s->CurrentConfig->Connection);
255 smprintf(s,"[Model type - \"%s\"]\n",s->CurrentConfig->Model);
256 smprintf(s,"[Device - \"%s\"]\n",s->CurrentConfig->Device);
257
258 Buffer[0] = 0;
259 if (strlen(GetOS()) != 0) sprintf(Buffer,"%s",GetOS());
260 if (strlen(GetCompiler()) != 0) {
261 if (Buffer[0] != 0) strcat(Buffer+strlen(Buffer),", ");
262 strcat(Buffer+strlen(Buffer),GetCompiler());
263 }
264 if (Buffer[0] != 0) smprintf(s,"[OS/compiler - %s]\n",Buffer);
265 }
266 if (s->di.dl==DL_BINARY) {
267 smprintf(s,"%c",((unsigned char)strlen(VERSION)));
268 smprintf(s,"%s",VERSION);
269 }
270
271 error=GSM_RegisterAllConnections(s, s->CurrentConfig->Connection);
272 if (error!=ERR_NONE) return error;
273
274 /* Model auto */
275 if (s->CurrentConfig->Model[0]==0) {
276 if (mystrncasecmp(s->CurrentConfig->LockDevice,"yes",0)) {
277 error = lock_device(s->CurrentConfig->Device, &(s->LockFile));
278 if (error != ERR_NONE) return error;
279 }
280
281 /* Irda devices can set now model to some specific and
282 * we don't have to make auto detection later */
283 error=s->Device.Functions->OpenDevice(s);
284 if (i != s->ConfigNum - 1) {
285 if (error == ERR_DEVICEOPENERROR) continue;
286 if (error == ERR_DEVICELOCKED) continue;
287 if (error == ERR_DEVICENOTEXIST) continue;
288 if (error == ERR_DEVICEBUSY) continue;
289 if (error == ERR_DEVICENOPERMISSION) continue;
290 if (error == ERR_DEVICENODRIVER) continue;
291 if (error == ERR_DEVICENOTWORK) continue;
292 }
293 if (error!=ERR_NONE) {
294 if (s->LockFile!=NULL) unlock_device(&(s->LockFile));
295 return error;
296 }
297
298 s->opened = true;
299
300 error=s->Protocol.Functions->Initialise(s);
301 if (error!=ERR_NONE) return error;
302
303 /* If still auto model, try to get model by asking phone for it */
304 if (s->Phone.Data.Model[0]==0) {
305 smprintf(s,"[Module - \"auto\"]\n");
306 switch (s->ConnectionType) {
307#ifdef GSM_ENABLE_ATGEN
308 case GCT_AT:
309 case GCT_BLUEAT:
310 case GCT_IRDAAT:
311 s->Phone.Functions = &ATGENPhone;
312 break;
313#endif
314#ifdef GSM_ENABLE_OBEXGEN
315 case GCT_IRDAOBEX:
316 case GCT_BLUEOBEX:
317 s->Phone.Functions = &OBEXGENPhone;
318 break;
319#endif
320#ifdef GSM_ENABLE_MROUTERGEN
321 case GCT_MROUTERBLUE:
322 s->Phone.Functions = &MROUTERGENPhone;
323 break;
324#endif
325#if defined(GSM_ENABLE_NOKIA_DCT3) || defined(GSM_ENABLE_NOKIA_DCT4)
326 case GCT_MBUS2:
327 case GCT_FBUS2:
328 case GCT_FBUS2DLR3:
329 case GCT_FBUS2DKU5:
330 case GCT_FBUS2PL2303:
331 case GCT_FBUS2BLUE:
332 case GCT_FBUS2IRDA:
333 case GCT_PHONETBLUE:
334 case GCT_IRDAPHONET:
335 case GCT_BLUEFBUS2:
336 case GCT_BLUEPHONET:
337 s->Phone.Functions = &NAUTOPhone;
338 break;
339#endif
340 default:
341 s->Phone.Functions = NULL;
342 }
343 if (s->Phone.Functions == NULL) return ERR_UNKNOWN;
344
345 /* Please note, that AT module need to send first
346 * command for enabling echo
347 */
348 error=s->Phone.Functions->Initialise(s);
349 if (error == ERR_TIMEOUT && i != s->ConfigNum - 1) continue;
350 if (error != ERR_NONE) return error;
351
352 error=s->Phone.Functions->GetModel(s);
353 if (error == ERR_TIMEOUT && i != s->ConfigNum - 1) continue;
354 if (error != ERR_NONE) return error;
355 }
356 }
357
358 /* Switching to "correct" module */
359 error=GSM_RegisterAllPhoneModules(s);
360 if (error!=ERR_NONE) return error;
361
362 /* We didn't open device earlier ? Make it now */
363 if (!s->opened) {
364 if (mystrncasecmp(s->CurrentConfig->LockDevice,"yes",0)) {
365 error = lock_device(s->CurrentConfig->Device, &(s->LockFile));
366 if (error != ERR_NONE) return error;
367 }
368
369 error=s->Device.Functions->OpenDevice(s);
370 if (i != s->ConfigNum - 1) {
371 if (error == ERR_DEVICEOPENERROR) continue;
372 if (error == ERR_DEVICELOCKED) continue;
373 if (error == ERR_DEVICENOTEXIST) continue;
374 if (error == ERR_DEVICEBUSY) continue;
375 if (error == ERR_DEVICENOPERMISSION) continue;
376 if (error == ERR_DEVICENODRIVER) continue;
377 if (error == ERR_DEVICENOTWORK) continue;
378 }
379 if (error!=ERR_NONE) {
380 if (s->LockFile!=NULL) unlock_device(&(s->LockFile));
381 return error;
382 }
383
384 s->opened = true;
385
386 error=s->Protocol.Functions->Initialise(s);
387 if (error!=ERR_NONE) return error;
388 }
389
390 error=s->Phone.Functions->Initialise(s);
391 if (error == ERR_TIMEOUT && i != s->ConfigNum - 1) continue;
392 if (error != ERR_NONE) return error;
393
394 if (mystrncasecmp(s->CurrentConfig->StartInfo,"yes",0)) {
395 s->Phone.Functions->ShowStartInfo(s,true);
396 s->Phone.Data.StartInfoCounter = 30;
397 }
398
399 if (mystrncasecmp(s->CurrentConfig->SyncTime,"yes",0)) {
400 GSM_GetCurrentDateTime (&time);
401 s->Phone.Functions->SetDateTime(s,&time);
402 }
403
404 /* For debug it's good to have firmware and real model version and manufacturer */
405 error=s->Phone.Functions->GetManufacturer(s);
406 if (error == ERR_TIMEOUT && i != s->ConfigNum - 1) continue;
407 if (error != ERR_NONE) return error;
408 error=s->Phone.Functions->GetModel(s);
409 if (error != ERR_NONE) return error;
410 error=s->Phone.Functions->GetFirmware(s);
411 if (error != ERR_NONE) return error;
412 return ERR_NONE;
413 }
414 return ERR_UNKNOWN;
415}
416
417int GSM_ReadDevice (GSM_StateMachine *s, bool wait)
418{
419 unsigned charbuff[255];
420 int res = 0, count;
421
422 unsigned inti;
423 GSM_DateTimeDate;
424
425 GSM_GetCurrentDateTime (&Date);
426 i=Date.Second;
427 while (i==Date.Second) {
428 res = s->Device.Functions->ReadDevice(s, buff, 255);
429 if (!wait) break;
430 if (res > 0) break;
431 my_sleep(5);
432 GSM_GetCurrentDateTime(&Date);
433 }
434
435 for (count = 0; count < res; count++)
436 s->Protocol.Functions->StateMachine(s,buff[count]);
437
438 return res;
439}
440
441GSM_Error GSM_TerminateConnection(GSM_StateMachine *s)
442{
443 GSM_Error error;
444
445 if (!s->opened) return ERR_UNKNOWN;
446
447 smprintf(s,"[Closing]\n");
448
449 if (mystrncasecmp(s->CurrentConfig->StartInfo,"yes",0)) {
450 if (s->Phone.Data.StartInfoCounter > 0) s->Phone.Functions->ShowStartInfo(s,false);
451 }
452
453 if (s->Phone.Functions != NULL) {
454 error=s->Phone.Functions->Terminate(s);
455 if (error!=ERR_NONE) return error;
456 }
457
458 error=s->Protocol.Functions->Terminate(s);
459 if (error!=ERR_NONE) return error;
460
461 error = s->Device.Functions->CloseDevice(s);
462 if (error!=ERR_NONE) return error;
463
464 s->Phone.Data.ModelInfo = NULL;
465 s->Phone.Data.Manufacturer[0] = 0;
466 s->Phone.Data.Model[0] = 0;
467 s->Phone.Data.Version[0] = 0;
468 s->Phone.Data.VerDate[0] = 0;
469 s->Phone.Data.VerNum = 0;
470
471 if (s->LockFile!=NULL) unlock_device(&(s->LockFile));
472
473 if (!s->di.use_global && s->di.dl!=0 && fileno(s->di.df) != 1 && fileno(s->di.df) != 2) fclose(s->di.df);
474
475 s->opened = false;
476
477 return ERR_NONE;
478}
479
480GSM_Error GSM_WaitForOnce(GSM_StateMachine *s, unsigned char *buffer,
481 int length, unsigned char type, int time)
482{
483 GSM_Phone_Data *Phone = &s->Phone.Data;
484 GSM_Protocol_Message sentmsg;
485 int i;
486
487 i=0;
488 do {
489 if (length != 0) {
490 sentmsg.Length = length;
491 sentmsg.Type= type;
492 sentmsg.Buffer = (unsigned char *)malloc(length);
493 memcpy(sentmsg.Buffer,buffer,length);
494 Phone->SentMsg = &sentmsg;
495 }
496
497 /* Some data received. Reset timer */
498 if (GSM_ReadDevice(s,true)!=0) i=0;
499
500 if (length != 0) {
501 free (sentmsg.Buffer);
502 Phone->SentMsg = NULL;
503 }
504
505 /* Request completed */
506 if (Phone->RequestID==ID_None) return Phone->DispatchError;
507
508 i++;
509 } while (i<time);
510
511 return ERR_TIMEOUT;
512}
513
514GSM_Error GSM_WaitFor (GSM_StateMachine *s, unsigned char *buffer,
515 int length, unsigned char type, int time,
516 GSM_Phone_RequestID request)
517{
518 GSM_Phone_Data *Phone = &s->Phone.Data;
519 GSM_Error error;
520 int reply;
521
522 if (mystrncasecmp(s->CurrentConfig->StartInfo,"yes",0)) {
523 if (Phone->StartInfoCounter > 0) {
524 Phone->StartInfoCounter--;
525 if (Phone->StartInfoCounter == 0) s->Phone.Functions->ShowStartInfo(s,false);
526 }
527 }
528
529 Phone->RequestID= request;
530 Phone->DispatchError= ERR_TIMEOUT;
531
532 for (reply=0;reply<s->ReplyNum;reply++) {
533 if (reply!=0) {
534 if (s->di.dl==DL_TEXT || s->di.dl==DL_TEXTALL || s->di.dl == DL_TEXTERROR ||
535 s->di.dl==DL_TEXTDATE || s->di.dl==DL_TEXTALLDATE || s->di.dl == DL_TEXTERRORDATE)
536 {
537 smprintf(s, "[Retrying %i type 0x%02X]\n", reply, type);
538 }
539 }
540 error = s->Protocol.Functions->WriteMessage(s, buffer, length, type);
541 if (error!=ERR_NONE) return error;
542
543 error = GSM_WaitForOnce(s, buffer, length, type, time);
544 if (error != ERR_TIMEOUT) return error;
545 }
546
547 return Phone->DispatchError;
548}
549
550static GSM_Error CheckReplyFunctions(GSM_StateMachine *s, GSM_Reply_Function *Reply, int *reply)
551{
552 GSM_Phone_Data *Data = &s->Phone.Data;
553 GSM_Protocol_Message *msg = s->Phone.Data.RequestMsg;
554 bool execute;
555 bool available = false;
556 int i = 0;
557
558 while (Reply[i].requestID!=ID_None) {
559 execute=false;
560 /* Binary frames like in Nokia */
561 if (strlen(Reply[i].msgtype) < 2) {
562 if (Reply[i].msgtype[0]==msg->Type) {
563 if (Reply[i].subtypechar!=0) {
564 if (Reply[i].subtypechar<=msg->Length) {
565 if (msg->Buffer[Reply[i].subtypechar]==Reply[i].subtype)
566 execute=true;
567 }
568 } else execute=true;
569 }
570 } else {
571 if (strncmp(Reply[i].msgtype,msg->Buffer,strlen(Reply[i].msgtype))==0) {
572 execute=true;
573 }
574 }
575
576 if (execute) {
577 *reply=i;
578 if (Reply[i].requestID == ID_IncomingFrame ||
579 Reply[i].requestID == Data->RequestID ||
580 Data->RequestID== ID_EachFrame) {
581 return ERR_NONE;
582 }
583 available=true;
584 }
585 i++;
586 }
587
588 if (available) {
589 return ERR_FRAMENOTREQUESTED;
590 } else {
591 return ERR_UNKNOWNFRAME;
592 }
593}
594
595GSM_Error GSM_DispatchMessage(GSM_StateMachine *s)
596{
597 GSM_Error error= ERR_UNKNOWNFRAME;
598 GSM_Protocol_Message *msg = s->Phone.Data.RequestMsg;
599 GSM_Phone_Data *Phone= &s->Phone.Data;
600 bool disp = false;
601 GSM_Reply_Function*Reply;
602 int reply, i;
603
604 if (s->di.dl==DL_TEXT || s->di.dl==DL_TEXTALL ||
605 s->di.dl==DL_TEXTDATE || s->di.dl==DL_TEXTALLDATE) {
606 smprintf(s, "RECEIVED frame ");
607 smprintf(s, "type 0x%02X/length 0x%02X/%i", msg->Type, msg->Length, msg->Length);
608 DumpMessage(s->di.use_global ? di.df : s->di.df, s->di.dl, msg->Buffer, msg->Length);
609 if (msg->Length == 0) smprintf(s, "\n");
610 fflush(s->di.df);
611 }
612 if (s->di.dl==DL_BINARY) {
613 smprintf(s,"%c",0x02);/* Receiving */
614 smprintf(s,"%c",msg->Type);
615 smprintf(s,"%c",msg->Length/256);
616 smprintf(s,"%c",msg->Length%256);
617 for (i=0;i<msg->Length;i++) {
618 smprintf(s,"%c",msg->Buffer[i]);
619 }
620 }
621
622 Reply=s->User.UserReplyFunctions;
623 if (Reply!=NULL) error=CheckReplyFunctions(s,Reply,&reply);
624
625 if (error==ERR_UNKNOWNFRAME) {
626 Reply=s->Phone.Functions->ReplyFunctions;
627 error=CheckReplyFunctions(s,Reply,&reply);
628 }
629
630 if (error==ERR_NONE) {
631 error=Reply[reply].Function(*msg, s);
632 if (Reply[reply].requestID==Phone->RequestID) {
633 if (error == ERR_NEEDANOTHERANSWER) {
634 error = ERR_NONE;
635 } else {
636 Phone->RequestID=ID_None;
637 }
638 }
639 }
640
641 if (strcmp(s->Phone.Functions->models,"NAUTO")) {
642 if (s->di.dl==DL_TEXT || s->di.dl==DL_TEXTALL || s->di.dl==DL_TEXTERROR ||
643 s->di.dl==DL_TEXTDATE || s->di.dl==DL_TEXTALLDATE || s->di.dl==DL_TEXTERRORDATE) {
644 disp = true;
645 switch (error) {
646 case ERR_UNKNOWNRESPONSE:
647 smprintf(s, "\nUNKNOWN response");
648 break;
649 case ERR_UNKNOWNFRAME:
650 smprintf(s, "\nUNKNOWN frame");
651 break;
652 case ERR_FRAMENOTREQUESTED:
653 smprintf(s, "\nFrame not request now");
654 break;
655 default:
656 disp = false;
657 }
658 }
659
660 if (error == ERR_UNKNOWNFRAME || error == ERR_FRAMENOTREQUESTED) {
661 error = ERR_TIMEOUT;
662 }
663 }
664
665 if (disp) {
666 smprintf(s,". If you can, PLEASE report it (see readme.txt). THANK YOU\n");
667 if (Phone->SentMsg != NULL) {
668 smprintf(s,"LAST SENT frame ");
669 smprintf(s, "type 0x%02X/length %i", Phone->SentMsg->Type, Phone->SentMsg->Length);
670 DumpMessage(s->di.use_global ? di.df : s->di.df, s->di.dl, Phone->SentMsg->Buffer, Phone->SentMsg->Length);
671 }
672 smprintf(s, "RECEIVED frame ");
673 smprintf(s, "type 0x%02X/length 0x%02X/%i", msg->Type, msg->Length, msg->Length);
674 DumpMessage(s->di.use_global ? di.df : s->di.df, s->di.dl, msg->Buffer, msg->Length);
675 smprintf(s, "\n");
676 }
677
678 return error;
679}
680
681INI_Section *GSM_FindGammuRC(void)
682{
683 INI_Section*ini_file;
684 char *HomeDrive,*HomePath,*FileName=malloc(1);
685 int FileNameUsed=1;
686
687 FileName[0] = 0;
688#if defined(WIN32) || defined(DJGPP)
689 HomeDrive = getenv("HOMEDRIVE");
690 if (HomeDrive) {
691 FileName = realloc(FileName,FileNameUsed+strlen(HomeDrive)+1);
692 FileName = strcat(FileName, HomeDrive);
693 FileNameUsed+= strlen(HomeDrive)+1;
694 }
695 HomePath = getenv("HOMEPATH");
696 if (HomePath) {
697 FileName = realloc(FileName,FileNameUsed+strlen(HomePath)+1);
698 FileName = strcat(FileName, HomePath);
699 FileNameUsed+= strlen(HomePath)+1;
700 }
701 FileName = realloc(FileName,FileNameUsed+8+1);
702 strcat(FileName, "\\gammurc");
703#else
704 HomeDrive = NULL;
705 HomePath = getenv("HOME");
706 if (HomePath) {
707 FileName = realloc(FileName,FileNameUsed+strlen(HomePath)+1);
708 FileName = strcat(FileName, HomePath);
709 FileNameUsed+= strlen(HomePath)+1;
710 }
711 FileName = realloc(FileName,FileNameUsed+9+1);
712 strcat(FileName, "/.gammurc");
713#endif
714 //dbgprintf("\"%s\"\n",FileName);
715
716 ini_file = INI_ReadFile(FileName, false);
717 free(FileName);
718 if (ini_file == NULL) {
719#if defined(WIN32) || defined(DJGPP)
720 ini_file = INI_ReadFile("gammurc", false);
721 if (ini_file == NULL) return NULL;
722#else
723 ini_file = INI_ReadFile("/etc/gammurc", false);
724 if (ini_file == NULL) return NULL;
725#endif
726 }
727
728 return ini_file;
729}
730
731bool GSM_ReadConfig(INI_Section *cfg_info, GSM_Config *cfg, int num)
732{
733 INI_Section *h;
734 unsigned char section[50];
735 bool found = false;
736
737#if defined(WIN32) || defined(DJGPP)
738 char *DefaultPort = "com2:";
739#else
740 char *DefaultPort = "/dev/ttyS1";
741#endif
742 char *DefaultModel = "";
743 char *DefaultConnection = "fbus";
744 char *DefaultSynchronizeTime= "no";
745 char *DefaultDebugFile = "";
746 char *DefaultDebugLevel = "";
747 char *DefaultLockDevice = "no";
748 char *DefaultStartInfo = "no";
749 char *Temp;
750
751 /* By default all debug output will go to one filedescriptor */
752 bool DefaultUseGlobalDebugFile = true;
753
754 cfg->Device = DefaultPort;
755 cfg->Connection = DefaultConnection;
756 cfg->SyncTime = DefaultSynchronizeTime;
757 cfg->DebugFile = DefaultDebugFile;
758 strcpy(cfg->Model,DefaultModel);
759 strcpy(cfg->DebugLevel,DefaultDebugLevel);
760 cfg->LockDevice = DefaultLockDevice;
761 cfg->StartInfo = DefaultStartInfo;
762 cfg->DefaultDevice = true;
763 cfg->DefaultModel = true;
764 cfg->DefaultConnection = true;
765 cfg->DefaultSyncTime = true;
766 cfg->DefaultDebugFile = true;
767 cfg->DefaultDebugLevel = true;
768 cfg->DefaultLockDevice = true;
769 cfg->DefaultStartInfo = true;
770
771 cfg->UseGlobalDebugFile = DefaultUseGlobalDebugFile;
772
773 if (cfg_info==NULL) return false;
774
775 if (num == 0) {
776 sprintf(section,"gammu");
777 } else {
778 sprintf(section,"gammu%i",num);
779 }
780 for (h = cfg_info; h != NULL; h = h->Next) {
781 if (mystrncasecmp(section, h->SectionName, strlen(section))) {
782 found = true;
783 break;
784 }
785 }
786 if (!found) return false;
787
788 cfg->Device = INI_GetValue(cfg_info, section, "port", false);
789 if (!cfg->Device) {
790 free(cfg->Device);
791 cfg->Device = strdup(DefaultPort);
792 } else {
793 cfg->DefaultDevice = false;
794 }
795 cfg->Connection = INI_GetValue(cfg_info, section, "connection", false);
796 if (!cfg->Connection) {
797 free(cfg->Connection);
798 cfg->Connection = strdup(DefaultConnection);
799 } else {
800 cfg->DefaultConnection = false;
801 }
802 cfg->SyncTime = INI_GetValue(cfg_info, section, "synchronizetime",false);
803 if (!cfg->SyncTime) {
804 free(cfg->SyncTime);
805 cfg->SyncTime = strdup(DefaultSynchronizeTime);
806 } else {
807 cfg->DefaultSyncTime = false;
808 }
809 cfg->DebugFile = INI_GetValue(cfg_info, section, "logfile", false);
810 if (!cfg->DebugFile) {
811 free(cfg->DebugFile);
812 cfg->DebugFile = strdup(DefaultDebugFile);
813 } else {
814 cfg->DefaultDebugFile = false;
815 }
816 cfg->LockDevice = INI_GetValue(cfg_info, section, "use_locking", false);
817 if (!cfg->LockDevice) {
818 free(cfg->LockDevice);
819 cfg->LockDevice = strdup(DefaultLockDevice);
820 } else {
821 cfg->DefaultLockDevice = false;
822 }
823 Temp = INI_GetValue(cfg_info, section, "model", false);
824 if (!Temp) {
825 strcpy(cfg->Model,DefaultModel);
826 } else {
827 cfg->DefaultModel = false;
828 strcpy(cfg->Model,Temp);
829 }
830 Temp = INI_GetValue(cfg_info, section, "logformat", false);
831 if (!Temp) {
832 strcpy(cfg->DebugLevel,DefaultDebugLevel);
833 } else {
834 cfg->DefaultDebugLevel = false;
835 strcpy(cfg->DebugLevel,Temp);
836 }
837 cfg->StartInfo = INI_GetValue(cfg_info, section, "startinfo", false);
838 if (!cfg->StartInfo) {
839 free(cfg->StartInfo);
840 cfg->StartInfo = strdup(DefaultStartInfo);
841 } else {
842 cfg->DefaultStartInfo = false;
843 }
844 return true;
845}
846
847static OnePhoneModel allmodels[] = {
848#ifdef GSM_ENABLE_NOKIA6510
849 {"1100", "RH-18" ,"", {0}},
850 {"1100a","RH-38" ,"", {0}},
851 {"1100b","RH-36" ,"", {0}},
852#endif
853#ifdef GSM_ENABLE_NOKIA6110
854 {"2100" ,"NAM-2" ,"", {F_NOWAP,F_NOCALLER,F_RING_SM,F_CAL33,F_POWER_BATT,F_PROFILES33,F_NOCALLINFO,F_NODTMF,0}},//quess
855#endif
856#ifdef GSM_ENABLE_NOKIA6510
857 {"3100" ,"RH-19" ,"", {F_PBKTONEGAL,F_PBKSMSLIST,0}},
858 {"3100b","RH-50" ,"", {F_PBKTONEGAL,F_PBKSMSLIST,0}},
859 {"3108", "RH-6", "Nokia 3108",{0}}, //does it have irda ?
860 {"3200", "RH-30" ,"Nokia 3200",{F_PBKTONEGAL,0}},
861 {"3200a","RH-31" ,"Nokia 3200",{F_PBKTONEGAL,0}},
862#endif
863#ifdef GSM_ENABLE_NOKIA6110
864 {"3210" ,"NSE-8" ,"", {F_NOWAP,F_NOCALLER,F_NOCALENDAR,F_NOPBKUNICODE,F_POWER_BATT,F_PROFILES51,F_NOPICTUREUNI,F_NOCALLINFO,F_NODTMF,0}},
865 {"3210" ,"NSE-9" ,"", {F_NOWAP,F_NOCALLER,F_NOCALENDAR,F_NOPBKUNICODE,F_POWER_BATT,F_PROFILES51,F_NOPICTUREUNI,F_NOCALLINFO,F_NODTMF,0}},
866#endif
867#ifdef GSM_ENABLE_NOKIA6510
868 {"3300" ,"NEM-1" ,"Nokia 3300", {F_PBKTONEGAL,0}},
869 {"3300" ,"NEM-2" ,"Nokia 3300", {F_PBKTONEGAL,0}},
870#endif
871#ifdef GSM_ENABLE_NOKIA6110
872 {"3310" ,"NHM-5" ,"", {F_NOWAP,F_NOCALLER,F_RING_SM,F_CAL33,F_POWER_BATT,F_PROFILES33,F_NOCALLINFO,F_NODTMF,0}},
873#endif
874#ifdef GSM_ENABLE_NOKIA3320
875 {"3320" ,"NPC-1" ,"Nokia 3320", {F_CAL62,F_DAYMONTH,0}},//fixme
876#endif
877#ifdef GSM_ENABLE_NOKIA6110
878 {"3330" ,"NHM-6" ,"", {F_NOCALLER,F_RING_SM,F_CAL33,F_PROFILES33,F_NOPICTUREUNI,F_NOCALLINFO,F_NODTMF,0}},
879 {"3390" ,"NPB-1" ,"", {F_NOWAP,F_NOCALLER,F_RING_SM,F_CAL33,F_PROFILES33,F_NOPICTUREUNI,F_NOCALLINFO,F_NODTMF,0}},
880 {"3410" ,"NHM-2" ,"", {F_RING_SM,F_CAL33,F_PROFILES33,F_NOCALLINFO,F_NODTMF,0}},
881#endif
882#ifdef GSM_ENABLE_NOKIA6510
883 {"3510" ,"NHM-8" ,"", {F_CAL35,F_PBK35,F_NOGPRSPOINT,F_VOICETAGS,0}},
884 {"3510i","RH-9" ,"", {F_CAL35,F_PBK35,F_NOGPRSPOINT,F_VOICETAGS,0}},
885 {"3530" ,"RH-9" ,"", {F_CAL35,F_PBK35,F_NOGPRSPOINT,F_VOICETAGS,0}},
886 {"3589i","RH-44" ,"", {F_VOICETAGS,0}},
887 {"3590" ,"NPM-8" ,"", {0}},//irda?
888 {"3595" ,"NPM-10" ,"", {0}},//irda?
889#endif
890#ifdef GSM_ENABLE_NOKIA6110
891 {"3610" ,"NAM-1" ,"", {F_NOCALLER,F_RING_SM,F_CAL33,F_POWER_BATT,F_PROFILES33,F_NOCALLINFO,F_NODTMF,0}},//quess
892#endif
893#if defined(GSM_ENABLE_ATGEN) || defined(GSM_ENABLE_NOKIA3650)
894 {"3650" ,"NHL-8" ,"Nokia 3650", {0}},
895 {"NGAGE","NEM-4" ,"", {F_RADIO,0}},
896#endif
897#if defined(GSM_ENABLE_ATGEN) || defined(GSM_ENABLE_NOKIA6510)
898 {"5100" ,"NPM-6" ,"Nokia 5100", {F_PBKTONEGAL,F_TODO66,F_RADIO,0}},
899 {"5100" ,"NPM-6U","Nokia 5100", {F_PBKTONEGAL,F_TODO66,F_RADIO,0}},
900 {"5100" ,"NPM-6X","Nokia 5100", {F_PBKTONEGAL,F_TODO66,F_RADIO,0}},
901#endif
902#ifdef GSM_ENABLE_NOKIA6110
903 {"5110" ,"NSE-1" ,"", {F_NOWAP,F_NOCALLER,F_NORING,F_NOPICTURE,F_NOSTARTUP,F_NOCALENDAR,F_NOPBKUNICODE,F_PROFILES51,F_MAGICBYTES,F_DISPSTATUS,0}},
904 {"5110i","NSE-2" ,"", {F_NOWAP,F_NOCALLER,F_NORING,F_NOPICTURE,F_NOSTARTUP,F_NOCALENDAR,F_NOPBKUNICODE,F_PROFILES51,F_MAGICBYTES,F_DISPSTATUS,0}},
905 {"5130" ,"NSK-1" ,"", {F_NOWAP,F_NOCALLER,F_NORING,F_NOPICTURE,F_NOSTARTUP,F_NOCALENDAR,F_NOPBKUNICODE,F_PROFILES51,F_MAGICBYTES,F_DISPSTATUS,0}},
906 {"5190" ,"NSB-1" ,"", {F_NOWAP,F_NOCALLER,F_NORING,F_NOPICTURE,F_NOSTARTUP,F_NOCALENDAR,F_NOPBKUNICODE,F_PROFILES51,F_MAGICBYTES,F_DISPSTATUS,0}},
907#endif
908#if defined(GSM_ENABLE_ATGEN) || defined(GSM_ENABLE_NOKIA6110)
909 {"5210" ,"NSM-5" ,"Nokia 5210", {F_CAL52,F_NOSTARTANI,F_NOPICTUREUNI,F_NODTMF,0}},
910#endif
911#ifdef GSM_ENABLE_NOKIA6110
912 {"5510" ,"NPM-5" ,"", {F_NOCALLER,F_PROFILES33,F_NOPICTUREUNI,0}},
913#endif
914#if defined(GSM_ENABLE_ATGEN) || defined(GSM_ENABLE_NOKIA6510)
915 {"6100" ,"NPL-2" ,"Nokia 6100", {F_PBKTONEGAL,F_TODO66,0}},
916#endif
917#ifdef GSM_ENABLE_NOKIA6110
918 {"6110" ,"NSE-3" ,"", {F_NOWAP,F_NOPICTURE,F_NOSTARTANI,F_NOPBKUNICODE,F_MAGICBYTES,F_DISPSTATUS,0}},
919 {"6130" ,"NSK-3" ,"", {F_NOWAP,F_NOPICTURE,F_NOSTARTANI,F_NOPBKUNICODE,F_MAGICBYTES,F_DISPSTATUS,0}},
920 {"6150" ,"NSM-1" ,"", {F_NOWAP,F_NOSTARTANI,F_NOPBKUNICODE,F_MAGICBYTES,F_DISPSTATUS,F_NOPICTUREUNI,0}},
921 {"6190" ,"NSB-3" ,"", {F_NOWAP,F_NOPICTURE,F_NOSTARTANI,F_NOPBKUNICODE,F_MAGICBYTES,F_DISPSTATUS,0}},
922#endif
923#if defined(GSM_ENABLE_ATGEN) || defined(GSM_ENABLE_NOKIA6510)
924 {"6200" ,"NPL-3" ,"Nokia 6200", {F_PBKTONEGAL,0}},
925 {"6220" ,"RH-20" ,"Nokia 6220", {F_PBKTONEGAL,F_TODO66,F_RADIO,F_PBKSMSLIST,F_PBKUSER,F_WAPMMSPROXY,0}},
926#endif
927#if defined(GSM_ENABLE_ATGEN) || defined(GSM_ENABLE_NOKIA7110)
928 {"6210" ,"NPE-3" ,"Nokia 6210", {F_VOICETAGS,F_CAL62,0}},
929 {"6250" ,"NHM-3" ,"Nokia 6250", {F_VOICETAGS,F_CAL62,0}},
930#endif
931#if defined(GSM_ENABLE_ATGEN) || defined(GSM_ENABLE_NOKIA6510)
932 {"6230" ,"RH-12" ,"Nokia 6230", {F_PBKTONEGAL,F_TODO66,F_RADIO,F_PBKSMSLIST,F_PBKUSER,0}},
933 {"6310" ,"NPE-4" ,"Nokia 6310", {F_TODO63,F_CAL65,F_NOMIDI,F_NOMMS,F_VOICETAGS,0}},
934 {"6310i","NPL-1" ,"Nokia 6310i",{F_TODO63,F_CAL65,F_NOMIDI,F_BLUETOOTH,F_NOMMS,F_VOICETAGS,0}},
935 {"6385" ,"NHP-2AX","Nokia 6385",{F_TODO63,F_CAL65,F_NOMIDI,F_NOMMS,F_VOICETAGS,0}},
936 {"6510" ,"NPM-9" ,"Nokia 6510", {F_TODO63,F_CAL65,F_NOMIDI,F_RADIO,F_NOFILESYSTEM,F_NOMMS,F_VOICETAGS,0}},
937 {"6610" ,"NHL-4U","Nokia 6610", {F_PBKTONEGAL,F_TODO66,F_RADIO,0}},
938 {"6800" ,"NSB-9" ,"Nokia 6800", {F_PBKTONEGAL,F_TODO66,F_RADIO,F_PBKSMSLIST,0}},
939 {"6800" ,"NHL-6" ,"Nokia 6800", {F_PBKTONEGAL,F_TODO66,F_RADIO,F_PBKSMSLIST,0}},
940#endif
941#if defined(GSM_ENABLE_ATGEN) || defined(GSM_ENABLE_NOKIA7110)
942 {"7110" ,"NSE-5" ,"Nokia 7110", {F_CAL62,0}},
943 {"7190" ,"NSB-5" ,"Nokia 7190", {F_CAL62,0}},
944#endif
945#if defined(GSM_ENABLE_ATGEN) || defined(GSM_ENABLE_NOKIA6510)
946 {"7210" ,"NHL-4" ,"Nokia 7210", {F_PBKTONEGAL,F_TODO66,F_RADIO,0}},
947 {"7250" ,"NHL-4J","Nokia 7250", {F_PBKTONEGAL,F_TODO66,F_RADIO,F_PBKIMG,0}},
948 {"7250i","NHL-4JX","Nokia 7250i",{F_PBKTONEGAL,F_TODO66,F_RADIO,F_PBKIMG,0}},
949 {"7600", "NMM-3", "Nokia 7600", {F_TODO66,0}},
950#endif
951#if defined(GSM_ENABLE_ATGEN)
952 {"7650" ,"NHL-2" ,"Nokia 7650", {0}},
953#endif
954#if defined(GSM_ENABLE_ATGEN) || defined(GSM_ENABLE_NOKIA6110)
955 {"8210" ,"NSM-3" ,"Nokia 8210", {F_NOWAP,F_NOSTARTANI,F_NOPBKUNICODE,F_NOPICTUREUNI,0}},
956 {"8250" ,"NSM-3D","Nokia 8250", {F_NOWAP,F_NOSTARTANI,F_CAL82,F_NOPICTUREUNI,0}},
957 {"8290" ,"NSB-7" ,"Nokia 8290", {F_NOWAP,F_NOSTARTANI,F_NOPBKUNICODE,F_NOPICTUREUNI,0}},
958#endif
959#if defined(GSM_ENABLE_ATGEN) || defined(GSM_ENABLE_NOKIA6510)
960 {"8310" ,"NHM-7" ,"Nokia 8310", {F_CAL62,F_NOMIDI,F_RADIO,F_NOFILESYSTEM,F_NOMMS,F_VOICETAGS,0}},
961 {"8390" ,"NSB-8" ,"Nokia 8390", {F_CAL62,F_NOMIDI,F_RADIO,F_NOFILESYSTEM,F_NOMMS,F_VOICETAGS,0}},
962#endif
963#if defined(GSM_ENABLE_ATGEN) || defined(GSM_ENABLE_NOKIA6110)
964 {"8850" ,"NSM-2" ,"Nokia 8850", {0}},
965 {"8855" ,"NSM-4" ,"Nokia 8855", {0}},
966 {"8890" ,"NSB-6" ,"Nokia 8890", {0}},
967#endif
968#if defined(GSM_ENABLE_ATGEN) || defined(GSM_ENABLE_NOKIA6510)
969 {"8910" ,"NHM-4" ,"Nokia 8910", {F_CAL62,F_NOMIDI,F_NOFILESYSTEM,F_NOMMS,0}},
970 {"8910i","NHM-4" ,"Nokia 8910i",{F_CAL62,F_NOMIDI,F_NOFILESYSTEM,F_NOMMS,0}},
971#endif
972#ifdef GSM_ENABLE_NOKIA9210
973 {"9210" ,"RAE-3" ,"", {0}},
974 {"9210i","RAE-5" ,"", {0}},
975#endif
976#ifdef GSM_ENABLE_ATGEN
977 {"at" , "at", "", {0}},
978 {"M20" , "M20", "", {F_M20SMS,F_SLOWWRITE,0}},
979 {"MC35" , "MC35", "", {0}},
980 {"S25", "S25", "SIEMENS S25", {0}},
981 {"C35i" , "C35i", "", {0}},
982 {"S35i" , "S35i", "", {0}},
983 {"M35i" , "M35i", "", {0}},
984 {"S40" , "Siemens S40", "", {0}},
985 {"C45" , "C45", "", {0}},
986 {"S45" , "S45", "", {0}},
987 {"ME45" , "ME45", "", {0}},
988 {"SL45" , "SL45", "", {0}},
989 {"SL45i" , "SL45i", "", {0}},
990 {"M50" , "M50", "", {0}},
991 {"S45" , "6618" , "", {0}},
992 {"ME45" , "3618" , "", {0}},
993 {"S55" , "S55" , "", {0}},
994 {"T28s", "1101101-BVT28s","", {0}},
995 {"R320s" , "1101201-BV R320s","", {0}},
996 {"R380s", "7100101-BVR380s" ,"", {0}},
997 {"R520m", "1130101-BVR520m" ,"", {0}},
998 {"T39m", "1130102-BVT39m" ,"", {0}},
999 {"T65", "1101901-BVT65" , "", {0}},
1000 {"T68", "1130201-BVT68" , "", {0}},
1001 {"T68i", "1130202-BVT68" , "", {0}},
1002 {"R600", "102001-BVR600" , "", {0}},
1003 {"T200", "1130501-BVT200" ,"", {0}},
1004 {"T300", "1130601-BVT300" ,"T300", {0}},
1005 {"T310", "1130602-BVT310" ,"", {0}},
1006 {"P800", "7130501-BVP800" ,"", {0}},
1007 {"iPAQ" , "iPAQ" , "" , {0}},
1008 {"A2D" , "A2D" , "" , {0}},
1009 {"9210" , "RAE-3", "Nokia Communicator GSM900/1800",{0}},
1010 {"myV-65", "myV-65 GPRS", "", {F_SMSME900,0}},
1011#endif
1012#if defined(GSM_ENABLE_ATGEN) || defined(GSM_ENABLE_ALCATEL)
1013 {"BE5", "ONE TOUCH 500","", {F_ALCATEL,F_SMSONLYSENT,F_BROKENCPBS,0}},
1014 {"BH4", "ONE TOUCH 535","ALCATEL OT535", {F_ALCATEL,F_SMSONLYSENT,0}},
1015 {"BF5", "ONE TOUCH 715","ALCATEL OT715", {F_ALCATEL,F_SMSONLYSENT,F_BROKENCPBS,0}},
1016#endif
1017 {"unknown", "" ,"", {0}}
1018};
1019
1020OnePhoneModel *GetModelData(char *model, char *number, char *irdamodel)
1021{
1022 int i = 0;
1023
1024 while (strcmp(allmodels[i].number,"") != 0) {
1025 if (model !=NULL) {
1026 if (strcmp (model, allmodels[i].model) == 0) {
1027 return (&allmodels[i]);
1028 }
1029 }
1030 if (number !=NULL) {
1031 if (strcmp (number, allmodels[i].number) == 0) {
1032 return (&allmodels[i]);
1033 }
1034 }
1035 if (irdamodel !=NULL) {
1036 if (strcmp (irdamodel, allmodels[i].irdamodel) == 0) {
1037 return (&allmodels[i]);
1038 }
1039 }
1040 i++;
1041 }
1042 return (&allmodels[i]);
1043}
1044
1045bool IsPhoneFeatureAvailable(OnePhoneModel *model, Feature feature)
1046{
1047 int i= 0;
1048 boolretval = false;
1049
1050 while (model->features[i] != 0) {
1051 if (model->features[i] == feature) {
1052 retval = true;
1053 break;
1054 }
1055 i++;
1056 }
1057 return retval;
1058}
1059
1060void GSM_DumpMessageLevel2(GSM_StateMachine *s, unsigned char *message, int messagesize, int type)
1061{
1062 if (s->di.dl==DL_TEXT || s->di.dl==DL_TEXTALL ||
1063 s->di.dl==DL_TEXTDATE || s->di.dl==DL_TEXTALLDATE) {
1064 smprintf(s,"SENDING frame ");
1065 smprintf(s,"type 0x%02X/length 0x%02X/%i", type, messagesize, messagesize);
1066 DumpMessage(s->di.use_global ? di.df : s->di.df, s->di.dl, message, messagesize);
1067 if (messagesize == 0) smprintf(s,"\n");
1068 if (s->di.df) fflush(s->di.df);
1069 }
1070}
1071
1072void GSM_DumpMessageLevel3(GSM_StateMachine *s, unsigned char *message, int messagesize, int type)
1073{
1074 int i;
1075
1076 if (s->di.dl==DL_BINARY) {
1077 smprintf(s,"%c",0x01);/* Sending */
1078 smprintf(s,"%c",type);
1079 smprintf(s,"%c",messagesize/256);
1080 smprintf(s,"%c",messagesize%256);
1081 for (i=0;i<messagesize;i++) smprintf(s,"%c",message[i]);
1082 }
1083}
1084
1085#ifdef __GNUC__
1086__attribute__((format(printf, 2, 3)))
1087#endif
1088int smprintf(GSM_StateMachine *s, const char *format, ...)
1089{
1090 va_list argp;
1091 int result=0;
1092 unsigned charbuffer[2000];
1093 Debug_Leveldl;
1094 FILE *df;
1095
1096 va_start(argp, format);
1097 if (s == NULL) {
1098 dl = di.dl;
1099 df = di.df;
1100 } else {
1101 dl = s->di.dl;
1102 if (s->di.use_global) {
1103 df = di.df;
1104 } else {
1105 df = s->di.df;
1106 }
1107 }
1108
1109 if (dl != 0) {
1110 result = vsprintf(buffer, format, argp);
1111 result = smfprintf(df, dl, "%s", buffer);
1112 }
1113
1114 va_end(argp);
1115 return result;
1116}
1117
1118void GSM_OSErrorInfo(GSM_StateMachine *s, char *description)
1119{
1120#ifdef WIN32
1121 int i;
1122 unsigned char *lpMsgBuf;
1123
1124 /* We don't use errno in win32 - GetLastError gives better info */
1125 if (GetLastError()!=-1) {
1126 if (s->di.dl == DL_TEXTERROR || s->di.dl == DL_TEXT || s->di.dl == DL_TEXTALL ||
1127 s->di.dl == DL_TEXTERRORDATE || s->di.dl == DL_TEXTDATE || s->di.dl == DL_TEXTALLDATE) {
1128 FormatMessage(
1129 FORMAT_MESSAGE_ALLOCATE_BUFFER |
1130 FORMAT_MESSAGE_FROM_SYSTEM |
1131 FORMAT_MESSAGE_IGNORE_INSERTS,
1132 NULL,
1133 GetLastError(),
1134 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
1135 (LPTSTR) &lpMsgBuf,
1136 0,
1137 NULL
1138 );
1139 for (i=0;i<(int)strlen(lpMsgBuf);i++) {
1140 if (lpMsgBuf[i] == 13 || lpMsgBuf[i] == 10) {
1141 lpMsgBuf[i] = ' ';
1142 }
1143 }
1144 smprintf(s,"[System error - %s, %i, \"%s\"]\n",description,GetLastError(),(LPCTSTR)lpMsgBuf);
1145 LocalFree(lpMsgBuf);
1146 }
1147 }
1148 return;
1149#endif
1150
1151 if (errno!=-1) {
1152 if (s->di.dl == DL_TEXTERROR || s->di.dl == DL_TEXT || s->di.dl == DL_TEXTALL ||
1153 s->di.dl == DL_TEXTERRORDATE || s->di.dl == DL_TEXTDATE || s->di.dl == DL_TEXTALLDATE) {
1154 smprintf(s,"[System error - %s, %i, \"%s\"]\n",description,errno,strerror(errno));
1155 }
1156 }
1157}
1158
1159#ifdef GSM_ENABLE_BACKUP
1160
1161void GSM_GetPhoneFeaturesForBackup(GSM_StateMachine *s, GSM_Backup_Info *info)
1162{
1163 GSM_Error error;
1164 GSM_MemoryStatusMemStatus;
1165 GSM_ToDoStatus ToDoStatus;
1166 GSM_CalendarEntry Note;
1167 GSM_WAPBookmark Bookmark;
1168 GSM_MultiWAPSettingsWAPSettings;
1169 GSM_FMStation FMStation;
1170 GSM_GPRSAccessPointGPRSPoint;
1171 // GSM_Profile Profile;
1172
1173 if (info->PhonePhonebook) {
1174 MemStatus.MemoryType = MEM_ME;
1175 error=s->Phone.Functions->GetMemoryStatus(s, &MemStatus);
1176 if (error==ERR_NONE && MemStatus.MemoryUsed != 0) {
1177 } else {
1178 info->PhonePhonebook = false;
1179 }
1180 }
1181 if (info->SIMPhonebook) {
1182 MemStatus.MemoryType = MEM_SM;
1183 error=s->Phone.Functions->GetMemoryStatus(s, &MemStatus);
1184 if (error==ERR_NONE && MemStatus.MemoryUsed != 0) {
1185 } else {
1186 info->SIMPhonebook = false;
1187 }
1188 }
1189 if (info->Calendar) {
1190 error=s->Phone.Functions->GetNextCalendar(s,&Note,true);
1191 if (error!=ERR_NONE) info->Calendar = false;
1192 }
1193 if (info->ToDo) {
1194 error=s->Phone.Functions->GetToDoStatus(s,&ToDoStatus);
1195 if (error == ERR_NONE && ToDoStatus.Used != 0) {
1196 } else {
1197 info->ToDo = false;
1198 }
1199 }
1200 if (info->WAPBookmark) {
1201 Bookmark.Location = 1;
1202 error=s->Phone.Functions->GetWAPBookmark(s,&Bookmark);
1203 if (error == ERR_NONE) {
1204 } else {
1205 info->WAPBookmark = false;
1206 }
1207 }
1208 if (info->WAPSettings) {
1209 WAPSettings.Location = 1;
1210 error=s->Phone.Functions->GetWAPSettings(s,&WAPSettings);
1211 if (error == ERR_NONE) {
1212 } else {
1213 info->WAPSettings = false;
1214 }
1215 }
1216 if (info->MMSSettings) {
1217 WAPSettings.Location = 1;
1218 error=s->Phone.Functions->GetMMSSettings(s,&WAPSettings);
1219 if (error == ERR_NONE) {
1220 } else {
1221 info->WAPSettings = false;
1222 }
1223 }
1224 if (info->FMStation) {
1225 FMStation.Location = 1;
1226 error = s->Phone.Functions->GetFMStation(s,&FMStation);
1227 if (error == ERR_NONE || error == ERR_EMPTY) {
1228 } else {
1229 info->FMStation = false;
1230 }
1231 }
1232 if (info->GPRSPoint) {
1233 GPRSPoint.Location = 1;
1234 error = s->Phone.Functions->GetGPRSAccessPoint(s,&GPRSPoint);
1235 if (error == ERR_NONE || error == ERR_EMPTY) {
1236 } else {
1237 info->GPRSPoint = false;
1238 }
1239 }
1240}
1241
1242#endif
1243
1244/* How should editor hadle tabs in this file? Add editor commands here.
1245 * vim: noexpandtab sw=8 ts=8 sts=8:
1246 */