Gammu internals  1.38.0
gsmstate.c File Reference
#include <stdarg.h>
#include <string.h>
#include <errno.h>
#include <limits.h>
#include <gammu-call.h>
#include <gammu-settings.h>
#include <gammu-unicode.h>
#include <gammu-config.h>
#include <gammu-misc.h>
#include "debug.h"
#include "gsmcomon.h"
#include "gsmphones.h"
#include "gsmstate.h"
#include "misc/coding/coding.h"
#include "misc/misc.h"
#include "device/devfunc.h"
#include "../helper/string.h"
Include dependency graph for gsmstate.c:

Go to the source code of this file.

Data Structures

struct  GSM_ConnectionInfo
 

Macros

#define _GNU_SOURCE   /* For strcasestr */
 
#define FALLBACK_GAMMURC   "/etc/gammurc"
 
#define GAMMURC_NAME   "/.gammurc"
 
#define XDG_GAMMURC_NAME   "/gammu/config"
 
#define DEFAULT_DEVICE   "/dev/ttyUSB0"
 
#define DEFAULT_MODEL   ""
 
#define DEFAULT_CONNECTION   "at"
 
#define DEFAULT_SYNCHRONIZE_TIME   FALSE
 
#define DEFAULT_DEBUG_FILE   ""
 
#define DEFAULT_DEBUG_LEVEL   ""
 
#define DEFAULT_LOCK_DEVICE   FALSE
 
#define DEFAULT_START_INFO   FALSE
 

Functions

GSM_Debug_InfoGSM_GetDI (GSM_StateMachine *s)
 
static void GSM_RegisterConnection (GSM_StateMachine *s, unsigned int connection, GSM_Device_Functions *device, GSM_Protocol_Functions *protocol)
 
static GSM_Error GSM_RegisterAllConnections (GSM_StateMachine *s, const char *connection)
 
static void GSM_RegisterModule (GSM_StateMachine *s, GSM_Phone_Functions *phone)
 
GSM_Error GSM_RegisterAllPhoneModules (GSM_StateMachine *s)
 
GSM_Error GSM_OpenConnection (GSM_StateMachine *s)
 
GSM_Error GSM_CloseConnection (GSM_StateMachine *s)
 
GSM_Error GSM_TryGetModel (GSM_StateMachine *s)
 
GSM_Error GSM_InitConnection_Log (GSM_StateMachine *s, int ReplyNum, GSM_Log_Function log_function, void *user_data)
 
GSM_Error GSM_InitConnection (GSM_StateMachine *s, int ReplyNum)
 
int GSM_ReadDevice (GSM_StateMachine *s, gboolean waitforreply)
 
GSM_Error GSM_TerminateConnection (GSM_StateMachine *s)
 
gboolean GSM_IsConnected (GSM_StateMachine *s)
 
GSM_Error GSM_AbortOperation (GSM_StateMachine *s)
 
GSM_Error GSM_WaitForOnce (GSM_StateMachine *s, unsigned const char *buffer, size_t length, int type, int timeout)
 
GSM_Error GSM_WaitFor (GSM_StateMachine *s, unsigned const char *buffer, size_t length, int type, int timeout, GSM_Phone_RequestID request)
 
static GSM_Error CheckReplyFunctions (GSM_StateMachine *s, GSM_Reply_Function *Reply, int *reply)
 
GSM_Error GSM_DispatchMessage (GSM_StateMachine *s)
 
GSM_Error GSM_TryReadGammuRC (const char *path, INI_Section **result)
 
GSM_Error GSM_FindGammuRC (INI_Section **result, const char *force_config)
 
GSM_ConfigGSM_GetConfig (GSM_StateMachine *s, int num)
 
int GSM_GetConfigNum (const GSM_StateMachine *s)
 
void GSM_SetConfigNum (GSM_StateMachine *s, int sections)
 
void GSM_ExpandUserPath (char **string)
 
GSM_Error GSM_ReadConfig (INI_Section *cfg_info, GSM_Config *cfg, int num)
 
void GSM_DumpMessageText_Custom (GSM_StateMachine *s, unsigned const char *message, size_t messagesize, int type, const char *text)
 
void GSM_DumpMessageText (GSM_StateMachine *s, unsigned const char *message, size_t messagesize, int type)
 
