Gammu internals  1.38.0
gsmstate.c
Go to the documentation of this file.
1 /* (c) 2002-2005 by Marcin Wiacek and Michal Cihar */
2 /* Phones ID (c) partially by Walek */
3 
4 #include <stdarg.h>
5 #define _GNU_SOURCE /* For strcasestr */
6 #include <string.h>
7 #include <errno.h>
8 #include <limits.h>
9 
10 #include <gammu-call.h>
11 #include <gammu-settings.h>
12 #include <gammu-unicode.h>
13 #include <gammu-config.h>
14 #include <gammu-misc.h>
15 
16 #include "debug.h"
17 #include "gsmcomon.h"
18 #include "gsmphones.h"
19 #include "gsmstate.h"
20 #include "misc/coding/coding.h"
21 #include "misc/misc.h"
22 #include "device/devfunc.h"
23 
24 #include "../helper/string.h"
25 
26 #if defined(HAVE_GETPWUID) && defined(HAVE_GETUID)
27 #include <sys/types.h>
28 #include <pwd.h>
29 #include <unistd.h>
30 #endif
31 
32 #if defined(WIN32) || defined(DJGPP)
33 /* Needed for SHGFP_TYPE_CURRENT */
34 #ifndef _WIN32_IE
35 #define _WIN32_IE 0x0501
36 #endif
37 #include <shlobj.h>
38 
39 #define FALLBACK_GAMMURC "gammurc"
40 #define GAMMURC_NAME "\\gammurc"
41 #else
42 #define FALLBACK_GAMMURC "/etc/gammurc"
43 #define GAMMURC_NAME "/.gammurc"
44 #endif
45 #define XDG_GAMMURC_NAME "/gammu/config"
46 
47 /* Win32 compatibility */
48 #ifndef PATH_MAX
49 #define PATH_MAX (MAX_PATH)
50 #endif
51 
52 /* Default settings */
53 #if defined(WIN32) || defined(DJGPP)
54 # define DEFAULT_DEVICE "com2:"
55 #else
56 # define DEFAULT_DEVICE "/dev/ttyUSB0"
57 #endif
58 #define DEFAULT_MODEL ""
59 #define DEFAULT_CONNECTION "at"
60 #define DEFAULT_SYNCHRONIZE_TIME FALSE
61 #define DEFAULT_DEBUG_FILE ""
62 #define DEFAULT_DEBUG_LEVEL ""
63 #define DEFAULT_LOCK_DEVICE FALSE
64 #define DEFAULT_START_INFO FALSE
65 
71 {
72  GSM_Debug_Info *curdi;
73 
74  curdi = &GSM_global_debug;
75  if (s != NULL && s->di.use_global == FALSE) {
76  curdi = &(s->di);
77  }
78  return curdi;
79 }
80 
81 static void GSM_RegisterConnection(GSM_StateMachine *s, unsigned int connection,
83 {
84  if ((unsigned int)s->ConnectionType == connection) {
85  s->Device.Functions = device;
86  s->Protocol.Functions = protocol;
87  }
88 }
89 
93 typedef struct {
97  const char *Name;
107 
112  {"at", GCT_AT, FALSE},
113 
114  /* cables */
115  {"mbus", GCT_MBUS2, FALSE},
116 
117  {"fbus", GCT_FBUS2, FALSE},
118 
119  {"fbususb", GCT_FBUS2USB, FALSE},
120 
121  {"fbuspl2303", GCT_FBUS2PL2303, FALSE},
122 
123  {"dlr3", GCT_FBUS2DLR3, FALSE},
124  {"fbusdlr3", GCT_FBUS2DLR3, FALSE},
125 
126  {"dku5", GCT_DKU5FBUS2, FALSE},
127  {"fbusdku5", GCT_DKU5FBUS2, FALSE},
128  {"dku5fbus", GCT_DKU5FBUS2, FALSE},
129 
130  {"ark3116fbus", GCT_DKU5FBUS2, TRUE},
131 #ifdef WIN32
132  {"dku2", GCT_DKU2PHONET, FALSE},
133  {"dku2phonet", GCT_DKU2PHONET, FALSE},
134 #else
135  {"dku2", GCT_FBUS2USB, FALSE},
136  {"dku2phonet", GCT_FBUS2USB, FALSE},
137 #endif
138  {"dku2at", GCT_DKU2AT, FALSE},
139 
140  /* for serial ports assigned by bt stack */
141  {"fbusblue", GCT_FBUS2BLUE, FALSE},
142  {"phonetblue", GCT_PHONETBLUE, FALSE},
143 
144  /* bt */
145  {"blueobex", GCT_BLUEOBEX, FALSE},
146  {"bluephonet", GCT_BLUEPHONET, FALSE},
147  {"blueat", GCT_BLUEAT, FALSE},
148  {"bluerfobex", GCT_BLUEOBEX, FALSE},
149  {"bluefbus", GCT_BLUEFBUS2, FALSE},
150  {"bluerffbus", GCT_BLUEFBUS2, FALSE},
151  {"bluerfphonet", GCT_BLUEPHONET, FALSE},
152  {"bluerfat", GCT_BLUEAT, FALSE},
153  {"bluerfgnapbus", GCT_BLUEGNAPBUS, FALSE},
154  {"blues60", GCT_BLUES60, FALSE},
155  {"bluerfs60", GCT_BLUES60, FALSE},
156 
157  /* proxy */
158  {"proxyobex", GCT_PROXYOBEX, FALSE},
159  {"proxyphonet", GCT_PROXYPHONET, FALSE},
160  {"proxyat", GCT_PROXYAT, FALSE},
161  {"proxygnapbus", GCT_PROXYGNAPBUS, FALSE},
162  {"proxyfbus", GCT_PROXYFBUS2, FALSE},
163  {"proxys60", GCT_PROXYS60, FALSE},
164 
165  /* old "serial" irda */
166  {"infrared", GCT_FBUS2IRDA, FALSE},
167  {"fbusirda", GCT_FBUS2IRDA, FALSE},
168 
169  /* socket irda */
170  {"irda", GCT_IRDAPHONET, FALSE},
171  {"irdaphonet", GCT_IRDAPHONET, FALSE},
172  {"irdaat", GCT_IRDAAT, FALSE},
173  {"irdaobex", GCT_IRDAOBEX, FALSE},
174  {"irdagnapbus", GCT_IRDAGNAPBUS, FALSE},
175 
176  /* testing purposes */
177  {"none", GCT_NONE, FALSE},
178 };
179 
181  NONEFUNCTION,
182  NONEFUNCTION,
183  NONEFUNCTION,
184  NONEFUNCTION,
185  NONEFUNCTION,
186  NONEFUNCTION,
187  NONEFUNCTION
188 };
189 
191  NONEFUNCTION,
192  NONEFUNCTION,
193  NONEFUNCTION,
194  NONEFUNCTION
195 };
196 
197 static GSM_Error GSM_RegisterAllConnections(GSM_StateMachine *s, const char *connection)
198 {
199  size_t i;
200  char *buff, *nodtr_pos, *nopower_pos;
201 
202  /* Copy connection name, so that we can play with it */
203  buff = strdup(connection);
204  if (buff == NULL) {
205  return ERR_MOREMEMORY;
206  }
207 
208  /* We check here is used connection string type is correct for ANY
209  * OS. If not, we return with error, that string is incorrect at all
210  */
211  s->ConnectionType = 0;
212  s->SkipDtrRts = FALSE;
213  s->NoPowerCable = FALSE;
214 
215  /* Are we asked for connection using stupid cable? */
216  nodtr_pos = strcasestr(buff, "-nodtr");
217  if (nodtr_pos != NULL) {
218  *nodtr_pos = 0;
219  }
220 
221  /* Are we asked for connection using cable which does not
222  * use DTR/RTS as power supply? */
223  nopower_pos = strcasestr(buff, "-nopower");
224  if (nopower_pos != NULL) {
225  *nopower_pos = 0;
226  s->NoPowerCable = TRUE;
227  }
228 
229  /* Compare known connections to what we got */
230  for (i = 0; i < sizeof(GSM_Connections) / sizeof(GSM_Connections[0]); i++) {
231  /* Check connection name */
232  if (strcasecmp(GSM_Connections[i].Name, buff) == 0) {
233  s->ConnectionType = GSM_Connections[i].Connection;
234  s->SkipDtrRts = GSM_Connections[i].SkipDtrRts;
235  break;
236  }
237  }
238 
239  /* If we were forced, set this flag */
240  if (nodtr_pos != NULL) {
241  s->SkipDtrRts = TRUE;
242  }
243 
244  /* Special case - at can contains speed */
245  if (s->ConnectionType == 0 && strncasecmp("at", buff, 2) == 0) {
246  s->Speed = FindSerialSpeed(buff + 2);
247  if (s->Speed != 0) {
248  s->ConnectionType = GCT_AT;
249  }
250  }
251 
252  /* Free allocated memory */
253  free(buff);
254  buff = NULL;
255 
256  if (s->ConnectionType == 0) {
258  }
259 
260  /* We check now if user gave connection type compiled & available
261  * for used OS (if not, we return, that source not available)
262  */
263  s->Device.Functions = NULL;
264  s->Protocol.Functions = NULL;
265  GSM_RegisterConnection(s, GCT_NONE, &NoneDevice, &NoProtocol);
266 #ifdef GSM_ENABLE_MBUS2
267  GSM_RegisterConnection(s, GCT_MBUS2, &SerialDevice, &MBUS2Protocol);
268 #endif
269 #ifdef GSM_ENABLE_FBUS2
270  GSM_RegisterConnection(s, GCT_FBUS2, &SerialDevice, &FBUS2Protocol);
271 #endif
272 #ifdef GSM_ENABLE_FBUS2DLR3
273  GSM_RegisterConnection(s, GCT_FBUS2DLR3, &SerialDevice, &FBUS2Protocol);
274 #endif
275 #ifdef GSM_ENABLE_DKU5FBUS2
276  GSM_RegisterConnection(s, GCT_DKU5FBUS2, &SerialDevice, &FBUS2Protocol);
277 #endif
278 #ifdef GSM_ENABLE_FBUS2PL2303
279  GSM_RegisterConnection(s, GCT_FBUS2PL2303,&SerialDevice, &FBUS2Protocol);
280 #endif
281 #ifdef GSM_ENABLE_FBUS2BLUE
282  GSM_RegisterConnection(s, GCT_FBUS2BLUE, &SerialDevice, &FBUS2Protocol);
283 #endif
284 #ifdef GSM_ENABLE_FBUS2IRDA
285  GSM_RegisterConnection(s, GCT_FBUS2IRDA, &SerialDevice, &FBUS2Protocol);
286 #endif
287 #if defined(GSM_ENABLE_DKU2PHONET) && defined(GSM_ENABLE_USBDEVICE)
288  GSM_RegisterConnection(s, GCT_FBUS2USB, &FBUSUSBDevice, &PHONETProtocol);
289 #endif
290 #ifdef GSM_ENABLE_DKU2PHONET
291  GSM_RegisterConnection(s, GCT_DKU2PHONET, &SerialDevice, &PHONETProtocol);
292 #endif
293 #ifdef GSM_ENABLE_DKU2AT
294  GSM_RegisterConnection(s, GCT_DKU2AT, &SerialDevice, &ATProtocol);
295 #endif
296 #ifdef GSM_ENABLE_AT
297  GSM_RegisterConnection(s, GCT_AT, &SerialDevice, &ATProtocol);
298 #endif
299 #ifdef GSM_ENABLE_PHONETBLUE
300  GSM_RegisterConnection(s, GCT_PHONETBLUE, &SerialDevice, &PHONETProtocol);
301 #endif
302 #ifdef GSM_ENABLE_IRDAGNAPBUS
303  GSM_RegisterConnection(s, GCT_IRDAGNAPBUS,&IrdaDevice, &GNAPBUSProtocol);
304 #endif
305 #ifdef GSM_ENABLE_IRDAPHONET
306  GSM_RegisterConnection(s, GCT_IRDAPHONET, &IrdaDevice, &PHONETProtocol);
307 #endif
308 #ifdef GSM_ENABLE_IRDAAT
309  GSM_RegisterConnection(s, GCT_IRDAAT, &IrdaDevice, &ATProtocol);
310 #endif
311 #ifdef GSM_ENABLE_IRDAOBEX
312  GSM_RegisterConnection(s, GCT_IRDAOBEX, &IrdaDevice, &OBEXProtocol);
313 #endif
314 #ifdef GSM_ENABLE_BLUEGNAPBUS
315  GSM_RegisterConnection(s, GCT_BLUES60, &BlueToothDevice,&S60Protocol);
316 #endif
317 #ifdef GSM_ENABLE_BLUEGNAPBUS
318  GSM_RegisterConnection(s, GCT_BLUEGNAPBUS,&BlueToothDevice,&GNAPBUSProtocol);
319 #endif
320 #ifdef GSM_ENABLE_BLUEFBUS2
321  GSM_RegisterConnection(s, GCT_BLUEFBUS2, &BlueToothDevice,&FBUS2Protocol);
322 #endif
323 #ifdef GSM_ENABLE_BLUEPHONET
324  GSM_RegisterConnection(s, GCT_BLUEPHONET, &BlueToothDevice,&PHONETProtocol);
325 #endif
326 #ifdef GSM_ENABLE_BLUEAT
327  GSM_RegisterConnection(s, GCT_BLUEAT, &BlueToothDevice,&ATProtocol);
328 #endif
329 #ifdef GSM_ENABLE_BLUEOBEX
330  GSM_RegisterConnection(s, GCT_BLUEOBEX, &BlueToothDevice,&OBEXProtocol);
331 #endif
332 #ifdef GSM_ENABLE_PROXY
333 #ifdef GSM_ENABLE_S60
335 #endif
336 #ifdef GSM_ENABLE_BLUEGNAPBUS
338 #endif
339 #ifdef GSM_ENABLE_FBUS2
341 #endif
342 #ifdef GSM_ENABLE_DKU2PHONET
343  GSM_RegisterConnection(s, GCT_PROXYPHONET, &ProxyDevice,&PHONETProtocol);
344 #endif
345 #ifdef GSM_ENABLE_ATGEN
347 #endif
348 #ifdef GSM_ENABLE_OBEXGEN
350 #endif
351 #endif
352  if (s->Device.Functions == NULL || s->Protocol.Functions == NULL) {
353  smprintf(s, "Connection %s is know but was disabled on compile time\n", connection);
354  return ERR_DISABLED;
355  }
356 
357  return ERR_NONE;
358 }
359 
361 {
362  /* Auto model */
363  if (s->CurrentConfig->Model[0] == 0) {
364  if (strstr(phone->models,GetModelData(s, NULL, s->Phone.Data.Model, NULL)->model) != NULL) {
365  smprintf(s,"[Module - \"%s\"]\n",phone->models);
366  s->Phone.Functions = phone;
367  }
368  } else {
369  if (strstr(phone->models,s->CurrentConfig->Model) != NULL) {
370  smprintf(s,"[Module - \"%s\"]\n",phone->models);
371  s->Phone.Functions = phone;
372  }
373  }
374 }
375 
384 {
385  GSM_PhoneModel *model;
386 
387  /* Auto model */
388  if (s->CurrentConfig->Model[0] == 0) {
389  model = GetModelData(s, NULL, s->Phone.Data.Model, NULL);
390 #ifdef GSM_ENABLE_ATGEN
391  /* With ATgen and auto model we can work with unknown models too */
393 #ifdef GSM_ENABLE_ALCATEL
394  /* If phone provides Alcatel specific functions, enable them */
395  if (model->model[0] != 0 && GSM_IsPhoneFeatureAvailable(model, F_ALCATEL)) {
396  smprintf(s,"[Module - \"%s\"]\n",ALCATELPhone.models);
397  s->Phone.Functions = &ALCATELPhone;
398  return ERR_NONE;
399  }
400 #endif
401 #ifdef GSM_ENABLE_ATOBEX
402  /* If phone provides Sony-Ericsson specific functions, enable them */
403  if (model->model[0] != 0 && GSM_IsPhoneFeatureAvailable(model, F_OBEX)) {
404  smprintf(s,"[Module - \"%s\"]\n",ATOBEXPhone.models);
405  s->Phone.Functions = &ATOBEXPhone;
406  return ERR_NONE;
407  }
408 #endif
409  smprintf(s,"[Module - \"%s\"]\n",ATGENPhone.models);
410  s->Phone.Functions = &ATGENPhone;
411  return ERR_NONE;
412  }
413 #endif
414  /* With OBEXgen and auto model we can work with unknown models too */
415 #ifdef GSM_ENABLE_OBEXGEN
417  smprintf(s,"[Module - \"%s\"]\n",OBEXGENPhone.models);
418  s->Phone.Functions = &OBEXGENPhone;
419  return ERR_NONE;
420  }
421 #endif
422 
423 #ifdef GSM_ENABLE_BACKUP
424  if (s->ConnectionType == GCT_NONE) {
425  smprintf(s,"[Module - \"%s\"]\n",DUMMYPhone.models);
426  s->Phone.Functions = &DUMMYPhone;
427  return ERR_NONE;
428  }
429 #endif
430 
431  /* With GNAPgen and auto model we can work with unknown models too */
432 #ifdef GSM_ENABLE_GNAPGEN
434  smprintf(s,"[Module - \"%s\"]\n",GNAPGENPhone.models);
435  s->Phone.Functions = &GNAPGENPhone;
436  return ERR_NONE;
437  }
438 #endif
439 #ifdef GSM_ENABLE_S60
441  smprintf(s,"[Module - \"%s\"]\n",S60Phone.models);
442  s->Phone.Functions = &S60Phone;
443  return ERR_NONE;
444  }
445 #endif
446 
447 #ifdef GSM_ENABLE_NOKIA6510
448  if ( s->ConnectionType == GCT_MBUS2 ||
449  s->ConnectionType == GCT_FBUS2 ||
463  /* Try to detect phone type */
464  if (strcmp(model->model, "unknown") == 0 && model->features[0] == 0) {
465  smprintf(s, "WARNING: phone not known, please report it to authors (see <https://wammu.eu/support/bugs/>). Thank you.\n");
466  if (strncmp(s->Phone.Data.Model, "RM-", 3) == 0) {
467  /* 167 is really a wild guess */
468  if (atoi(s->Phone.Data.Model + 3) > 167) {
469  smprintf(s, "WARNING: Guessed phone as S40/30 compatible (RM series)!\n");
477  }
478  }
479  if (strncmp(s->Phone.Data.Model, "RH-", 3) == 0) {
480  /* 63 is really a wild guess */
481  if (atoi(s->Phone.Data.Model + 3) > 63) {
482  smprintf(s, "WARNING: Guessed phone as S40/30 compatible (RH series)!\n");
489  }
490  }
491  }
492 
493  /* If phone is S40, use 6510 */
495  smprintf(s,"[Module - \"%s\"]\n", N6510Phone.models);
496  s->Phone.Functions = &N6510Phone;
497  return ERR_NONE;
498  }
499  }
500 #endif
501  if (model->model[0] == 0) return ERR_UNKNOWNMODELSTRING;
502  }
503  s->Phone.Functions = NULL;
504 #ifdef GSM_ENABLE_ATGEN
505  /* AT module can have the same models ID to "normal" Nokia modules */
507  GSM_RegisterModule(s,&ATGENPhone);
508  if (s->Phone.Functions != NULL) return ERR_NONE;
509  }
510 #endif
511 #ifdef GSM_ENABLE_BACKUP
513 #endif
514 #ifdef GSM_ENABLE_OBEXGEN
515  GSM_RegisterModule(s,&OBEXGENPhone);
516 #endif
517 #ifdef GSM_ENABLE_GNAPGEN
518  GSM_RegisterModule(s,&GNAPGENPhone);
519 #endif
520 #ifdef GSM_ENABLE_S60
521  GSM_RegisterModule(s,&S60Phone);
522 #endif
523 #ifdef GSM_ENABLE_NOKIA3320
524  GSM_RegisterModule(s,&N3320Phone);
525 #endif
526 #ifdef GSM_ENABLE_NOKIA3650
527  GSM_RegisterModule(s,&N3650Phone);
528 #endif
529 #ifdef GSM_ENABLE_NOKIA650
530  GSM_RegisterModule(s,&N650Phone);
531 #endif
532 #ifdef GSM_ENABLE_NOKIA6110
533  GSM_RegisterModule(s,&N6110Phone);
534 #endif
535 #ifdef GSM_ENABLE_NOKIA6510
536  GSM_RegisterModule(s,&N6510Phone);
537 #endif
538 #ifdef GSM_ENABLE_NOKIA7110
539  GSM_RegisterModule(s,&N7110Phone);
540 #endif
541 #ifdef GSM_ENABLE_NOKIA9210
542  GSM_RegisterModule(s,&N9210Phone);
543 #endif
544 #ifdef GSM_ENABLE_ALCATEL
545  GSM_RegisterModule(s,&ALCATELPhone);
546 #endif
547 #ifdef GSM_ENABLE_ATOBEX
548  GSM_RegisterModule(s,&ATOBEXPhone);
549 #endif
550  if (s->Phone.Functions == NULL) {
551  return ERR_UNKNOWNMODELSTRING;
552  }
553  return ERR_NONE;
554 }
555 
556 
561 {
562  GSM_Error error;
563 
564  if (s->CurrentConfig->LockDevice) {
565  error = lock_device(s, s->CurrentConfig->Device, &(s->LockFile));
566  if (error != ERR_NONE) return error;
567  }
568 
569  /* Irda devices can set now model to some specific and
570  * we don't have to make auto detection later */
571  error=s->Device.Functions->OpenDevice(s);
572  if (error!=ERR_NONE) {
573  if (s->LockFile != NULL)
574  unlock_device(s, &(s->LockFile));
575  return error;
576  }
577 
578  s->opened = TRUE;
579 
580  error=s->Protocol.Functions->Initialise(s);
581  if (error!=ERR_NONE) return error;
582 
583  return ERR_NONE;
584 }
585 
590 {
591  GSM_Error error;
592 
593  smprintf(s, "[Closing]\n");
594 
595  /* Terminate protocol */
596  error = s->Protocol.Functions->Terminate(s);
597  if (error != ERR_NONE) return error;
598 
599  /* Close the device */
600  error = s->Device.Functions->CloseDevice(s);
601  if (error != ERR_NONE) return error;
602 
603  /* Release lock if there was any */
604  if (s->LockFile != NULL) {
605  unlock_device(s, &(s->LockFile));
606  }
607 
608  /* Null all structures in case we will be asked for new initialisation */
609  s->Phone.Data.ModelInfo = NULL;
610  s->Phone.Data.Manufacturer[0] = 0;
611  s->Phone.Data.Model[0] = 0;
612  s->Phone.Data.Version[0] = 0;
613  s->Phone.Data.VerDate[0] = 0;
614  s->Phone.Data.VerNum = 0;
615 
616  return ERR_NONE;
617 }
618 
619 
624 {
625  GSM_Error error;
626 
627  error = GSM_OpenConnection(s);
628  if (error != ERR_NONE) return error;
629 
630  /* If still auto model, try to get model by asking phone for it */
631  if (s->Phone.Data.Model[0]==0) {
632  smprintf(s,"[Module - \"auto\"]\n");
633  switch (s->ConnectionType) {
634 #ifdef GSM_ENABLE_BACKUP
635  case GCT_NONE:
636  s->Phone.Functions = &DUMMYPhone;
637  break;
638 #endif
639 #ifdef GSM_ENABLE_ATGEN
640  case GCT_AT:
641  case GCT_BLUEAT:
642  case GCT_PROXYAT:
643  case GCT_IRDAAT:
644  case GCT_DKU2AT:
645  s->Phone.Functions = &ATGENPhone;
646  break;
647 #endif
648 #ifdef GSM_ENABLE_OBEXGEN
649  case GCT_IRDAOBEX:
650  case GCT_PROXYOBEX:
651  case GCT_BLUEOBEX:
652  s->Phone.Functions = &OBEXGENPhone;
653  break;
654 #endif
655 #ifdef GSM_ENABLE_GNAPGEN
656  case GCT_BLUEGNAPBUS:
657  case GCT_PROXYGNAPBUS:
658  case GCT_IRDAGNAPBUS:
659  s->Phone.Functions = &GNAPGENPhone;
660  break;
661 #endif
662 #ifdef GSM_ENABLE_S60
663  case GCT_BLUES60:
664  case GCT_PROXYS60:
665  s->Phone.Functions = &S60Phone;
666  break;
667 #endif
668 #if defined(GSM_ENABLE_NOKIA_DCT3) || defined(GSM_ENABLE_NOKIA_DCT4)
669  case GCT_MBUS2:
670  case GCT_FBUS2:
671  case GCT_FBUS2USB:
672  case GCT_FBUS2DLR3:
673  case GCT_FBUS2PL2303:
674  case GCT_FBUS2BLUE:
675  case GCT_FBUS2IRDA:
676  case GCT_DKU5FBUS2:
677  case GCT_DKU2PHONET:
678  case GCT_PHONETBLUE:
679  case GCT_IRDAPHONET:
680  case GCT_BLUEFBUS2:
681  case GCT_PROXYFBUS2:
682  case GCT_BLUEPHONET:
683  case GCT_PROXYPHONET:
684  s->Phone.Functions = &NAUTOPhone;
685  break;
686 #endif
687  default:
688  s->Phone.Functions = NULL;
689  }
690  /* Did we find matching phone driver? */
691  if (s->Phone.Functions == NULL) {
692  smprintf(s, "ERROR: Could not find proper module for autodetection!\n");
693  return ERR_UNKNOWN;
694  }
695 
696  /* Initialize the phone driver */
697  error = s->Phone.Functions->Initialise(s);
698  if (error != ERR_NONE) return error;
699 
700  /* Get model name from phone */
701  error = s->Phone.Functions->GetModel(s);
702  if (error != ERR_NONE) return error;
703 
704  /* And terminate it again */
705  error = s->Phone.Functions->Terminate(s);
706  if (error != ERR_NONE) return error;
707  }
708  return ERR_NONE;
709 }
710 
711 GSM_Error GSM_InitConnection_Log(GSM_StateMachine *s, int ReplyNum, GSM_Log_Function log_function, void *user_data)
712 {
713  GSM_Error error;
714  GSM_DateTime current_time;
715  int i;
716 
717  for (i=0;i<s->ConfigNum;i++) {
718  s->CurrentConfig = &s->Config[i];
719 
720  /* Skip non configured sections */
721  if (s->CurrentConfig->Connection == NULL) {
722  smprintf_level(s, D_ERROR, "[Empty section - %d]\n", i);
723  continue;
724  }
725 
726  s->Speed = 0;
727  s->ReplyNum = ReplyNum;
728  s->Phone.Data.ModelInfo = GetModelData(s, "unknown", NULL, NULL);
729  s->Phone.Data.Manufacturer[0] = 0;
730  s->Phone.Data.Model[0] = 0;
731  s->Phone.Data.Version[0] = 0;
732  s->Phone.Data.VerDate[0] = 0;
733  s->Phone.Data.VerNum = 0;
734  s->Phone.Data.StartInfoCounter = 0;
735  s->Phone.Data.SentMsg = NULL;
736 
737  s->Phone.Data.HardwareCache[0] = 0;
738  s->Phone.Data.ProductCodeCache[0] = 0;
743  s->User.UserReplyFunctions = NULL;
744  s->User.IncomingCall = NULL;
745  s->User.IncomingSMS = NULL;
746  s->User.IncomingCB = NULL;
747  s->User.IncomingUSSD = NULL;
748  s->User.SendSMSStatus = NULL;
749  s->LockFile = NULL;
750  s->opened = FALSE;
751  s->Phone.Functions = NULL;
752 
753  s->di = GSM_none_debug;
755  if (!s->di.use_global) {
756  GSM_SetDebugFunction(log_function, user_data, &s->di);
758  error = GSM_SetDebugFile(s->CurrentConfig->DebugFile, &s->di);
759  if (error != ERR_NONE) {
760  GSM_LogError(s, "Init:GSM_SetDebugFile" , error);
761  return error;
762  }
763  }
764 
765  smprintf_level(s, D_ERROR, "[Gammu - %s]\n", GAMMU_VERSION);
769  smprintf_level(s, D_ERROR, "[Connection - \"%s\"]\n",
771  smprintf_level(s, D_ERROR, "[Connection index - %d]\n", i);
772  smprintf_level(s, D_ERROR, "[Model type - \"%s\"]\n",
773  s->CurrentConfig->Model);
774  smprintf_level(s, D_ERROR, "[Device - \"%s\"]\n",
775  s->CurrentConfig->Device);
776  if (strlen(GetOS()) != 0) {
777  smprintf_level(s, D_ERROR, "[Running on - %s]\n",
778  GetOS());
779  }
780 
781  if (GSM_GetDI(s)->dl == DL_BINARY) {
782  smprintf(s,"%c",((unsigned char)strlen(GAMMU_VERSION)));
783  smprintf(s,"%s",GAMMU_VERSION);
784  }
785 
787  if (error != ERR_NONE) {
788  GSM_LogError(s, "Init:GSM_RegisterAllConnections" , error);
789  return error;
790  }
791 
792 autodetect:
793  /* Model auto */
794  /* Try to guess correct driver based on model */
795  if (s->CurrentConfig->Model[0] == 0 &&
796  s->ConnectionType != GCT_NONE &&
804  s->ConnectionType != GCT_BLUES60) {
805  error = GSM_TryGetModel(s);
806  /* Fall back to other configuraitons if the device is not existing (or similar error) */
807  if ((i != s->ConfigNum - 1) && (
808  (error == ERR_DEVICEOPENERROR) ||
809  (error == ERR_DEVICELOCKED) ||
810  (error == ERR_DEVICENOTEXIST) ||
811  (error == ERR_DEVICEBUSY) ||
812  (error == ERR_DEVICENOPERMISSION) ||
813  (error == ERR_DEVICENODRIVER) ||
814  (error == ERR_DEVICENOTWORK))) {
816  continue;
817  }
818  if (error != ERR_NONE) {
819  GSM_LogError(s, "Init:GSM_TryGetModel" , error);
820  return error;
821  }
822  }
823 
824  /* Switching to "correct" module */
825  error = GSM_RegisterAllPhoneModules(s);
826  /* If user selected soemthing which is not supported, try autodetection */
827  if (s->CurrentConfig->Model[0] != 0 && error == ERR_UNKNOWNMODELSTRING) {
828  smprintf(s, "Configured model %s is not known, retrying with autodetection!\n",
829  s->CurrentConfig->Model);
830  s->CurrentConfig->Model[0] = 0;
831  goto autodetect;
832  }
833  if (error != ERR_NONE) {
834  GSM_LogError(s, "Init:GSM_RegisterAllPhoneModules" , error);
835  return error;
836  }
837 
838  /* We didn't open device earlier ? Make it now */
839  if (!s->opened) {
840  error = GSM_OpenConnection(s);
841  if ((i != s->ConfigNum - 1) && (
842  (error == ERR_DEVICEOPENERROR) ||
843  (error == ERR_DEVICELOCKED) ||
844  (error == ERR_DEVICENOTEXIST) ||
845  (error == ERR_DEVICEBUSY) ||
846  (error == ERR_DEVICENOPERMISSION) ||
847  (error == ERR_DEVICENODRIVER) ||
848  (error == ERR_DEVICENOTWORK))) {
850  continue;
851  }
852  if (error != ERR_NONE) {
853  GSM_LogError(s, "Init:GSM_OpenConnection" , error);
854  return error;
855  }
856  }
857 
858  /* Initialize phone layer */
859  error=s->Phone.Functions->Initialise(s);
860  if (error == ERR_TIMEOUT && i != s->ConfigNum - 1) {
862  continue;
863  }
864  if (error != ERR_NONE) {
865  GSM_LogError(s, "Init:Phone->Initialise" , error);
866  return error;
867  }
868 
869  if (s->CurrentConfig->StartInfo) {
871  s->Phone.Data.StartInfoCounter = 30;
872  }
873 
874  if (s->CurrentConfig->SyncTime) {
875  GSM_GetCurrentDateTime (&current_time);
876  s->Phone.Functions->SetDateTime(s,&current_time);
877  }
878 
879  /* For debug it's good to have firmware and real model version and manufacturer */
880  error=s->Phone.Functions->GetManufacturer(s);
881  if (error == ERR_TIMEOUT && i != s->ConfigNum - 1) {
883  continue;
884  }
885  if (error != ERR_NONE && error != ERR_NOTSUPPORTED) {
886  GSM_LogError(s, "Init:Phone->GetManufacturer" , error);
887  return error;
888  }
889 
890  error=s->Phone.Functions->GetModel(s);
891  if (error != ERR_NONE && error != ERR_NOTSUPPORTED) {
892  GSM_LogError(s, "Init:Phone->GetModel" , error);
893  return error;
894  }
895 
896  error=s->Phone.Functions->GetFirmware(s);
897  if (error != ERR_NONE && error != ERR_NOTSUPPORTED) {
898  GSM_LogError(s, "Init:Phone->GetFirmware" , error);
899  return error;
900  }
901 
902  error=s->Phone.Functions->PostConnect(s);
903  if (error != ERR_NONE && error != ERR_NOTSUPPORTED) {
904  GSM_LogError(s, "Init:Phone->PostConnect" , error);
905  return error;
906  }
907 
908  smprintf(s,"[Connected]\n");
909  return ERR_NONE;
910  }
911  return ERR_UNCONFIGURED;
912 }
913 
915 {
917 }
918 
920 {
921  GSM_DateTime Date;
922  unsigned char buff[65536]={'\0'};
923  int res=0,count=0,i=0;
924 
925  if (!GSM_IsConnected(s)) {
926  return -1;
927  }
928 
929  GSM_GetCurrentDateTime (&Date);
930  i = Date.Second;
931  while (i == Date.Second && !s->Abort) {
932  res = s->Device.Functions->ReadDevice(s, buff, sizeof(buff));
933 
934  if (!waitforreply) {
935  break;
936  }
937  if (res > 0) {
938  break;
939  }
940  usleep(5000);
941  GSM_GetCurrentDateTime(&Date);
942  }
943  for (count = 0; count < res; count++) {
944  s->Protocol.Functions->StateMachine(s, buff[count]);
945  }
946  return res;
947 }
948 
950 {
951  GSM_Error error;
952 
953  if (!s->opened) return ERR_NONE;
954 
955  smprintf(s,"[Terminating]\n");
956 
957  if (s->CurrentConfig->StartInfo) {
959  }
960 
961  if (s->Phone.Functions != NULL) {
962  error=s->Phone.Functions->Terminate(s);
963  if (error!=ERR_NONE) return error;
964  }
965 
966  error = GSM_CloseConnection(s);
967  if (error != ERR_NONE) return error;
968 
969  GSM_SetDebugFileDescriptor(NULL, FALSE, &(s->di));
970 
971  s->opened = FALSE;
972 
973  return ERR_NONE;
974 }
975 
977  return (s != NULL) && s->Phone.Functions != NULL && s->opened;
978 }
979 
981 {
982  s->Abort = TRUE;
983  return ERR_NONE;
984 }
985 
986 GSM_Error GSM_WaitForOnce(GSM_StateMachine *s, unsigned const char *buffer,
987  size_t length, int type, int timeout)
988 {
989  GSM_Phone_Data *Phone = &s->Phone.Data;
990  GSM_Protocol_Message sentmsg;
991  int i = 0;
992 
993  do {
994  if (length != 0) {
995  sentmsg.Length = length;
996  sentmsg.Type = type;
997  sentmsg.Buffer = (unsigned char *)malloc(length);
998  memcpy(sentmsg.Buffer, buffer, length);
999  Phone->SentMsg = &sentmsg;
1000  }
1001 
1002  /* Some data received. Reset timer */
1003  if (GSM_ReadDevice(s, TRUE) > 0) {
1004  i = 0;
1005  } else {
1006  usleep(10000);
1007  }
1008 
1009  if (length != 0) {
1010  free(sentmsg.Buffer);
1011  sentmsg.Buffer = NULL;
1012  Phone->SentMsg = NULL;
1013  }
1014 
1015  if (s->Abort) {
1016  return ERR_ABORTED;
1017  }
1018 
1019  /* Request completed */
1020  if (Phone->RequestID == ID_None) {
1021  return Phone->DispatchError;
1022  }
1023  i++;
1024  } while (i < timeout);
1025 
1026  return ERR_TIMEOUT;
1027 }
1028 
1029 GSM_Error GSM_WaitFor (GSM_StateMachine *s, unsigned const char *buffer,
1030  size_t length, int type, int timeout,
1031  GSM_Phone_RequestID request)
1032 {
1033  GSM_Phone_Data *Phone = &s->Phone.Data;
1034  GSM_Error error;
1035  int reply;
1036 
1037  if (s->CurrentConfig->StartInfo) {
1038  if (Phone->StartInfoCounter > 0) {
1039  Phone->StartInfoCounter--;
1040  if (Phone->StartInfoCounter == 0) {
1042  }
1043  }
1044  }
1045 
1046  Phone->RequestID = request;
1047  Phone->DispatchError = ERR_TIMEOUT;
1048 
1049  for (reply = 0; reply < s->ReplyNum; reply++) {
1050  if (reply != 0) {
1051  smprintf_level(s, D_ERROR, "[Retrying %i type 0x%02X]\n", reply, type);
1052  }
1053  error = s->Protocol.Functions->WriteMessage(s, buffer, length, type);
1054  if (error != ERR_NONE) {
1055  return error;
1056  }
1057 
1058  /* Special case when no reply is expected */
1059  if (request == ID_None) {
1060  return ERR_NONE;
1061  }
1062 
1063  error = GSM_WaitForOnce(s, buffer, length, type, timeout);
1064  if (error != ERR_TIMEOUT) {
1065  return error;
1066  }
1067  }
1068 
1070  smprintf_level(s, D_ERROR, "Performing device reset after timeout!\n");
1071  GSM_Reset(s, FALSE);
1072  }
1073 
1074  return ERR_TIMEOUT;
1075 }
1076 
1078 {
1079  GSM_Phone_Data *Data = &s->Phone.Data;
1081  gboolean execute;
1082  gboolean available = FALSE;
1083  int i = 0;
1084 
1085  while (Reply[i].requestID != ID_None) {
1086  execute = FALSE;
1087  /* Long ID frames like S60 */
1088  if (Reply[i].msgtype[0] == 0 && Reply[i].subtypechar == 0) {
1089  if (Reply[i].subtype == msg->Type) {
1090  execute = TRUE;
1091  }
1092  /* Binary frames like in Nokia */
1093  } else if (strlen(Reply[i].msgtype) < 2) {
1094  if (Reply[i].msgtype[0]==msg->Type) {
1095  if (Reply[i].subtypechar!=0) {
1096  if (Reply[i].subtypechar<=msg->Length) {
1097  if (msg->Buffer[Reply[i].subtypechar]==Reply[i].subtype)
1098  execute=TRUE;
1099  }
1100  } else {
1101  execute=TRUE;
1102  }
1103  }
1104  } else {
1105  if (strlen(Reply[i].msgtype) < msg->Length) {
1106  if (strncmp(Reply[i].msgtype,msg->Buffer,strlen(Reply[i].msgtype))==0) {
1107  execute=TRUE;
1108  }
1109  }
1110  }
1111 
1112  if (execute) {
1113  *reply = i;
1114  if (Reply[i].requestID == ID_IncomingFrame ||
1115  Reply[i].requestID == Data->RequestID ||
1116  Data->RequestID == ID_EachFrame) {
1117  return ERR_NONE;
1118  }
1119  available = TRUE;
1120  }
1121  i++;
1122  }
1123 
1124  if (available) {
1125  return ERR_FRAMENOTREQUESTED;
1126  } else {
1127  return ERR_UNKNOWNFRAME;
1128  }
1129 }
1130 
1132 {
1133  GSM_Error error = ERR_UNKNOWNFRAME;
1135  GSM_Phone_Data *Phone = &s->Phone.Data;
1136  gboolean disp = FALSE;
1137  GSM_Reply_Function *Reply;
1138  int reply;
1139 
1140  s->MessagesCount++;
1141 
1142  GSM_DumpMessageTextRecv(s, msg->Buffer, msg->Length, msg->Type);
1143  GSM_DumpMessageBinaryRecv(s, msg->Buffer, msg->Length, msg->Type);
1144 
1145  Reply = s->User.UserReplyFunctions;
1146  if (Reply != NULL) {
1147  error = CheckReplyFunctions(s, Reply, &reply);
1148  }
1149 
1150  if (error == ERR_UNKNOWNFRAME) {
1151  Reply = s->Phone.Functions->ReplyFunctions;
1152  error = CheckReplyFunctions(s, Reply, &reply);
1153  }
1154 
1155  if (error == ERR_NONE) {
1156  error = Reply[reply].Function(msg, s);
1157  if (Reply[reply].requestID == Phone->RequestID) {
1158  if (error == ERR_NEEDANOTHERANSWER) {
1159  error = ERR_NONE;
1160  } else {
1161  Phone->RequestID = ID_None;
1162  }
1163  }
1164  }
1165 
1166  if (strcmp(s->Phone.Functions->models,"NAUTO")) {
1167  disp = TRUE;
1168  switch (error) {
1169  case ERR_UNKNOWNRESPONSE:
1170  smprintf_level(s, D_ERROR, "\nUNKNOWN response");
1171  break;
1172  case ERR_UNKNOWNFRAME:
1173  smprintf_level(s, D_ERROR, "\nUNKNOWN frame");
1174  break;
1175  case ERR_FRAMENOTREQUESTED:
1176  smprintf_level(s, D_ERROR, "\nFrame not request now");
1177  break;
1178  default:
1179  disp = FALSE;
1180  }
1181 
1182  if (error == ERR_UNKNOWNFRAME || error == ERR_FRAMENOTREQUESTED) {
1183  error = ERR_TIMEOUT;
1184  }
1185  }
1186 
1187  if (disp) {
1188  smprintf(s,". Please report the error, see <https://wammu.eu/support/bugs/>. Thank you\n");
1189  if (Phone->SentMsg != NULL) {
1190  smprintf(s,"LAST SENT frame ");
1191  smprintf(s, "type 0x%02X/length %ld", Phone->SentMsg->Type, (long)Phone->SentMsg->Length);
1192  DumpMessage(GSM_GetDI(s), Phone->SentMsg->Buffer, Phone->SentMsg->Length);
1193  }
1194  smprintf(s, "RECEIVED frame ");
1195  smprintf(s, "type 0x%02X/length 0x%lx/%ld", msg->Type, (long)msg->Length, (long)msg->Length);
1196  DumpMessage(GSM_GetDI(s), msg->Buffer, msg->Length);
1197  smprintf(s, "\n");
1198  }
1199 
1200  return error;
1201 }
1202 
1203 GSM_Error GSM_TryReadGammuRC (const char *path, INI_Section **result)
1204 {
1205  dbgprintf(NULL, "Open config: \"%s\"\n", path);
1206  return INI_ReadFile(path, FALSE, result);
1207 }
1208 
1209 GSM_Error GSM_FindGammuRC (INI_Section **result, const char *force_config)
1210 {
1211  char configfile[PATH_MAX + 1];
1212  char *envpath;
1213  GSM_Error error;
1214 #if defined(HAVE_GETPWUID) && defined(HAVE_GETUID)
1215  struct passwd *pwent;
1216 #endif
1217 
1218  *result = NULL;
1219 
1220  if (force_config != NULL) {
1221  return GSM_TryReadGammuRC(force_config, result);
1222  }
1223 
1224 #ifdef WIN32
1225  /* Get Windows application data path */
1226  if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, configfile))) {
1227  strcat(configfile, GAMMURC_NAME);
1228 
1229  error = GSM_TryReadGammuRC(configfile, result);
1230  if (error == ERR_NONE) return ERR_NONE;
1231  }
1232 #endif
1233 
1234  /* XDG paths */
1235  envpath = getenv("XDG_CONFIG_HOME");
1236  if (envpath) {
1237  strcpy(configfile, envpath);
1238  strcat(configfile, XDG_GAMMURC_NAME);
1239 
1240  error = GSM_TryReadGammuRC(configfile, result);
1241  if (error == ERR_NONE) return ERR_NONE;
1242  } else {
1243  envpath = getenv("HOME");
1244  if (envpath) {
1245  strcpy(configfile, envpath);
1246  strcat(configfile, "/.config");
1247  strcat(configfile, XDG_GAMMURC_NAME);
1248 
1249  error = GSM_TryReadGammuRC(configfile, result);
1250  if (error == ERR_NONE) return ERR_NONE;
1251  }
1252  }
1253 
1254  /* Try home from environment */
1255  envpath = getenv("HOME");
1256  if (envpath) {
1257  strcpy(configfile, envpath);
1258  strcat(configfile, GAMMURC_NAME);
1259 
1260  error = GSM_TryReadGammuRC(configfile, result);
1261  if (error == ERR_NONE) return ERR_NONE;
1262  }
1263 
1264 #if defined(HAVE_GETPWUID) && defined(HAVE_GETUID)
1265  /* Tru home from passwd */
1266  pwent = getpwuid(getuid());
1267  if (pwent != NULL) {
1268  strcpy(configfile, pwent->pw_dir);
1269  strcat(configfile, GAMMURC_NAME);
1270 
1271  error = GSM_TryReadGammuRC(configfile, result);
1272  if (error == ERR_NONE) return ERR_NONE;
1273  }
1274 
1275 #endif
1276 
1277 #if defined(WIN32)
1278  /* Reset as we're using strcat */
1279  configfile[0] = 0;
1280 
1281  /* This makes sense only on Windows */
1282  envpath = getenv("HOMEDRIVE");
1283  if (envpath) {
1284  strcat(configfile, envpath);
1285  }
1286 
1287  envpath = getenv("HOMEPATH");
1288  if (envpath) {
1289  strcat(configfile, envpath);
1290  strcat(configfile, GAMMURC_NAME);
1291 
1292  error = GSM_TryReadGammuRC(configfile, result);
1293  if (error == ERR_NONE) return ERR_NONE;
1294  }
1295 #endif
1296 
1297  /* Try fallback config as last */
1298  return GSM_TryReadGammuRC(FALLBACK_GAMMURC, result);
1299 }
1300 
1302 {
1303  if (num == -1) {
1304  return s->CurrentConfig;
1305  } else {
1306  if (num > MAX_CONFIG_NUM) return NULL;
1307  return &(s->Config[num]);
1308  }
1309 }
1310 
1311 
1313 {
1314  return s->ConfigNum;
1315 }
1316 
1317 void GSM_SetConfigNum(GSM_StateMachine *s, int sections)
1318 {
1319  if (sections > MAX_CONFIG_NUM) return;
1320  s->ConfigNum = sections;
1321 }
1322 
1326 void GSM_ExpandUserPath(char **string)
1327 {
1328  char *tmp = NULL, *home = NULL;
1329 
1330  /* Is there something to expand */
1331  if (*string[0] != '~') return;
1332 
1333  /* Grab home */
1334  home = getenv("HOME");
1335  if (home == NULL) return;
1336 
1337  /* Allocate memory */
1338  tmp = (char *)malloc(strlen(home) + strlen(*string) + 2);
1339  if (tmp == NULL) return;
1340 
1341  /* Create final path */
1342  strcpy(tmp, home);
1343  strcat(tmp, *string + 1);
1344 
1345  /* Free old storage and replace it */
1346  free(*string);
1347  *string = tmp;
1348 }
1349 
1351 {
1352  INI_Section *h;
1353  unsigned char section[50]={0};
1354  gboolean found = FALSE;
1355  char *Temp = NULL;
1356 
1357  GSM_Error error = ERR_UNKNOWN;
1358 
1359  cfg->UseGlobalDebugFile = TRUE;
1360 
1361  /* If we don't have valid config, bail out */
1362  if (cfg_info == NULL) {
1363  error = ERR_UNCONFIGURED;
1364  goto fail;
1365  }
1366 
1367  /* Which section should we read? */
1368  if (num == 0) {
1369  snprintf(section, sizeof(section) - 1, "gammu");
1370  } else {
1371  snprintf(section, sizeof(section) - 1, "gammu%i", num);
1372  }
1373 
1374  /* Scan for section */
1375  for (h = cfg_info; h != NULL; h = h->Next) {
1376  if (strcasecmp(section, h->SectionName) == 0) {
1377  found = TRUE;
1378  break;
1379  }
1380  }
1381  if (!found) {
1382  error = ERR_NONE_SECTION;
1383  goto fail;
1384  }
1385 
1386  /* Set device name */
1387  free(cfg->Device);
1388  cfg->Device = INI_GetValue(cfg_info, section, "device", FALSE);
1389  if (!cfg->Device) {
1390  cfg->Device = INI_GetValue(cfg_info, section, "port", FALSE);
1391  if (!cfg->Device) {
1392  cfg->Device = strdup(DEFAULT_DEVICE);
1393  } else {
1394  cfg->Device = strdup(cfg->Device);
1395  }
1396  } else {
1397  cfg->Device = strdup(cfg->Device);
1398  }
1399 
1400  /* Set connection type */
1401  free(cfg->Connection);
1402  cfg->Connection = INI_GetValue(cfg_info, section, "connection", FALSE);
1403  if (cfg->Connection == NULL) {
1404  cfg->Connection = strdup(DEFAULT_CONNECTION);
1405  } else {
1406  cfg->Connection = strdup(cfg->Connection);
1407  }
1408 
1409  /* Set time sync */
1410  cfg->SyncTime = INI_GetBool(cfg_info, section, "synchronizetime", DEFAULT_SYNCHRONIZE_TIME);
1411 
1412  /* Set debug file */
1413  free(cfg->DebugFile);
1414  cfg->DebugFile = INI_GetValue(cfg_info, section, "logfile", FALSE);
1415  if (cfg->DebugFile == NULL) {
1416  cfg->DebugFile = strdup(DEFAULT_DEBUG_FILE);
1417  } else {
1418  cfg->DebugFile = strdup(cfg->DebugFile);
1420  }
1421 
1422  /* Set file locking */
1423  cfg->LockDevice = INI_GetBool(cfg_info, section, "use_locking", DEFAULT_LOCK_DEVICE);
1424 
1425  /* Set model */
1426  Temp = INI_GetValue(cfg_info, section, "model", FALSE);
1427  if (Temp == NULL || strcmp(Temp, "auto") == 0) {
1428  strcpy(cfg->Model,DEFAULT_MODEL);
1429  } else {
1430  if (strlen(Temp) >= sizeof(cfg->Model))
1431  Temp[sizeof(cfg->Model) - 1] = '\0';
1432  strcpy(cfg->Model,Temp);
1433  }
1434 
1435  /* Set Log format */
1436  Temp = INI_GetValue(cfg_info, section, "logformat", FALSE);
1437 
1438  if (Temp == NULL) {
1439  strcpy(cfg->DebugLevel,DEFAULT_DEBUG_LEVEL);
1440  } else {
1441  if (strlen(Temp) >= sizeof(cfg->DebugLevel))
1442  Temp[sizeof(cfg->DebugLevel) - 1] = '\0';
1443  strcpy(cfg->DebugLevel,Temp);
1444  }
1445 
1446  /* Set startup info */
1447  cfg->StartInfo = INI_GetBool(cfg_info, section, "startinfo", DEFAULT_START_INFO);
1448 
1449  /* Read localised strings for some phones */
1450 
1451  Temp = INI_GetValue(cfg_info, section, "reminder", FALSE);
1452 
1453  if (Temp == NULL) {
1454  strcpy(cfg->TextReminder,"Reminder");
1455  } else {
1456  if (strlen(Temp) >= sizeof(cfg->TextReminder))
1457  Temp[sizeof(cfg->TextReminder) - 1] = '\0';
1458  strcpy(cfg->TextReminder,Temp);
1459  }
1460 
1461  Temp = INI_GetValue(cfg_info, section, "meeting", FALSE);
1462 
1463  if (Temp == NULL) {
1464  strcpy(cfg->TextMeeting,"Meeting");
1465  } else {
1466  if (strlen(Temp) >= sizeof(cfg->TextMeeting))
1467  Temp[sizeof(cfg->TextMeeting) - 1] = '\0';
1468  strcpy(cfg->TextMeeting,Temp);
1469  }
1470 
1471  Temp = INI_GetValue(cfg_info, section, "call", FALSE);
1472 
1473  if (Temp == NULL) {
1474  strcpy(cfg->TextCall,"Call");
1475  } else {
1476  if (strlen(Temp) >= sizeof(cfg->TextCall))
1477  Temp[sizeof(cfg->TextCall) - 1] = '\0';
1478  strcpy(cfg->TextCall,Temp);
1479  }
1480 
1481  Temp = INI_GetValue(cfg_info, section, "birthday", FALSE);
1482 
1483  if (Temp == NULL) {
1484  strcpy(cfg->TextBirthday,"Birthday");
1485  } else {
1486  if (strlen(Temp) >= sizeof(cfg->TextBirthday))
1487  Temp[sizeof(cfg->TextBirthday) - 1] = '\0';
1488  strcpy(cfg->TextBirthday,Temp);
1489  }
1490 
1491  Temp = INI_GetValue(cfg_info, section, "memo", FALSE);
1492 
1493  if (Temp == NULL) {
1494  strcpy(cfg->TextMemo,"Memo");
1495  } else {
1496  if (strlen(Temp) >= sizeof(cfg->TextMemo))
1497  Temp[sizeof(cfg->TextMemo) - 1] = '\0';
1498  strcpy(cfg->TextMemo,Temp);
1499  }
1500 
1501  /* Phone features */
1502  Temp = INI_GetValue(cfg_info, section, "features", FALSE);
1503 
1504  if (Temp == NULL) {
1505  cfg->PhoneFeatures[0] = 0;
1506  } else {
1507  error = GSM_SetFeatureString(cfg->PhoneFeatures, Temp);
1508 
1509  if (error != ERR_NONE) {
1510  goto fail;
1511  }
1512  }
1513  return ERR_NONE;
1514 
1515 fail:
1516  /* Special case, this config needs to be somehow valid */
1517  if (num == 0) {
1518  cfg->Device = strdup(DEFAULT_DEVICE);
1519  cfg->Connection = strdup(DEFAULT_CONNECTION);
1521  cfg->DebugFile = strdup(DEFAULT_DEBUG_FILE);
1523  strcpy(cfg->Model,DEFAULT_MODEL);
1524  strcpy(cfg->DebugLevel,DEFAULT_DEBUG_LEVEL);
1526  strcpy(cfg->TextReminder,"Reminder");
1527  strcpy(cfg->TextMeeting,"Meeting");
1528  strcpy(cfg->TextCall,"Call");
1529  strcpy(cfg->TextBirthday,"Birthday");
1530  strcpy(cfg->TextMemo,"Memo");
1531  cfg->PhoneFeatures[0] = 0;
1532  /* Indicate that we used defaults */
1533  return ERR_USING_DEFAULTS;
1534  }
1535  return error;
1536 }
1537 
1538 void GSM_DumpMessageText_Custom(GSM_StateMachine *s, unsigned const char *message, size_t messagesize, int type, const char *text)
1539 {
1540  GSM_Debug_Info *curdi;
1541 
1542  curdi = GSM_GetDI(s);
1543 
1544  if (curdi->dl == DL_TEXT ||
1545  curdi->dl == DL_TEXTALL ||
1546  curdi->dl == DL_TEXTDATE ||
1547  curdi->dl == DL_TEXTALLDATE) {
1548  smprintf(s, "%s ", text);
1549  smprintf(s, "type 0x%02X/length 0x%02lX/%ld",
1550  type, (long)messagesize, (long)messagesize);
1551  DumpMessage(curdi, message, messagesize);
1552  }
1553 }
1554 
1555 void GSM_DumpMessageText(GSM_StateMachine *s, unsigned const char *message, size_t messagesize, int type)
1556 {
1557  GSM_DumpMessageText_Custom(s, message, messagesize, type, "SENDING frame");
1558 }
1559 
1560 void GSM_DumpMessageTextRecv(GSM_StateMachine *s, unsigned const char *message, size_t messagesize, int type)
1561 {
1562  GSM_DumpMessageText_Custom(s, message, messagesize, type, "RECEIVED frame");
1563 }
1564 
1565 void GSM_DumpMessageBinary_Custom(GSM_StateMachine *s, unsigned const char *message, size_t messagesize, int type, int direction)
1566 {
1567  size_t i=0;
1568  GSM_Debug_Info *curdi;
1569 
1570  curdi = GSM_GetDI(s);
1571 
1572  if (curdi->dl == DL_BINARY) {
1573  smprintf(s,"%c", direction);
1574  smprintf(s,"%c",type);
1575  smprintf(s,"%c",(int)(messagesize/256));
1576  smprintf(s,"%c",(int)(messagesize%256));
1577 
1578  for (i=0;i<messagesize;i++) {
1579  smprintf(s,"%c",message[i]);
1580  }
1581  }
1582 }
1583 void GSM_DumpMessageBinary(GSM_StateMachine *s, unsigned const char *message, size_t messagesize, int type)
1584 {
1585  GSM_DumpMessageBinary_Custom(s, message, messagesize, type, 0x01);
1586 }
1587 
1588 void GSM_DumpMessageBinaryRecv(GSM_StateMachine *s, unsigned const char *message, size_t messagesize, int type)
1589 {
1590  GSM_DumpMessageBinary_Custom(s, message, messagesize, type, 0x02);
1591 }
1592 
1593 void GSM_OSErrorInfo(GSM_StateMachine *s, const char *description)
1594 {
1595 #ifdef WIN32
1596  int i=0;
1597  unsigned char *lpMsgBuf = NULL;
1598 #endif
1599  GSM_Debug_Info *curdi;
1600 
1601  curdi = GSM_GetDI(s);
1602 
1603 #ifdef WIN32
1604  /* We don't use errno in win32 - GetLastError gives better info */
1605  if (GetLastError() != 0) {
1606  if (curdi->dl == DL_TEXTERROR ||
1607  curdi->dl == DL_TEXT ||
1608  curdi->dl == DL_TEXTALL ||
1609  curdi->dl == DL_TEXTERRORDATE ||
1610  curdi->dl == DL_TEXTDATE ||
1611  curdi->dl == DL_TEXTALLDATE) {
1612  FormatMessage(
1613  FORMAT_MESSAGE_ALLOCATE_BUFFER |
1614  FORMAT_MESSAGE_FROM_SYSTEM |
1615  FORMAT_MESSAGE_IGNORE_INSERTS,
1616  NULL,
1617  GetLastError(),
1618  MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */
1619  (LPTSTR) &lpMsgBuf,
1620  0,
1621  NULL
1622  );
1623  for (i=0;i<(int)strlen(lpMsgBuf);i++) {
1624  if (lpMsgBuf[i] == 13 || lpMsgBuf[i] == 10) {
1625  lpMsgBuf[i] = ' ';
1626  }
1627  }
1628  smprintf(s,"[System error - %s, %i, \"%s\"]\n", description, (int)GetLastError(), (LPCTSTR)lpMsgBuf);
1629  LocalFree(lpMsgBuf);
1630  }
1631  }
1632 #else
1633 
1634  if (errno!=-1) {
1635  if (curdi->dl == DL_TEXTERROR ||
1636  curdi->dl == DL_TEXT ||
1637  curdi->dl == DL_TEXTALL ||
1638  curdi->dl == DL_TEXTERRORDATE ||
1639  curdi->dl == DL_TEXTDATE ||
1640  curdi->dl == DL_TEXTALLDATE) {
1641  smprintf(s,"[System error - %s, %i, \"%s\"]\n",description,errno,strerror(errno));
1642  }
1643  }
1644 #endif
1645 }
1646 
1648 {
1649  s->User.IncomingCall = callback;
1650  s->User.IncomingCallUserData = user_data;
1651 }
1652 
1654 {
1655  s->User.IncomingSMS = callback;
1656  s->User.IncomingSMSUserData = user_data;
1657 }
1658 
1660 {
1661  s->User.IncomingCB = callback;
1662  s->User.IncomingCBUserData = user_data;
1663 }
1664 
1666 {
1667  s->User.IncomingUSSD = callback;
1668  s->User.IncomingUSSDUserData = user_data;
1669 }
1670 
1672 {
1673  s->User.SendSMSStatus = callback;
1674  s->User.SendSMSStatusUserData = user_data;
1675 }
1676 
1678 {
1679  GSM_StateMachine *ret;
1680  ret = (GSM_StateMachine *)calloc(1, sizeof(GSM_StateMachine));
1681  if (ret == NULL) {
1682  return ret;
1683  }
1684  ret->CurrentConfig = &(ret->Config[0]);
1685  ret->Abort = FALSE;
1686  return ret;
1687 }
1688 
1690 {
1691  int i=0;
1692 
1693  if (s == NULL) return;
1694 
1695  /* Free allocated memory */
1696  for (i = 0; i <= MAX_CONFIG_NUM; i++) {
1697  free(s->Config[i].Device);
1698  s->Config[i].Device = NULL;
1699  free(s->Config[i].Connection);
1700  s->Config[i].Connection = NULL;
1701  free(s->Config[i].DebugFile);
1702  s->Config[i].DebugFile = NULL;
1703  }
1704  free(s);
1705  s = NULL;
1706 }
1707 
1708 
1710 {
1711  return s->ConnectionType;
1712 }
1713 
1715 {
1716  return s->Phone.Data.ModelInfo;
1717 }
1718 
1720 {
1721  return s == NULL ? NULL : &(s->di);
1722 }
1723 
1724 
1725 /* How should editor hadle tabs in this file? Add editor commands here.
1726  * vim: noexpandtab sw=8 ts=8 sts=8:
1727  */
void GSM_DumpMessageBinary(GSM_StateMachine *s, unsigned const char *message, size_t messagesize, int type)
Definition: gsmstate.c:1583
GSM_Error(* Terminate)(GSM_StateMachine *s)
Definition: gsmstate.h:760
GSM_Config * CurrentConfig
Definition: gsmstate.h:1415
gboolean EnableIncomingUSSD
Definition: gsmstate.h:671
GSM_Error GSM_SetDebugFunction(GSM_Log_Function info, void *data, GSM_Debug_Info *privdi)
Definition: debug.c:179
void GSM_SetIncomingCallCallback(GSM_StateMachine *s, IncomingCallCallback callback, void *user_data)
Definition: gsmstate.c:1647
const char * GetOS(void)
Definition: misc.c:537
gboolean UseGlobalDebugFile
char HardwareCache[50]
Definition: gsmstate.h:466
IncomingUSSDCallback IncomingUSSD
Definition: gsmstate.h:1384
void GSM_SetIncomingSMSCallback(GSM_StateMachine *s, IncomingSMSCallback callback, void *user_data)
Definition: gsmstate.c:1653
GSM_Error GSM_InitConnection_Log(GSM_StateMachine *s, int ReplyNum, GSM_Log_Function log_function, void *user_data)
Definition: gsmstate.c:711
#define GAMMU_VERSION
Definition: gammu-config.h:7
void DumpMessage(GSM_Debug_Info *d, const unsigned char *message, const size_t messagesize)
Definition: debug.c:314
GSM_Error GSM_InitConnection(GSM_StateMachine *s, int ReplyNum)
Definition: gsmstate.c:914
GSM_StateMachine * GSM_AllocStateMachine(void)
Definition: gsmstate.c:1677
char TextBirthday[32]
#define PATH_MAX
Definition: dummy.h:31
IncomingCBCallback IncomingCB
Definition: gsmstate.h:1383
void * IncomingCallUserData
Definition: gsmstate.h:1386
GSM_Error GSM_OpenConnection(GSM_StateMachine *s)
Definition: gsmstate.c:560
void GSM_SetConfigNum(GSM_StateMachine *s, int sections)
Definition: gsmstate.c:1317
void * IncomingUSSDUserData
Definition: gsmstate.h:1389
GSM_Phone_Functions NAUTOPhone
void GSM_DumpMessageTextRecv(GSM_StateMachine *s, unsigned const char *message, size_t messagesize, int type)
Definition: gsmstate.c:1560
GSM_Reply_Function * UserReplyFunctions
Definition: gsmstate.h:1379
GSM_ConnectionType ConnectionType
Definition: gsmstate.h:1402
GSM_Error(* PostConnect)(GSM_StateMachine *s)
Definition: gsmstate.h:1313
#define DEFAULT_DEBUG_FILE
Definition: gsmstate.c:61
int StartInfoCounter
Definition: gsmstate.h:476
GSM_Error(* CloseDevice)(GSM_StateMachine *s)
Definition: gsmstate.h:236
GSM_Debug_Info * GSM_GetDI(GSM_StateMachine *s)
Definition: gsmstate.c:70
GSM_Config Config[MAX_CONFIG_NUM+1]
Definition: gsmstate.h:1414
GSM_Log_Function log_function
Definition: debug.h:44
char VerDate[GSM_MAX_VERSION_DATE_LENGTH+1]
Definition: gsmstate.h:458
int FindSerialSpeed(const char *buffer)
Definition: devfunc.c:367
GSM_Error GSM_Reset(GSM_StateMachine *s, gboolean hard)
Definition: api.c:333
Definition: debug.h:26
GSM_Error(* StateMachine)(GSM_StateMachine *s, unsigned char rx_char)
Definition: gsmstate.h:352
GSM_Error(* Function)(GSM_Protocol_Message *msg, GSM_StateMachine *s)
Definition: gsmreply.h:231
gboolean GSM_IsConnected(GSM_StateMachine *s)
Definition: gsmstate.c:976
SendSMSStatusCallback SendSMSStatus
Definition: gsmstate.h:1385
GSM_Error GSM_DispatchMessage(GSM_StateMachine *s)
Definition: gsmstate.c:1131
#define NONEFUNCTION
Definition: gsmcomon.h:12
gboolean EnableIncomingCB
Definition: gsmstate.h:667
GSM_Error(* SetDateTime)(GSM_StateMachine *s, GSM_DateTime *date_time)
Definition: gsmstate.h:818
GSM_Error
Definition: gammu-error.h:23
static void GSM_RegisterConnection(GSM_StateMachine *s, unsigned int connection, GSM_Device_Functions *device, GSM_Protocol_Functions *protocol)
Definition: gsmstate.c:81
gboolean LockDevice
static GSM_Error CheckReplyFunctions(GSM_StateMachine *s, GSM_Reply_Function *Reply, int *reply)
Definition: gsmstate.c:1077
GSM_Error DispatchError
Definition: gsmstate.h:689
GSM_Debug_Info di
Definition: gsmstate.h:1412
const char * model
Definition: gammu-info.h:764
int GSM_ReadDevice(GSM_StateMachine *s, gboolean waitforreply)
Definition: gsmstate.c:919
void(* SendSMSStatusCallback)(GSM_StateMachine *s, int status, int MessageReference, void *user_data)
void * SendSMSStatusUserData
Definition: gsmstate.h:1390
gboolean EnableIncomingCall
Definition: gsmstate.h:659
GSM_Error GSM_WaitForOnce(GSM_StateMachine *s, unsigned const char *buffer, size_t length, int type, int timeout)
Definition: gsmstate.c:986
gboolean SkipDtrRts
Definition: gsmstate.c:105
GSM_Error GSM_SetDebugFileDescriptor(FILE *fd, gboolean closable, GSM_Debug_Info *privdi)
Definition: debug.c:127
GSM_Error(* WriteMessage)(GSM_StateMachine *s, unsigned const char *buffer, int length, int type)
Definition: gsmstate.h:347
char Version[GSM_MAX_VERSION_LENGTH+1]
Definition: gsmstate.h:454
const int subtype
Definition: gsmreply.h:245
static const GSM_ConnectionInfo GSM_Connections[]
Definition: gsmstate.c:111
gboolean unlock_device(GSM_StateMachine *s, char **lock_file)
Definition: devfunc.c:347
void(* GSM_Log_Function)(const char *text, void *data)
char Manufacturer[GSM_MAX_MANUFACTURER_LENGTH+1]
Definition: gsmstate.h:441
void GSM_SetIncomingUSSDCallback(GSM_StateMachine *s, IncomingUSSDCallback callback, void *user_data)
Definition: gsmstate.c:1665
GSM_PhoneModel * ModelInfo
Definition: gsmstate.h:449
volatile gboolean Abort
Definition: gsmstate.h:1423
void StripSpaces(char *buff)
Definition: misc.c:713
int smprintf_level(GSM_StateMachine *s, GSM_DebugSeverity severity, const char *format,...)
Definition: debug.c:278
const char * Name
Definition: gsmstate.c:97
static void GSM_RegisterModule(GSM_StateMachine *s, GSM_Phone_Functions *phone)
Definition: gsmstate.c:360
void GSM_DumpMessageBinary_Custom(GSM_StateMachine *s, unsigned const char *message, size_t messagesize, int type, int direction)
Definition: gsmstate.c:1565
char DebugLevel[50]
GSM_Error(* GetModel)(GSM_StateMachine *s)
Definition: gsmstate.h:777
GSM_Error(* GetManufacturer)(GSM_StateMachine *s)
Definition: gsmstate.h:773
void GSM_ExpandUserPath(char **string)
Definition: gsmstate.c:1326
GSM_Error(* OpenDevice)(GSM_StateMachine *s)
Definition: gsmstate.h:232
#define DEFAULT_MODEL
Definition: gsmstate.c:58
GSM_Error(* Initialise)(GSM_StateMachine *s)
Definition: gsmstate.h:356
#define FALLBACK_GAMMURC
Definition: gsmstate.c:42
void(* IncomingUSSDCallback)(GSM_StateMachine *s, GSM_USSDMessage *ussd, void *user_data)
GSM_ConnectionType
int gboolean
Definition: gammu-types.h:23
GSM_Error(* GetFirmware)(GSM_StateMachine *s)
Definition: gsmstate.h:781
GSM_Feature PhoneFeatures[GSM_MAX_PHONE_FEATURES+1]
const char * models
Definition: gsmstate.h:743
GSM_Debug_Info GSM_global_debug
Definition: debug.c:33
GSM_PhoneModel * GetModelData(GSM_StateMachine *s, const char *model, const char *number, const char *irdamodel)
Definition: gsmphones.c:1002
GSM_Error GSM_CloseConnection(GSM_StateMachine *s)
Definition: gsmstate.c:589
GSM_Phone Phone
Definition: gsmstate.h:1431
#define FALSE
Definition: gammu-types.h:25
void(* IncomingCallCallback)(GSM_StateMachine *s, GSM_Call *call, void *user_data)
gboolean INI_GetBool(INI_Section *cfg, const unsigned char *section, const unsigned char *key, gboolean fallback)
Definition: cfg.c:344
GSM_Protocol_Message * SentMsg
Definition: gsmstate.h:680
gboolean GSM_AddPhoneFeature(GSM_PhoneModel *model, GSM_Feature feature)
Definition: gsmphones.c:1039
GSM_PhoneModel * GSM_GetModelInfo(GSM_StateMachine *s)
Definition: gsmstate.c:1714
GSM_Error INI_ReadFile(const char *FileName, gboolean Unicode, INI_Section **result)
Definition: cfg.c:24
GSM_Error GSM_WaitFor(GSM_StateMachine *s, unsigned const char *buffer, size_t length, int type, int timeout, GSM_Phone_RequestID request)
Definition: gsmstate.c:1029
#define MAX_CONFIG_NUM
Definition: gsmstate.h:1399
GSM_Device_Functions NoneDevice
Definition: gsmstate.c:180
int GSM_GetConfigNum(const GSM_StateMachine *s)
Definition: gsmstate.c:1312
void GSM_LogError(GSM_StateMachine *s, const char *message, const GSM_Error err)
Definition: gsmcomon.c:221
gboolean StartInfo
GSM_Protocol_Functions NoProtocol
Definition: gsmstate.c:190
gboolean SyncTime
GSM_Phone_RequestID RequestID
Definition: gsmstate.h:685
GSM_Error GSM_AbortOperation(GSM_StateMachine *s)
Definition: gsmstate.c:980
int(* ReadDevice)(GSM_StateMachine *s, void *buf, size_t nbytes)
Definition: gsmstate.h:252
void * user_data
Definition: debug.h:48
char TextMeeting[32]
void GSM_OSErrorInfo(GSM_StateMachine *s, const char *description)
Definition: gsmstate.c:1593
const size_t subtypechar
Definition: gsmreply.h:241
GSM_Feature features[GSM_MAX_PHONE_FEATURES+1]
Definition: gammu-info.h:776
GSM_Error GSM_TerminateConnection(GSM_StateMachine *s)
Definition: gsmstate.c:949
GSM_Error GSM_SetDebugFile(const char *info, GSM_Debug_Info *privdi)
Definition: debug.c:144
GSM_Device_Functions * Functions
Definition: gsmstate.h:335
IncomingCallCallback IncomingCall
Definition: gsmstate.h:1381
gboolean opened
Definition: gsmstate.h:1413
GSM_Error GSM_SetFeatureString(GSM_Feature *list, const char *string)
Definition: gsmphones.c:155
GSM_Error GSM_FindGammuRC(INI_Section **result, const char *force_config)
Definition: gsmstate.c:1209
GSM_Protocol Protocol
Definition: gsmstate.h:1430
void(* IncomingCBCallback)(GSM_StateMachine *s, GSM_CBMessage *cb, void *user_data)
GSM_Config * GSM_GetConfig(GSM_StateMachine *s, int num)
Definition: gsmstate.c:1301
GSM_Device_Functions ProxyDevice
Definition: proxy.c:212
gboolean use_global
Definition: debug.h:37
const GSM_ConnectionType Connection
Definition: gsmstate.c:101
void * IncomingCBUserData
Definition: gsmstate.h:1388
#define DEFAULT_DEBUG_LEVEL
Definition: gsmstate.c:62
GSM_Phone_Data Data
Definition: gsmstate.h:1369
#define dbgprintf
Definition: debug.h:72
void GSM_GetCurrentDateTime(GSM_DateTime *Date)
Definition: misc.c:184
GSM_Error(* Terminate)(GSM_StateMachine *s)
Definition: gsmstate.h:360
double VerNum
Definition: gsmstate.h:462
gboolean GSM_IsPhoneFeatureAvailable(GSM_PhoneModel *model, GSM_Feature feature)
Definition: gsmphones.c:1026
gboolean GSM_SetDebugLevel(const char *info, GSM_Debug_Info *privdi)
Definition: debug.c:186
GSM_Phone_Functions * Functions
Definition: gsmstate.h:1373
gboolean NoPowerCable
Definition: gsmstate.h:1410
unsigned char * INI_GetValue(INI_Section *cfg, const unsigned char *section, const unsigned char *key, const gboolean Unicode)
Definition: cfg.c:365
#define DEFAULT_SYNCHRONIZE_TIME
Definition: gsmstate.c:60
GSM_Error(* Initialise)(GSM_StateMachine *s)
Definition: gsmstate.h:756
gboolean SkipDtrRts
Definition: gsmstate.h:1406
#define DEFAULT_LOCK_DEVICE
Definition: gsmstate.c:63
GSM_Phone_Functions DUMMYPhone
Definition: dummy.c:1964
GSM_Error GSM_TryReadGammuRC(const char *path, INI_Section **result)
Definition: gsmstate.c:1203
unsigned char * SectionName
Definition: gammu-inifile.h:55
#define DEFAULT_START_INFO
Definition: gsmstate.c:64
#define DEFAULT_CONNECTION
Definition: gsmstate.c:59
void * IncomingSMSUserData
Definition: gsmstate.h:1387
GSM_Error GSM_ReadConfig(INI_Section *cfg_info, GSM_Config *cfg, int num)
Definition: gsmstate.c:1350
char TextReminder[32]
GSM_Reply_Function * ReplyFunctions
Definition: gsmstate.h:748
GSM_Error GSM_RegisterAllPhoneModules(GSM_StateMachine *s)
Definition: gsmstate.c:383
void GSM_DumpMessageBinaryRecv(GSM_StateMachine *s, unsigned const char *message, size_t messagesize, int type)
Definition: gsmstate.c:1588
GSM_Protocol_Functions * Functions
Definition: gsmstate.h:424
#define TRUE
Definition: gammu-types.h:28
GSM_ConnectionType GSM_GetUsedConnection(GSM_StateMachine *s)
Definition: gsmstate.c:1709
#define GAMMURC_NAME
Definition: gsmstate.c:43
void GSM_SetIncomingCBCallback(GSM_StateMachine *s, IncomingCBCallback callback, void *user_data)
Definition: gsmstate.c:1659
GSM_Error GSM_TryGetModel(GSM_StateMachine *s)
Definition: gsmstate.c:623
void GSM_SetSendSMSStatusCallback(GSM_StateMachine *s, SendSMSStatusCallback callback, void *user_data)
Definition: gsmstate.c:1671
gboolean EnableIncomingSMS
Definition: gsmstate.h:663
unsigned char * Buffer
Definition: protocol.h:22
#define XDG_GAMMURC_NAME
Definition: gsmstate.c:45
void GSM_FreeStateMachine(GSM_StateMachine *s)
Definition: gsmstate.c:1689
static GSM_Error GSM_RegisterAllConnections(GSM_StateMachine *s, const char *connection)
Definition: gsmstate.c:197
GSM_Phone_RequestID
Definition: gsmreply.h:25
char Model[GSM_MAX_MODEL_LENGTH+1]
Definition: gsmstate.h:445
void(* IncomingSMSCallback)(GSM_StateMachine *s, GSM_SMSMessage *sms, void *user_data)
GSM_Debug_Info GSM_none_debug
Definition: debug.c:22
Debug_Level dl
Definition: debug.h:35
GSM_Error(* ShowStartInfo)(GSM_StateMachine *s, gboolean enable)
Definition: gsmstate.h:769
GSM_Protocol_Message * RequestMsg
Definition: gsmstate.h:676
volatile size_t MessagesCount
Definition: gsmstate.h:1427
IncomingSMSCallback IncomingSMS
Definition: gsmstate.h:1382
void GSM_DumpMessageText(GSM_StateMachine *s, unsigned const char *message, size_t messagesize, int type)
Definition: gsmstate.c:1555
GSM_Device Device
Definition: gsmstate.h:1429
Definition: debug.h:91
INI_Section * Next
Definition: gammu-inifile.h:53
char TextCall[32]
char ProductCodeCache[50]
Definition: gsmstate.h:470
int smprintf(GSM_StateMachine *s, const char *format,...)
Definition: debug.c:261
#define DEFAULT_DEVICE
Definition: gsmstate.c:56
GSM_Error lock_device(GSM_StateMachine *s, const char *port, char **lock_name)
Definition: devfunc.c:212
void GSM_DumpMessageText_Custom(GSM_StateMachine *s, unsigned const char *message, size_t messagesize, int type, const char *text)
Definition: gsmstate.c:1538
GSM_Debug_Info * GSM_GetDebug(GSM_StateMachine *s)
Definition: gsmstate.c:1719