void GSM_DumpMessageTextRecv (GSM_StateMachine *s, unsigned const char *message, size_t messagesize, int type)
 
void GSM_DumpMessageBinary_Custom (GSM_StateMachine *s, unsigned const char *message, size_t messagesize, int type, int direction)
 
void GSM_DumpMessageBinary (GSM_StateMachine *s, unsigned const char *message, size_t messagesize, int type)
 
void GSM_DumpMessageBinaryRecv (GSM_StateMachine *s, unsigned const char *message, size_t messagesize, int type)
 
void GSM_OSErrorInfo (GSM_StateMachine *s, const char *description)
 
void GSM_SetIncomingCallCallback (GSM_StateMachine *s, IncomingCallCallback callback, void *user_data)
 
void GSM_SetIncomingSMSCallback (GSM_StateMachine *s, IncomingSMSCallback callback, void *user_data)
 
void GSM_SetIncomingCBCallback (GSM_StateMachine *s, IncomingCBCallback callback, void *user_data)
 
void GSM_SetIncomingUSSDCallback (GSM_StateMachine *s, IncomingUSSDCallback callback, void *user_data)
 
void GSM_SetSendSMSStatusCallback (GSM_StateMachine *s, SendSMSStatusCallback callback, void *user_data)
 
GSM_StateMachineGSM_AllocStateMachine (void)
 
void GSM_FreeStateMachine (GSM_StateMachine *s)
 
GSM_ConnectionType GSM_GetUsedConnection (GSM_StateMachine *s)
 
GSM_PhoneModelGSM_GetModelInfo (GSM_StateMachine *s)
 
GSM_Debug_InfoGSM_GetDebug (GSM_StateMachine *s)
 

Variables

static const GSM_ConnectionInfo GSM_Connections []
 
GSM_Device_Functions NoneDevice
 
GSM_Protocol_Functions NoProtocol
 

Macro Definition Documentation

§ _GNU_SOURCE

#define _GNU_SOURCE   /* For strcasestr */

Definition at line 5 of file gsmstate.c.

§ DEFAULT_CONNECTION

#define DEFAULT_CONNECTION   "at"

Definition at line 59 of file gsmstate.c.

Referenced by GSM_ReadConfig().

§ DEFAULT_DEBUG_FILE

#define DEFAULT_DEBUG_FILE   ""

Definition at line 61 of file gsmstate.c.

Referenced by GSM_ReadConfig().

§ DEFAULT_DEBUG_LEVEL

#define DEFAULT_DEBUG_LEVEL   ""

Definition at line 62 of file gsmstate.c.

Referenced by GSM_ReadConfig().

§ DEFAULT_DEVICE

#define DEFAULT_DEVICE   "/dev/ttyUSB0"

Definition at line 56 of file gsmstate.c.

Referenced by GSM_ReadConfig().

§ DEFAULT_LOCK_DEVICE

#define DEFAULT_LOCK_DEVICE   FALSE

Definition at line 63 of file gsmstate.c.

Referenced by GSM_ReadConfig().

§ DEFAULT_MODEL

#define DEFAULT_MODEL   ""

Definition at line 58 of file gsmstate.c.

Referenced by GSM_ReadConfig().

§ DEFAULT_START_INFO

#define DEFAULT_START_INFO   FALSE

Definition at line 64 of file gsmstate.c.

Referenced by GSM_ReadConfig().

§ DEFAULT_SYNCHRONIZE_TIME

#define DEFAULT_SYNCHRONIZE_TIME   FALSE

Definition at line 60 of file gsmstate.c.

Referenced by GSM_ReadConfig().

§ FALLBACK_GAMMURC

#define FALLBACK_GAMMURC   "/etc/gammurc"

Definition at line 42 of file gsmstate.c.

Referenced by GSM_FindGammuRC().

§ GAMMURC_NAME

#define GAMMURC_NAME   "/.gammurc"

Definition at line 43 of file gsmstate.c.

Referenced by GSM_FindGammuRC().

§ XDG_GAMMURC_NAME

#define XDG_GAMMURC_NAME   "/gammu/config"

Definition at line 45 of file gsmstate.c.

Referenced by GSM_FindGammuRC().

Function Documentation

§ CheckReplyFunctions()

static GSM_Error CheckReplyFunctions ( GSM_StateMachine s,
GSM_Reply_Function Reply,
int *  reply 
)
static

Definition at line 1077 of file gsmstate.c.

References GSM_Protocol_Message::Buffer, GSM_Phone::Data, ERR_FRAMENOTREQUESTED, ERR_NONE, ERR_UNKNOWNFRAME, FALSE, ID_EachFrame, ID_IncomingFrame, ID_None, GSM_Protocol_Message::Length, _GSM_StateMachine::Phone, GSM_Phone_Data::RequestID, GSM_Phone_Data::RequestMsg, GSM_Reply_Function::subtype, GSM_Reply_Function::subtypechar, TRUE, and GSM_Protocol_Message::Type.

Referenced by GSM_DispatchMessage().

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 }
const int subtype
Definition: gsmreply.h:245
int gboolean
Definition: gammu-types.h:23
GSM_Phone Phone
Definition: gsmstate.h:1431
#define FALSE
Definition: gammu-types.h:25
GSM_Phone_RequestID RequestID
Definition: gsmstate.h:685
const size_t subtypechar
Definition: gsmreply.h:241
GSM_Phone_Data Data
Definition: gsmstate.h:1369
#define TRUE
Definition: gammu-types.h:28
unsigned char * Buffer
Definition: protocol.h:22
GSM_Protocol_Message * RequestMsg
Definition: gsmstate.h:676

§ GSM_CloseConnection()

GSM_Error GSM_CloseConnection ( GSM_StateMachine s)

Internal function which just closes connection and cleans up structures.

Definition at line 589 of file gsmstate.c.

References GSM_Device_Functions::CloseDevice, GSM_Phone::Data, _GSM_StateMachine::Device, ERR_NONE, GSM_Device::Functions, GSM_Protocol::Functions, _GSM_StateMachine::LockFile, GSM_Phone_Data::Manufacturer, GSM_Phone_Data::Model, GSM_Phone_Data::ModelInfo, _GSM_StateMachine::Phone, _GSM_StateMachine::Protocol, smprintf(), GSM_Protocol_Functions::Terminate, unlock_device(), GSM_Phone_Data::VerDate, GSM_Phone_Data::VerNum, and GSM_Phone_Data::Version.

Referenced by GSM_InitConnection_Log(), and GSM_TerminateConnection().

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 }
GSM_Error(* CloseDevice)(GSM_StateMachine *s)
Definition: gsmstate.h:236
char VerDate[GSM_MAX_VERSION_DATE_LENGTH+1]
Definition: gsmstate.h:458
GSM_Error
Definition: gammu-error.h:23
char Version[GSM_MAX_VERSION_LENGTH+1]
Definition: gsmstate.h:454
gboolean unlock_device(GSM_StateMachine *s, char **lock_file)
Definition: devfunc.c:347
char Manufacturer[GSM_MAX_MANUFACTURER_LENGTH+1]
Definition: gsmstate.h:441
GSM_PhoneModel * ModelInfo
Definition: gsmstate.h:449
GSM_Phone Phone
Definition: gsmstate.h:1431
GSM_Device_Functions * Functions
Definition: gsmstate.h:335
GSM_Protocol Protocol
Definition: gsmstate.h:1430
GSM_Phone_Data Data
Definition: gsmstate.h:1369
GSM_Error(* Terminate)(GSM_StateMachine *s)
Definition: gsmstate.h:360
double VerNum
Definition: gsmstate.h:462
GSM_Protocol_Functions * Functions
Definition: gsmstate.h:424
char Model[GSM_MAX_MODEL_LENGTH+1]
Definition: gsmstate.h:445
GSM_Device Device
Definition: gsmstate.h:1429
int smprintf(GSM_StateMachine *s, const char *format,...)
Definition: debug.c:261

§ GSM_DumpMessageBinary_Custom()

void GSM_DumpMessageBinary_Custom ( GSM_StateMachine s,
unsigned const char *  message,
size_t  messagesize,
int  type,
int  direction 
)

Definition at line 1565 of file gsmstate.c.

References _GSM_Debug_Info::dl, DL_BINARY, GSM_GetDI(), and smprintf().

Referenced by GSM_DumpMessageBinary(), and GSM_DumpMessageBinaryRecv().

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 }
GSM_Debug_Info * GSM_GetDI(GSM_StateMachine *s)
Definition: gsmstate.c:70
Debug_Level dl
Definition: debug.h:35
int smprintf(GSM_StateMachine *s, const char *format,...)
Definition: debug.c:261

§ GSM_DumpMessageText_Custom()

void GSM_DumpMessageText_Custom ( GSM_StateMachine s,
unsigned const char *  message,
size_t  messagesize,
int  type,
const char *  text 
)

Definition at line 1538 of file gsmstate.c.

References _GSM_Debug_Info::dl, DL_TEXT, DL_TEXTALL, DL_TEXTALLDATE, DL_TEXTDATE, DumpMessage(), GSM_GetDI(), and smprintf().

Referenced by GSM_DumpMessageText(), and GSM_DumpMessageTextRecv().

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 }
void DumpMessage(GSM_Debug_Info *d, const unsigned char *message, const size_t messagesize)
Definition: debug.c:314
GSM_Debug_Info * GSM_GetDI(GSM_StateMachine *s)
Definition: gsmstate.c:70
Definition: debug.h:26
Debug_Level dl
Definition: debug.h:35
int smprintf(GSM_StateMachine *s, const char *format,...)
Definition: debug.c:261

§ GSM_ExpandUserPath()

void GSM_ExpandUserPath ( char **  string)

Expand path to user home.

Definition at line 1326 of file gsmstate.c.

Referenced by GSM_ReadConfig().

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 }

§ GSM_OpenConnection()

GSM_Error GSM_OpenConnection ( GSM_StateMachine s)

Opens connection to device and initiates protocol layer.

Definition at line 560 of file gsmstate.c.

References _GSM_StateMachine::CurrentConfig, GSM_Config::Device, _GSM_StateMachine::Device, ERR_NONE, GSM_Device::Functions, GSM_Protocol::Functions, GSM_Protocol_Functions::Initialise, lock_device(), GSM_Config::LockDevice, _GSM_StateMachine::LockFile, GSM_Device_Functions::OpenDevice, _GSM_StateMachine::opened, _GSM_StateMachine::Protocol, TRUE, and unlock_device().

Referenced by GSM_InitConnection_Log(), and GSM_TryGetModel().

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 }
GSM_Config * CurrentConfig
Definition: gsmstate.h:1415
GSM_Error
Definition: gammu-error.h:23
gboolean LockDevice
gboolean unlock_device(GSM_StateMachine *s, char **lock_file)
Definition: devfunc.c:347
GSM_Error(* OpenDevice)(GSM_StateMachine *s)
Definition: gsmstate.h:232
GSM_Error(* Initialise)(GSM_StateMachine *s)
Definition: gsmstate.h:356
GSM_Device_Functions * Functions
Definition: gsmstate.h:335
gboolean opened
Definition: gsmstate.h:1413
GSM_Protocol Protocol
Definition: gsmstate.h:1430
GSM_Protocol_Functions * Functions
Definition: gsmstate.h:424
#define TRUE
Definition: gammu-types.h:28
GSM_Device Device
Definition: gsmstate.h:1429
GSM_Error lock_device(GSM_StateMachine *s, const char *port, char **lock_name)
Definition: devfunc.c:212

§ GSM_RegisterAllConnections()

static GSM_Error GSM_RegisterAllConnections ( GSM_StateMachine s,
const char *  connection 
)
static

Definition at line 197 of file gsmstate.c.

References GSM_ConnectionInfo::Connection, _GSM_StateMachine::ConnectionType, _GSM_StateMachine::Device, ERR_DISABLED, ERR_MOREMEMORY, ERR_NONE, ERR_UNKNOWNCONNECTIONTYPESTRING, FALSE, FindSerialSpeed(), GSM_Device::Functions, GSM_Protocol::Functions, GCT_AT, GCT_BLUEAT, GCT_BLUEFBUS2, GCT_BLUEGNAPBUS, GCT_BLUEOBEX, GCT_BLUEPHONET, GCT_BLUES60, GCT_DKU2AT, GCT_DKU2PHONET, GCT_DKU5FBUS2, GCT_FBUS2, GCT_FBUS2BLUE, GCT_FBUS2DLR3, GCT_FBUS2IRDA, GCT_FBUS2PL2303, GCT_FBUS2USB, GCT_IRDAAT, GCT_IRDAGNAPBUS, GCT_IRDAOBEX, GCT_IRDAPHONET, GCT_MBUS2, GCT_NONE, GCT_PHONETBLUE, GCT_PROXYAT, GCT_PROXYFBUS2, GCT_PROXYGNAPBUS, GCT_PROXYOBEX, GCT_PROXYPHONET, GCT_PROXYS60, GSM_Connections, GSM_RegisterConnection(), _GSM_StateMachine::NoPowerCable, _GSM_StateMachine::Protocol, ProxyDevice, GSM_ConnectionInfo::SkipDtrRts, _GSM_StateMachine::SkipDtrRts, smprintf(), _GSM_StateMachine::Speed, and TRUE.

Referenced by GSM_InitConnection_Log().

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) {
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;
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 }
GSM_ConnectionType ConnectionType
Definition: gsmstate.h:1402
int FindSerialSpeed(const char *buffer)
Definition: devfunc.c:367
static void GSM_RegisterConnection(GSM_StateMachine *s, unsigned int connection, GSM_Device_Functions *device, GSM_Protocol_Functions *protocol)
Definition: gsmstate.c:81
gboolean SkipDtrRts
Definition: gsmstate.c:105
static const GSM_ConnectionInfo GSM_Connections[]
Definition: gsmstate.c:111
#define FALSE
Definition: gammu-types.h:25
GSM_Device_Functions NoneDevice
Definition: gsmstate.c:180
GSM_Protocol_Functions NoProtocol
Definition: gsmstate.c:190
GSM_Device_Functions * Functions
Definition: gsmstate.h:335
GSM_Protocol Protocol
Definition: gsmstate.h:1430
GSM_Device_Functions ProxyDevice
Definition: proxy.c:212
const GSM_ConnectionType Connection
Definition: gsmstate.c:101
gboolean NoPowerCable
Definition: gsmstate.h:1410
gboolean SkipDtrRts
Definition: gsmstate.h:1406
GSM_Protocol_Functions * Functions
Definition: gsmstate.h:424
#define TRUE
Definition: gammu-types.h:28
GSM_Device Device
Definition: gsmstate.h:1429
int smprintf(GSM_StateMachine *s, const char *format,...)
Definition: debug.c:261

§ GSM_RegisterConnection()

static void GSM_RegisterConnection ( GSM_StateMachine s,
unsigned int  connection,
GSM_Device_Functions device,
GSM_Protocol_Functions protocol 
)
static

Definition at line 81 of file gsmstate.c.

References _GSM_StateMachine::ConnectionType, _GSM_StateMachine::Device, GSM_Device::Functions, GSM_Protocol::Functions, and _GSM_StateMachine::Protocol.

Referenced by GSM_RegisterAllConnections().

83 {
84  if ((unsigned int)s->ConnectionType == connection) {
85  s->Device.Functions = device;
86  s->Protocol.Functions = protocol;
87  }
88 }
GSM_ConnectionType ConnectionType
Definition: gsmstate.h:1402
GSM_Device_Functions * Functions
Definition: gsmstate.h:335
GSM_Protocol Protocol
Definition: gsmstate.h:1430
GSM_Protocol_Functions * Functions
Definition: gsmstate.h:424
GSM_Device Device
Definition: gsmstate.h:1429

§ GSM_RegisterModule()

static void GSM_RegisterModule ( GSM_StateMachine s,
GSM_Phone_Functions phone 
)
static

Definition at line 360 of file gsmstate.c.

References _GSM_StateMachine::CurrentConfig, GSM_Phone::Data, GSM_Phone::Functions, GetModelData(), GSM_Config::Model, GSM_Phone_Data::Model, GSM_PhoneModel::model, GSM_Phone_Functions::models, _GSM_StateMachine::Phone, and smprintf().

Referenced by GSM_RegisterAllPhoneModules().

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 }
GSM_Config * CurrentConfig
Definition: gsmstate.h:1415
const char * model
Definition: gammu-info.h:764
const char * models
Definition: gsmstate.h:743
GSM_PhoneModel * GetModelData(GSM_StateMachine *s, const char *model, const char *number, const char *irdamodel)
Definition: gsmphones.c:1002
GSM_Phone Phone
Definition: gsmstate.h:1431
GSM_Phone_Data Data
Definition: gsmstate.h:1369
GSM_Phone_Functions * Functions
Definition: gsmstate.h:1373
char Model[GSM_MAX_MODEL_LENGTH+1]
Definition: gsmstate.h:445
int smprintf(GSM_StateMachine *s, const char *format,...)
Definition: debug.c:261

§ GSM_TryGetModel()

GSM_Error GSM_TryGetModel ( GSM_StateMachine s)

Tries to read model using configured phone connection.

Definition at line 623 of file gsmstate.c.

References _GSM_StateMachine::ConnectionType, GSM_Phone::Data, DUMMYPhone, ERR_NONE, ERR_UNKNOWN, GSM_Phone::Functions, GCT_AT, GCT_BLUEAT, GCT_BLUEFBUS2, GCT_BLUEGNAPBUS, GCT_BLUEOBEX, GCT_BLUEPHONET, GCT_BLUES60, GCT_DKU2AT, GCT_DKU2PHONET, GCT_DKU5FBUS2, GCT_FBUS2, GCT_FBUS2BLUE, GCT_FBUS2DLR3, GCT_FBUS2IRDA, GCT_FBUS2PL2303, GCT_FBUS2USB, GCT_IRDAAT, GCT_IRDAGNAPBUS, GCT_IRDAOBEX, GCT_IRDAPHONET, GCT_MBUS2, GCT_NONE, GCT_PHONETBLUE, GCT_PROXYAT, GCT_PROXYFBUS2, GCT_PROXYGNAPBUS, GCT_PROXYOBEX, GCT_PROXYPHONET, GCT_PROXYS60, GSM_Phone_Functions::GetModel, GSM_OpenConnection(), GSM_Phone_Functions::Initialise, GSM_Phone_Data::Model, NAUTOPhone, _GSM_StateMachine::Phone, smprintf(), and GSM_Phone_Functions::Terminate.

Referenced by GSM_InitConnection_Log().

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 }
GSM_Error(* Terminate)(GSM_StateMachine *s)
Definition: gsmstate.h:760
GSM_Error GSM_OpenConnection(GSM_StateMachine *s)
Definition: gsmstate.c:560
GSM_Phone_Functions NAUTOPhone
GSM_ConnectionType ConnectionType
Definition: gsmstate.h:1402
GSM_Error
Definition: gammu-error.h:23
GSM_Error(* GetModel)(GSM_StateMachine *s)
Definition: gsmstate.h:777
GSM_Phone Phone
Definition: gsmstate.h:1431
GSM_Phone_Data Data
Definition: gsmstate.h:1369
GSM_Phone_Functions * Functions
Definition: gsmstate.h:1373
GSM_Error(* Initialise)(GSM_StateMachine *s)
Definition: gsmstate.h:756
GSM_Phone_Functions DUMMYPhone
Definition: dummy.c:1964
char Model[GSM_MAX_MODEL_LENGTH+1]
Definition: gsmstate.h:445
int smprintf(GSM_StateMachine *s, const char *format,...)
Definition: debug.c:261

§ GSM_TryReadGammuRC()

GSM_Error GSM_TryReadGammuRC ( const char *  path,
INI_Section **  result 
)

Definition at line 1203 of file gsmstate.c.

References dbgprintf, FALSE, and INI_ReadFile().

Referenced by GSM_FindGammuRC().

1204 {
1205  dbgprintf(NULL, "Open config: \"%s\"\n", path);
1206  return INI_ReadFile(path, FALSE, result);
1207 }
#define FALSE
Definition: gammu-types.h:25
GSM_Error INI_ReadFile(const char *FileName, gboolean Unicode, INI_Section **result)
Definition: cfg.c:24
#define dbgprintf
Definition: debug.h:72

Variable Documentation

§ GSM_Connections

const GSM_ConnectionInfo GSM_Connections[]
static

Mapping of connection names to internal identifications.

Definition at line 111 of file gsmstate.c.

Referenced by GSM_RegisterAllConnections().

§ NoneDevice

Initial value:

Definition at line 180 of file gsmstate.c.

§ NoProtocol

Initial value:
= {
NONEFUNCTION
}
#define NONEFUNCTION
Definition: gsmcomon.h:12

Definition at line 190 of file gsmstate.c.