Gammu internals  1.38.0
State machine

Data Structures

struct  GSM_Reply_Function
 
struct  GSM_Device_Functions
 
struct  GSM_Device
 
struct  GSM_Protocol_Functions
 
struct  GSM_Protocol
 
struct  GSM_Phone_Data
 
struct  GSM_Phone_Functions
 
struct  GSM_Phone
 
struct  _GSM_User
 
struct  _GSM_StateMachine
 
struct  GSM_Config
 

Macros

#define GSM_ENABLE_SERIALDEVICE
 
#define GSM_ENABLE_IRDADEVICE
 
#define MAX_CONFIG_NUM   5
 
#define GSM_WaitForAutoLen(s, buffer, type, timeout, request)   GSM_WaitFor(s,buffer,strlen(buffer),type,timeout,request)
 

Typedefs

typedef struct _GSM_User GSM_User
 
typedef struct _GSM_StateMachine GSM_StateMachine
 

Enumerations

enum  GSM_Phone_RequestID {
  ID_None =1, ID_GetModel, ID_GetFirmware, ID_EnableSecurity,
  ID_OpenFile, ID_CloseFile, ID_GetIMEI, ID_GetDateTime,
  ID_GetAlarm, ID_GetMemory, ID_GetMemoryStatus, ID_GetSMSC,
  ID_GetSMSMessage, ID_EnableEcho, ID_EnableErrorInfo, ID_SetOBEX,
  ID_SetUSSD, ID_GetUSSD, ID_GetNote, ID_SetNote,
  ID_GetSignalQuality, ID_GetBatteryCharge, ID_GetSMSFolders, ID_GetSMSFolderStatus,
  ID_GetSMSStatus, ID_AddSMSFolder, ID_ConfigureNetworkInfo, ID_GetNetworkInfo,
  ID_GetNetworkCode, ID_GetNetworkName, ID_GetRingtone, ID_DialVoice,
  ID_GetCalendarNotesInfo, ID_GetCalendarNote, ID_GetSecurityCode, ID_GetWAPBookmark,
  ID_GetBitmap, ID_GetCRC, ID_SetAttrib, ID_SaveSMSMessage,
  ID_CancelCall, ID_SetDateTime, ID_SetAlarm, ID_DisableConnectFunc,
  ID_EnableConnectFunc, ID_AnswerCall, ID_SetBitmap, ID_SetRingtone,
  ID_DeleteSMSMessage, ID_DeleteCalendarNote, ID_SetPath, ID_SetSMSC,
  ID_SetProfile, ID_SetMemory, ID_DeleteMemory, ID_SetCalendarNote,
  ID_AddCalendarNote, ID_SetIncomingSMS, ID_SetIncomingCB, ID_SetIncomingCall,
  ID_GetCNMIMode, ID_GetCalendarNotePos, ID_Initialise, ID_Terminate,
  ID_GetConnectSet, ID_SetWAPBookmark, ID_GetLocale, ID_SetLocale,
  ID_GetCalendarSettings, ID_SetCalendarSettings, ID_GetGPRSPoint, ID_GetGPRSState,
  ID_SetGPRSPoint, ID_EnableGPRSPoint, ID_DeleteWAPBookmark, ID_Netmonitor,
  ID_HoldCall, ID_UnholdCall, ID_ConferenceCall, ID_SplitCall,
  ID_TransferCall, ID_SwitchCall, ID_GetManufactureMonth, ID_GetProductCode,
  ID_GetOriginalIMEI, ID_GetHardware, ID_GetPPM, ID_GetSMSMode,
  ID_GetSMSMemories, ID_GetManufacturer, ID_SetMemoryType, ID_GetMemoryCharset,
  ID_SetMemoryCharset, ID_SetSMSParameters, ID_GetFMStation, ID_SetFMStation,
  ID_GetLanguage, ID_SetFastSMSSending, ID_Reset, ID_GetToDoInfo,
  ID_GetToDo, ID_PressKey, ID_DeleteAllToDo, ID_SetLight,
  ID_Divert, ID_SetDivert, ID_SetToDo, ID_AddToDo,
  ID_PlayTone, ID_GetChatSettings, ID_GetSyncMLSettings, ID_GetSyncMLName,
  ID_GetSecurityStatus, ID_EnterSecurityCode, ID_GetProfile, ID_GetRingtonesInfo,
  ID_MakeAuthentication, ID_GetSpeedDial, ID_ResetPhoneSettings, ID_SendDTMF,
  ID_GetDisplayStatus, ID_SetAutoNetworkLogin, ID_SetConnectSet, ID_GetSIMIMSI,
  ID_GetFileInfo, ID_FileSystemStatus, ID_GetFile, ID_AddFile,
  ID_AddFolder, ID_DeleteFolder, ID_DeleteFile, ID_ModeSwitch,
  ID_GetProtocol, ID_Screenshot, ID_GetScreenSize, ID_SetFlowControl,
  ID_AlcatelConnect, ID_AlcatelProtocol, ID_AlcatelAttach, ID_AlcatelDetach,
  ID_AlcatelCommit, ID_AlcatelCommit2, ID_AlcatelEnd, ID_AlcatelClose,
  ID_AlcatelStart, ID_AlcatelSelect1, ID_AlcatelSelect2, ID_AlcatelSelect3,
  ID_AlcatelBegin1, ID_AlcatelBegin2, ID_AlcatelGetIds1, ID_AlcatelGetIds2,
  ID_AlcatelGetCategories1, ID_AlcatelGetCategories2, ID_AlcatelGetCategoryText1, ID_AlcatelGetCategoryText2,
  ID_AlcatelAddCategoryText1, ID_AlcatelAddCategoryText2, ID_AlcatelGetFields1, ID_AlcatelGetFields2,
  ID_AlcatelGetFieldValue1, ID_AlcatelGetFieldValue2, ID_AlcatelDeleteItem1, ID_AlcatelDeleteItem2,
  ID_AlcatelDeleteField, ID_AlcatelCreateField, ID_AlcatelUpdateField, ID_SetPower,
  ID_IncomingFrame, ID_User1, ID_User2, ID_User3,
  ID_User4, ID_User5, ID_User6, ID_User7,
  ID_User8, ID_User9, ID_User10, ID_All,
  ID_EachFrame
}
 

Functions

GSM_Error GSM_RegisterAllPhoneModules (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) WARNUNUSED
 
GSM_Error GSM_DispatchMessage (GSM_StateMachine *s)
 
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 (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)
 
GSM_Debug_InfoGSM_GetDebug (GSM_StateMachine *s)
 
GSM_Debug_InfoGSM_GetDI (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)
 
GSM_Error GSM_TerminateConnection (GSM_StateMachine *s)
 
GSM_Error GSM_AbortOperation (GSM_StateMachine *s)
 
int GSM_ReadDevice (GSM_StateMachine *s, gboolean waitforreply)
 
gboolean GSM_IsConnected (GSM_StateMachine *s)
 
GSM_Error GSM_FindGammuRC (INI_Section **result, const char *force_config)
 
GSM_Error GSM_ReadConfig (INI_Section *cfg_info, GSM_Config *cfg, int num)
 
GSM_ConfigGSM_GetConfig (GSM_StateMachine *s, int num)
 
int GSM_GetConfigNum (const GSM_StateMachine *s)
 
void GSM_SetConfigNum (GSM_StateMachine *s, int sections)
 
GSM_StateMachineGSM_AllocStateMachine (void)
 
void GSM_FreeStateMachine (GSM_StateMachine *s)
 
GSM_ConnectionType GSM_GetUsedConnection (GSM_StateMachine *s)
 
GSM_Error GSM_Install (GSM_StateMachine *s, const char *ExtraPath, gboolean Minimal)
 

Variables

GSM_Device_Functions ProxyDevice
 
GSM_Phone_Functions NAUTOPhone
 
GSM_Phone_Functions DUMMYPhone
 

Detailed Description

Generic state machine layer.

Macro Definition Documentation

§ GSM_ENABLE_IRDADEVICE

#define GSM_ENABLE_IRDADEVICE

Definition at line 172 of file gsmstate.h.

§ GSM_ENABLE_SERIALDEVICE

#define GSM_ENABLE_SERIALDEVICE

Definition at line 162 of file gsmstate.h.

§ GSM_WaitForAutoLen

#define GSM_WaitForAutoLen (   s,
  buffer,
  type,
  timeout,
  request 
)    GSM_WaitFor(s,buffer,strlen(buffer),type,timeout,request)

Wait for reply from the phone for ASCII strings without given length. This is just a convenience wrapper around GSM_WaitFor which fills in length.

Parameters
sState machine pointer.
bufferData to write to phone.
typeType of request (for protocols where it makes sense).
timeoutHow long to wait for reply.
requestID of request
Returns
Error code, ERR_NONE on sucecss.

Definition at line 1478 of file gsmstate.h.

§ MAX_CONFIG_NUM

#define MAX_CONFIG_NUM   5

Maximum number of concurrent configurations.

Definition at line 1399 of file gsmstate.h.

Referenced by GSM_FreeStateMachine(), GSM_GetConfig(), and GSM_SetConfigNum().

Typedef Documentation

§ GSM_StateMachine

Private structure holding information about phone connection. Should be allocated by GSM_AllocStateMachine and freed by GSM_FreeStateMachine.

Definition at line 40 of file gammu-statemachine.h.

§ GSM_User

typedef struct _GSM_User GSM_User

Definition at line 32 of file gsmstate.h.

Enumeration Type Documentation

§ GSM_Phone_RequestID

Phone requests identificators, these are used for internally identifying which operation is being performed.

Enumerator
ID_None 
ID_GetModel 
ID_GetFirmware 
ID_EnableSecurity 
ID_OpenFile 
ID_CloseFile 
ID_GetIMEI 
ID_GetDateTime 
ID_GetAlarm 
ID_GetMemory 
ID_GetMemoryStatus 
ID_GetSMSC 
ID_GetSMSMessage 
ID_EnableEcho 
ID_EnableErrorInfo 
ID_SetOBEX 
ID_SetUSSD 
ID_GetUSSD 
ID_GetNote 
ID_SetNote 
ID_GetSignalQuality 
ID_GetBatteryCharge 
ID_GetSMSFolders 
ID_GetSMSFolderStatus 
ID_GetSMSStatus 
ID_AddSMSFolder 
ID_ConfigureNetworkInfo 
ID_GetNetworkInfo 
ID_GetNetworkCode 
ID_GetNetworkName 
ID_GetRingtone 
ID_DialVoice 
ID_GetCalendarNotesInfo 
ID_GetCalendarNote 
ID_GetSecurityCode 
ID_GetWAPBookmark 
ID_GetBitmap 
ID_GetCRC 
ID_SetAttrib 
ID_SaveSMSMessage 
ID_CancelCall 
ID_SetDateTime 
ID_SetAlarm 
ID_DisableConnectFunc 
ID_EnableConnectFunc 
ID_AnswerCall 
ID_SetBitmap 
ID_SetRingtone 
ID_DeleteSMSMessage 
ID_DeleteCalendarNote 
ID_SetPath 
ID_SetSMSC 
ID_SetProfile 
ID_SetMemory 
ID_DeleteMemory 
ID_SetCalendarNote 
ID_AddCalendarNote 
ID_SetIncomingSMS 
ID_SetIncomingCB 
ID_SetIncomingCall 
ID_GetCNMIMode 
ID_GetCalendarNotePos 
ID_Initialise 
ID_Terminate 
ID_GetConnectSet 
ID_SetWAPBookmark 
ID_GetLocale 
ID_SetLocale 
ID_GetCalendarSettings 
ID_SetCalendarSettings 
ID_GetGPRSPoint 
ID_GetGPRSState 
ID_SetGPRSPoint 
ID_EnableGPRSPoint 
ID_DeleteWAPBookmark 
ID_Netmonitor 
ID_HoldCall 
ID_UnholdCall 
ID_ConferenceCall 
ID_SplitCall 
ID_TransferCall 
ID_SwitchCall 
ID_GetManufactureMonth 
ID_GetProductCode 
ID_GetOriginalIMEI 
ID_GetHardware 
ID_GetPPM 
ID_GetSMSMode 
ID_GetSMSMemories 
ID_GetManufacturer 
ID_SetMemoryType 
ID_GetMemoryCharset 
ID_SetMemoryCharset 
ID_SetSMSParameters 
ID_GetFMStation 
ID_SetFMStation 
ID_GetLanguage 
ID_SetFastSMSSending 
ID_Reset 
ID_GetToDoInfo 
ID_GetToDo 
ID_PressKey 
ID_DeleteAllToDo 
ID_SetLight 
ID_Divert 
ID_SetDivert 
ID_SetToDo 
ID_AddToDo 
ID_PlayTone 
ID_GetChatSettings 
ID_GetSyncMLSettings 
ID_GetSyncMLName 
ID_GetSecurityStatus 
ID_EnterSecurityCode 
ID_GetProfile 
ID_GetRingtonesInfo 
ID_MakeAuthentication 
ID_GetSpeedDial 
ID_ResetPhoneSettings 
ID_SendDTMF 
ID_GetDisplayStatus 
ID_SetAutoNetworkLogin 
ID_SetConnectSet 
ID_GetSIMIMSI 
ID_GetFileInfo 
ID_FileSystemStatus 
ID_GetFile 
ID_AddFile 
ID_AddFolder 
ID_DeleteFolder 
ID_DeleteFile 
ID_ModeSwitch 
ID_GetProtocol 
ID_Screenshot 
ID_GetScreenSize 
ID_SetFlowControl 
ID_AlcatelConnect 
ID_AlcatelProtocol 
ID_AlcatelAttach 
ID_AlcatelDetach 
ID_AlcatelCommit 
ID_AlcatelCommit2 
ID_AlcatelEnd 
ID_AlcatelClose 
ID_AlcatelStart 
ID_AlcatelSelect1 
ID_AlcatelSelect2 
ID_AlcatelSelect3 
ID_AlcatelBegin1 
ID_AlcatelBegin2 
ID_AlcatelGetIds1 
ID_AlcatelGetIds2 
ID_AlcatelGetCategories1 
ID_AlcatelGetCategories2 
ID_AlcatelGetCategoryText1 
ID_AlcatelGetCategoryText2 
ID_AlcatelAddCategoryText1 
ID_AlcatelAddCategoryText2 
ID_AlcatelGetFields1 
ID_AlcatelGetFields2 
ID_AlcatelGetFieldValue1 
ID_AlcatelGetFieldValue2 
ID_AlcatelDeleteItem1 
ID_AlcatelDeleteItem2 
ID_AlcatelDeleteField 
ID_AlcatelCreateField 
ID_AlcatelUpdateField 
ID_SetPower 
ID_IncomingFrame 
ID_User1 
ID_User2 
ID_User3 
ID_User4 
ID_User5 
ID_User6 
ID_User7 
ID_User8 
ID_User9 
ID_User10 
ID_All 
ID_EachFrame 

Definition at line 25 of file gsmreply.h.

25  {
26  ID_None=1,
32  ID_GetIMEI,
37  ID_GetSMSC,
41  ID_SetOBEX,
42  ID_SetUSSD,
43  ID_GetUSSD,
44  ID_GetNote,
45  ID_SetNote,
63  ID_GetCRC,
76  ID_SetPath,
77  ID_SetSMSC,
102  ID_HoldCall,
105  ID_SplitCall,
112  ID_GetPPM,
124  ID_Reset,
126  ID_GetToDo,
127  ID_PressKey,
129  ID_SetLight,
130  ID_Divert,
131  ID_SetDivert,
132  ID_SetToDo,
133  ID_AddToDo,
134  ID_PlayTone,
145  ID_SendDTMF,
152  ID_GetFile,
153  ID_AddFile,
154  ID_AddFolder,
161 
162  /* Alcatel AT mode */
166 
167  /* Alcatel Binary mode */
197 
198  ID_SetPower,
199 
201 
202  ID_User1,
203  ID_User2,
204  ID_User3,
205  ID_User4,
206  ID_User5,
207  ID_User6,
208  ID_User7,
209  ID_User8,
210  ID_User9,
211  ID_User10,
212 
213  ID_All,
GSM_Phone_RequestID
Definition: gsmreply.h:25

Function Documentation

§ GSM_AbortOperation()

GSM_Error GSM_AbortOperation ( GSM_StateMachine s)

Aborts current operation.

This is thread safe call to abort any existing operations with the phone.

Parameters
sState machine data
Returns
Error code

Definition at line 980 of file gsmstate.c.

References _GSM_StateMachine::Abort, ERR_NONE, and TRUE.

981 {
982  s->Abort = TRUE;
983  return ERR_NONE;
984 }
volatile gboolean Abort
Definition: gsmstate.h:1423
#define TRUE
Definition: gammu-types.h:28

§ GSM_AllocStateMachine()

GSM_StateMachine* GSM_AllocStateMachine ( void  )

Allocates new clean state machine structure. You should free it then by GSM_FreeStateMachine.

Returns
Pointer to state machine structure.

Definition at line 1677 of file gsmstate.c.

References _GSM_StateMachine::Abort, _GSM_StateMachine::Config, _GSM_StateMachine::CurrentConfig, and FALSE.

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 }
GSM_Config * CurrentConfig
Definition: gsmstate.h:1415
GSM_Config Config[MAX_CONFIG_NUM+1]
Definition: gsmstate.h:1414
volatile gboolean Abort
Definition: gsmstate.h:1423
#define FALSE
Definition: gammu-types.h:25

§ GSM_DispatchMessage()

GSM_Error GSM_DispatchMessage ( GSM_StateMachine s)

Definition at line 1131 of file gsmstate.c.

References GSM_Protocol_Message::Buffer, CheckReplyFunctions(), D_ERROR, GSM_Phone::Data, DumpMessage(), ERR_FRAMENOTREQUESTED, ERR_NEEDANOTHERANSWER, ERR_NONE, ERR_TIMEOUT, ERR_UNKNOWNFRAME, ERR_UNKNOWNRESPONSE, FALSE, GSM_Reply_Function::Function, GSM_Phone::Functions, GSM_DumpMessageBinaryRecv(), GSM_DumpMessageTextRecv(), GSM_GetDI(), ID_None, GSM_Protocol_Message::Length, _GSM_StateMachine::MessagesCount, GSM_Phone_Functions::models, _GSM_StateMachine::Phone, GSM_Phone_Functions::ReplyFunctions, GSM_Phone_Data::RequestID, GSM_Phone_Data::RequestMsg, GSM_Phone_Data::SentMsg, smprintf(), smprintf_level(), TRUE, GSM_Protocol_Message::Type, _GSM_StateMachine::User, and _GSM_User::UserReplyFunctions.

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 }
void DumpMessage(GSM_Debug_Info *d, const unsigned char *message, const size_t messagesize)
Definition: debug.c:314
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_Debug_Info * GSM_GetDI(GSM_StateMachine *s)
Definition: gsmstate.c:70
GSM_Error(* Function)(GSM_Protocol_Message *msg, GSM_StateMachine *s)
Definition: gsmreply.h:231
GSM_Error
Definition: gammu-error.h:23
static GSM_Error CheckReplyFunctions(GSM_StateMachine *s, GSM_Reply_Function *Reply, int *reply)
Definition: gsmstate.c:1077
int smprintf_level(GSM_StateMachine *s, GSM_DebugSeverity severity, const char *format,...)
Definition: debug.c:278
int gboolean
Definition: gammu-types.h:23
const char * models
Definition: gsmstate.h:743
GSM_Phone Phone
Definition: gsmstate.h:1431
#define FALSE
Definition: gammu-types.h:25
GSM_Protocol_Message * SentMsg
Definition: gsmstate.h:680
GSM_Phone_RequestID RequestID
Definition: gsmstate.h:685
GSM_Phone_Data Data
Definition: gsmstate.h:1369
GSM_Phone_Functions * Functions
Definition: gsmstate.h:1373
GSM_Reply_Function * ReplyFunctions
Definition: gsmstate.h:748
void GSM_DumpMessageBinaryRecv(GSM_StateMachine *s, unsigned const char *message, size_t messagesize, int type)
Definition: gsmstate.c:1588
#define TRUE
Definition: gammu-types.h:28
unsigned char * Buffer
Definition: protocol.h:22
GSM_Protocol_Message * RequestMsg
Definition: gsmstate.h:676
volatile size_t MessagesCount
Definition: gsmstate.h:1427
Definition: debug.h:91
int smprintf(GSM_StateMachine *s, const char *format,...)
Definition: debug.c:261

§ GSM_DumpMessageBinary()

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

Definition at line 1583 of file gsmstate.c.

References GSM_DumpMessageBinary_Custom().

1584 {
1585  GSM_DumpMessageBinary_Custom(s, message, messagesize, type, 0x01);
1586 }
void GSM_DumpMessageBinary_Custom(GSM_StateMachine *s, unsigned const char *message, size_t messagesize, int type, int direction)
Definition: gsmstate.c:1565

§ GSM_DumpMessageBinaryRecv()

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

Definition at line 1588 of file gsmstate.c.

References GSM_DumpMessageBinary_Custom().

Referenced by GSM_DispatchMessage().

1589 {
1590  GSM_DumpMessageBinary_Custom(s, message, messagesize, type, 0x02);
1591 }
void GSM_DumpMessageBinary_Custom(GSM_StateMachine *s, unsigned const char *message, size_t messagesize, int type, int direction)
Definition: gsmstate.c:1565

§ GSM_DumpMessageText()

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

Definition at line 1555 of file gsmstate.c.

References GSM_DumpMessageText_Custom().

1556 {
1557  GSM_DumpMessageText_Custom(s, message, messagesize, type, "SENDING frame");
1558 }
void GSM_DumpMessageText_Custom(GSM_StateMachine *s, unsigned const char *message, size_t messagesize, int type, const char *text)
Definition: gsmstate.c:1538

§ GSM_DumpMessageTextRecv()

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

Definition at line 1560 of file gsmstate.c.

References GSM_DumpMessageText_Custom().

Referenced by GSM_DispatchMessage().

1561 {
1562  GSM_DumpMessageText_Custom(s, message, messagesize, type, "RECEIVED frame");
1563 }
void GSM_DumpMessageText_Custom(GSM_StateMachine *s, unsigned const char *message, size_t messagesize, int type, const char *text)
Definition: gsmstate.c:1538

§ GSM_FindGammuRC()

GSM_Error GSM_FindGammuRC ( INI_Section **  result,
const char *  force_config 
)

Finds and reads gammu configuration file. The search order depends on platform. On POSIX systems it looks for ~/.gammurc and then for /etc/gammurc, on Windows for gammurc in Application data folder, then in home and last fallback is in current driectory.

Parameters
resultIni file representation
force_configForcing of custom path instead of autodetected one (if NULL, autodetection is performed).
Returns
Error code

Definition at line 1209 of file gsmstate.c.

References ERR_NONE, FALLBACK_GAMMURC, GAMMURC_NAME, GSM_TryReadGammuRC(), PATH_MAX, and XDG_GAMMURC_NAME.

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 }
#define PATH_MAX
Definition: dummy.h:31
GSM_Error
Definition: gammu-error.h:23
#define FALLBACK_GAMMURC
Definition: gsmstate.c:42
GSM_Error GSM_TryReadGammuRC(const char *path, INI_Section **result)
Definition: gsmstate.c:1203
#define GAMMURC_NAME
Definition: gsmstate.c:43
#define XDG_GAMMURC_NAME
Definition: gsmstate.c:45

§ GSM_FreeStateMachine()

void GSM_FreeStateMachine ( GSM_StateMachine s)

Frees state machine structure allocated by GSM_AllocStateMachine.

Parameters
sPointer to state machine structure.

Definition at line 1689 of file gsmstate.c.

References _GSM_StateMachine::Config, GSM_Config::Connection, GSM_Config::DebugFile, GSM_Config::Device, and MAX_CONFIG_NUM.

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 }
GSM_Config Config[MAX_CONFIG_NUM+1]
Definition: gsmstate.h:1414
#define MAX_CONFIG_NUM
Definition: gsmstate.h:1399

§ GSM_GetConfig()

GSM_Config* GSM_GetConfig ( GSM_StateMachine s,
int  num 
)

Gets gammu configuration from state machine. This actually returns pointer to internal configuration storage, so you can use it also for updating existing settings.

Parameters
sState machine data
numNumber of section to read, -1 for currently used.
Returns
Pointer to configuration.

Definition at line 1301 of file gsmstate.c.

References _GSM_StateMachine::Config, _GSM_StateMachine::CurrentConfig, and MAX_CONFIG_NUM.

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 }
GSM_Config * CurrentConfig
Definition: gsmstate.h:1415
GSM_Config Config[MAX_CONFIG_NUM+1]
Definition: gsmstate.h:1414
#define MAX_CONFIG_NUM
Definition: gsmstate.h:1399

§ GSM_GetConfigNum()

int GSM_GetConfigNum ( const GSM_StateMachine s)

Gets number of active gammu configurations.

Parameters
sState machine data
Returns
Number of sections.

Definition at line 1312 of file gsmstate.c.

References _GSM_StateMachine::ConfigNum.

1313 {
1314  return s->ConfigNum;
1315 }

§ GSM_GetDebug()

GSM_Debug_Info* GSM_GetDebug ( GSM_StateMachine s)

Gets debug information for state machine.

Parameters
sState machine data
Returns
Debug information.

Definition at line 1719 of file gsmstate.c.

References _GSM_StateMachine::di.

1720 {
1721  return s == NULL ? NULL : &(s->di);
1722 }
GSM_Debug_Info di
Definition: gsmstate.h:1412

§ GSM_GetDI()

GSM_Debug_Info* GSM_GetDI ( GSM_StateMachine s)

Returns debug information active for state machine. Please note that it can be either global debug or state machine debug structure, depending on use_global flag. For configuring usite GSM_GetDebug.

Parameters
sState machine data
Returns
Debug information.

Returns current debuging descriptor. It honors use_global flag.

Definition at line 70 of file gsmstate.c.

References _GSM_StateMachine::di, FALSE, GSM_global_debug, and _GSM_Debug_Info::use_global.

Referenced by GSM_DispatchMessage(), GSM_DumpMessageBinary_Custom(), GSM_DumpMessageText_Custom(), GSM_InitConnection_Log(), GSM_OSErrorInfo(), N71_65_DecodePhonebook(), PHONE_EncodeSMSFrame(), smprintf(), and smprintf_level().

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 }
GSM_Debug_Info di
Definition: gsmstate.h:1412
GSM_Debug_Info GSM_global_debug
Definition: debug.c:33
#define FALSE
Definition: gammu-types.h:25
gboolean use_global
Definition: debug.h:37

§ GSM_GetUsedConnection()

GSM_ConnectionType GSM_GetUsedConnection ( GSM_StateMachine s)

Gets number of active gammu configurations.

Parameters
sState machine data
Returns
Connection type.

Definition at line 1709 of file gsmstate.c.

References _GSM_StateMachine::ConnectionType.

1710 {
1711  return s->ConnectionType;
1712 }
GSM_ConnectionType ConnectionType
Definition: gsmstate.h:1402

§ GSM_InitConnection()

GSM_Error GSM_InitConnection ( GSM_StateMachine s,
int  ReplyNum 
)

Initiates connection.

Parameters
sState machine data
ReplyNumNumber of replies to await (usually 3).
Returns
Error code

Definition at line 914 of file gsmstate.c.

References GSM_InitConnection_Log(), GSM_none_debug, _GSM_Debug_Info::log_function, and _GSM_Debug_Info::user_data.

915 {
917 }
GSM_Error GSM_InitConnection_Log(GSM_StateMachine *s, int ReplyNum, GSM_Log_Function log_function, void *user_data)
Definition: gsmstate.c:711
GSM_Log_Function log_function
Definition: debug.h:44
void * user_data
Definition: debug.h:48
GSM_Debug_Info GSM_none_debug
Definition: debug.c:22

§ GSM_InitConnection_Log()

GSM_Error GSM_InitConnection_Log ( GSM_StateMachine s,
int  ReplyNum,
GSM_Log_Function  log_function,
void *  user_data 
)

Initiates connection with custom logging callback.

Parameters
sState machine data
ReplyNumNumber of replies to await (usually 3).
log_functionLogging function, see GSM_SetDebugFunction.
user_dataUser data for logging function, see GSM_SetDebugFunction.
Returns
Error code
See also
GSM_SetDebugFunction

Definition at line 711 of file gsmstate.c.

References _GSM_StateMachine::Config, _GSM_StateMachine::ConfigNum, GSM_Config::Connection, _GSM_StateMachine::ConnectionType, _GSM_StateMachine::CurrentConfig, D_ERROR, GSM_Phone::Data, GSM_Config::DebugFile, GSM_Config::DebugLevel, GSM_Config::Device, _GSM_StateMachine::di, DL_BINARY, GSM_Phone_Data::EnableIncomingCall, GSM_Phone_Data::EnableIncomingCB, GSM_Phone_Data::EnableIncomingSMS, GSM_Phone_Data::EnableIncomingUSSD, ERR_DEVICEBUSY, ERR_DEVICELOCKED, ERR_DEVICENODRIVER, ERR_DEVICENOPERMISSION, ERR_DEVICENOTEXIST, ERR_DEVICENOTWORK, ERR_DEVICEOPENERROR, ERR_NONE, ERR_NOTSUPPORTED, ERR_TIMEOUT, ERR_UNCONFIGURED, ERR_UNKNOWNMODELSTRING, FALSE, GSM_Phone::Functions, GAMMU_VERSION, GCT_BLUEGNAPBUS, GCT_BLUEOBEX, GCT_BLUES60, GCT_IRDAGNAPBUS, GCT_IRDAOBEX, GCT_NONE, GCT_PROXYGNAPBUS, GCT_PROXYOBEX, GCT_PROXYS60, GSM_Phone_Functions::GetFirmware, GSM_Phone_Functions::GetManufacturer, GSM_Phone_Functions::GetModel, GetModelData(), GetOS(), GSM_CloseConnection(), GSM_GetCurrentDateTime(), GSM_GetDI(), GSM_LogError(), GSM_none_debug, GSM_OpenConnection(), GSM_RegisterAllConnections(), GSM_RegisterAllPhoneModules(), GSM_SetDebugFile(), GSM_SetDebugFunction(), GSM_SetDebugLevel(), GSM_TryGetModel(), GSM_Phone_Data::HardwareCache, _GSM_User::IncomingCall, _GSM_User::IncomingCB, _GSM_User::IncomingSMS, _GSM_User::IncomingUSSD, GSM_Phone_Functions::Initialise, _GSM_StateMachine::LockFile, GSM_Phone_Data::Manufacturer, GSM_Config::Model, GSM_Phone_Data::Model, GSM_Phone_Data::ModelInfo, _GSM_StateMachine::opened, _GSM_StateMachine::Phone, GSM_Phone_Functions::PostConnect, GSM_Phone_Data::ProductCodeCache, _GSM_StateMachine::ReplyNum, _GSM_User::SendSMSStatus, GSM_Phone_Data::SentMsg, GSM_Phone_Functions::SetDateTime, GSM_Phone_Functions::ShowStartInfo, smprintf(), smprintf_level(), _GSM_StateMachine::Speed, GSM_Config::StartInfo, GSM_Phone_Data::StartInfoCounter, StripSpaces(), GSM_Config::SyncTime, TRUE, _GSM_Debug_Info::use_global, GSM_Config::UseGlobalDebugFile, _GSM_StateMachine::User, _GSM_User::UserReplyFunctions, GSM_Phone_Data::VerDate, GSM_Phone_Data::VerNum, and GSM_Phone_Data::Version.

Referenced by GSM_InitConnection().

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 }
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
const char * GetOS(void)
Definition: misc.c:537
gboolean UseGlobalDebugFile
char HardwareCache[50]
Definition: gsmstate.h:466
IncomingUSSDCallback IncomingUSSD
Definition: gsmstate.h:1384
#define GAMMU_VERSION
Definition: gammu-config.h:7
IncomingCBCallback IncomingCB
Definition: gsmstate.h:1383
GSM_Error GSM_OpenConnection(GSM_StateMachine *s)
Definition: gsmstate.c:560
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
int StartInfoCounter
Definition: gsmstate.h:476
GSM_Debug_Info * GSM_GetDI(GSM_StateMachine *s)
Definition: gsmstate.c:70
GSM_Config Config[MAX_CONFIG_NUM+1]
Definition: gsmstate.h:1414
char VerDate[GSM_MAX_VERSION_DATE_LENGTH+1]
Definition: gsmstate.h:458
SendSMSStatusCallback SendSMSStatus
Definition: gsmstate.h:1385
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
GSM_Debug_Info di
Definition: gsmstate.h:1412
gboolean EnableIncomingCall
Definition: gsmstate.h:659
char Version[GSM_MAX_VERSION_LENGTH+1]
Definition: gsmstate.h:454
char Manufacturer[GSM_MAX_MANUFACTURER_LENGTH+1]
Definition: gsmstate.h:441
GSM_PhoneModel * ModelInfo
Definition: gsmstate.h:449
void StripSpaces(char *buff)
Definition: misc.c:713
int smprintf_level(GSM_StateMachine *s, GSM_DebugSeverity severity, const char *format,...)
Definition: debug.c:278
char DebugLevel[50]
GSM_Error(* GetModel)(GSM_StateMachine *s)
Definition: gsmstate.h:777
GSM_Error(* GetManufacturer)(GSM_StateMachine *s)
Definition: gsmstate.h:773
GSM_Error(* GetFirmware)(GSM_StateMachine *s)
Definition: gsmstate.h:781
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
GSM_Protocol_Message * SentMsg
Definition: gsmstate.h:680
void GSM_LogError(GSM_StateMachine *s, const char *message, const GSM_Error err)
Definition: gsmcomon.c:221
gboolean StartInfo
gboolean SyncTime
GSM_Error GSM_SetDebugFile(const char *info, GSM_Debug_Info *privdi)
Definition: debug.c:144
IncomingCallCallback IncomingCall
Definition: gsmstate.h:1381
gboolean opened
Definition: gsmstate.h:1413
gboolean use_global
Definition: debug.h:37
GSM_Phone_Data Data
Definition: gsmstate.h:1369
void GSM_GetCurrentDateTime(GSM_DateTime *Date)
Definition: misc.c:184
double VerNum
Definition: gsmstate.h:462
gboolean GSM_SetDebugLevel(const char *info, GSM_Debug_Info *privdi)
Definition: debug.c:186
GSM_Phone_Functions * Functions
Definition: gsmstate.h:1373
GSM_Error(* Initialise)(GSM_StateMachine *s)
Definition: gsmstate.h:756
GSM_Error GSM_RegisterAllPhoneModules(GSM_StateMachine *s)
Definition: gsmstate.c:383
#define TRUE
Definition: gammu-types.h:28
GSM_Error GSM_TryGetModel(GSM_StateMachine *s)
Definition: gsmstate.c:623
gboolean EnableIncomingSMS
Definition: gsmstate.h:663
static GSM_Error GSM_RegisterAllConnections(GSM_StateMachine *s, const char *connection)
Definition: gsmstate.c:197
char Model[GSM_MAX_MODEL_LENGTH+1]
Definition: gsmstate.h:445
GSM_Debug_Info GSM_none_debug
Definition: debug.c:22
GSM_Error(* ShowStartInfo)(GSM_StateMachine *s, gboolean enable)
Definition: gsmstate.h:769
IncomingSMSCallback IncomingSMS
Definition: gsmstate.h:1382
Definition: debug.h:91
char ProductCodeCache[50]
Definition: gsmstate.h:470
int smprintf(GSM_StateMachine *s, const char *format,...)
Definition: debug.c:261

§ GSM_Install()

GSM_Error GSM_Install ( GSM_StateMachine s,
const char *  ExtraPath,
gboolean  Minimal 
)

Installs applet required for configured connection to the phone.

Parameters
sState machine data.
ExtraPathExtra path where to search for installation data.
MinimalWhether to do minimal installation (eg. without support libraries), useful for applet updates
Returns
Result of operation.

Gets phone screenshot

Definition at line 1888 of file api.c.

References GSM_Phone::Functions, GSM_Phone_Functions::Install, _GSM_StateMachine::Phone, and PRINT_LOG_ERROR.

1889 {
1890  GSM_Error err;
1891 
1892  err = s->Phone.Functions->Install(s, ExtraPath, Minimal);
1893  PRINT_LOG_ERROR(err);
1894  return err;
1895 }
GSM_Error
Definition: gammu-error.h:23
GSM_Phone Phone
Definition: gsmstate.h:1431
#define PRINT_LOG_ERROR(err)
Definition: api.c:28
GSM_Error(* Install)(GSM_StateMachine *s, const char *ExtraPath, gboolean Minimal)
Definition: gsmstate.h:752
GSM_Phone_Functions * Functions
Definition: gsmstate.h:1373

§ GSM_IsConnected()

gboolean GSM_IsConnected ( GSM_StateMachine s)

Detects whether state machine is connected.

Parameters
sState machine data
Returns
Whether phone is connected.

Definition at line 976 of file gsmstate.c.

References GSM_Phone::Functions, _GSM_StateMachine::opened, and _GSM_StateMachine::Phone.

Referenced by GSM_ReadDevice().

976  {
977  return (s != NULL) && s->Phone.Functions != NULL && s->opened;
978 }
GSM_Phone Phone
Definition: gsmstate.h:1431
gboolean opened
Definition: gsmstate.h:1413
GSM_Phone_Functions * Functions
Definition: gsmstate.h:1373

§ GSM_OSErrorInfo()

void GSM_OSErrorInfo ( GSM_StateMachine s,
const char *  description 
)

Definition at line 1593 of file gsmstate.c.

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

Referenced by DUMMY_Error(), DUMMY_Initialise(), proxy_connect(), proxy_read(), and proxy_write().

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 }
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_ReadConfig()

GSM_Error GSM_ReadConfig ( INI_Section cfg_info,
GSM_Config cfg,
int  num 
)

Processes gammu configuration.

Parameters
cfg_infoIni file representation.
cfgWhere to store configuration.
numNumber of section to read.
Returns
Whether we got valid configuration. Especially check for ERR_USING_DEFAULTS.
See also
GSM_FallbackConfig

Definition at line 1350 of file gsmstate.c.

References GSM_Config::Connection, GSM_Config::DebugFile, GSM_Config::DebugLevel, DEFAULT_CONNECTION, DEFAULT_DEBUG_FILE, DEFAULT_DEBUG_LEVEL, DEFAULT_DEVICE, DEFAULT_LOCK_DEVICE, DEFAULT_MODEL, DEFAULT_START_INFO, DEFAULT_SYNCHRONIZE_TIME, GSM_Config::Device, ERR_NONE, ERR_NONE_SECTION, ERR_UNCONFIGURED, ERR_UNKNOWN, ERR_USING_DEFAULTS, FALSE, GSM_ExpandUserPath(), GSM_SetFeatureString(), INI_GetBool(), INI_GetValue(), GSM_Config::LockDevice, GSM_Config::Model, _INI_Section::Next, GSM_Config::PhoneFeatures, _INI_Section::SectionName, GSM_Config::StartInfo, GSM_Config::SyncTime, GSM_Config::TextBirthday, GSM_Config::TextCall, GSM_Config::TextMeeting, GSM_Config::TextMemo, GSM_Config::TextReminder, TRUE, and GSM_Config::UseGlobalDebugFile.

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 }
gboolean UseGlobalDebugFile
char TextBirthday[32]
#define DEFAULT_DEBUG_FILE
Definition: gsmstate.c:61
GSM_Error
Definition: gammu-error.h:23
gboolean LockDevice
char DebugLevel[50]
void GSM_ExpandUserPath(char **string)
Definition: gsmstate.c:1326
#define DEFAULT_MODEL
Definition: gsmstate.c:58
int gboolean
Definition: gammu-types.h:23
GSM_Feature PhoneFeatures[GSM_MAX_PHONE_FEATURES+1]
#define FALSE
Definition: gammu-types.h:25
gboolean INI_GetBool(INI_Section *cfg, const unsigned char *section, const unsigned char *key, gboolean fallback)
Definition: cfg.c:344
gboolean StartInfo
gboolean SyncTime
char TextMeeting[32]
GSM_Error GSM_SetFeatureString(GSM_Feature *list, const char *string)
Definition: gsmphones.c:155
#define DEFAULT_DEBUG_LEVEL
Definition: gsmstate.c:62
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
#define DEFAULT_LOCK_DEVICE
Definition: gsmstate.c:63
unsigned char * SectionName
Definition: gammu-inifile.h:55
#define DEFAULT_START_INFO
Definition: gsmstate.c:64
#define DEFAULT_CONNECTION
Definition: gsmstate.c:59
char TextReminder[32]
#define TRUE
Definition: gammu-types.h:28
INI_Section * Next
Definition: gammu-inifile.h:53
char TextCall[32]
#define DEFAULT_DEVICE
Definition: gsmstate.c:56

§ GSM_ReadDevice()

int GSM_ReadDevice ( GSM_StateMachine s,
gboolean  waitforreply 
)

Attempts to read data from phone. This can be used for getting status of incoming events, which would not be found out without polling device.

Parameters
sState machine data
waitforreplyWhether to wait for some event
Returns
Number of read bytes

Definition at line 919 of file gsmstate.c.

References _GSM_StateMachine::Abort, _GSM_StateMachine::Device, GSM_Device::Functions, GSM_Protocol::Functions, GSM_GetCurrentDateTime(), GSM_IsConnected(), _GSM_StateMachine::Protocol, GSM_Device_Functions::ReadDevice, GSM_DateTime::Second, and GSM_Protocol_Functions::StateMachine.

Referenced by GSM_WaitForOnce().

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 }
GSM_Error(* StateMachine)(GSM_StateMachine *s, unsigned char rx_char)
Definition: gsmstate.h:352
gboolean GSM_IsConnected(GSM_StateMachine *s)
Definition: gsmstate.c:976
volatile gboolean Abort
Definition: gsmstate.h:1423
int(* ReadDevice)(GSM_StateMachine *s, void *buf, size_t nbytes)
Definition: gsmstate.h:252
GSM_Device_Functions * Functions
Definition: gsmstate.h:335
GSM_Protocol Protocol
Definition: gsmstate.h:1430
void GSM_GetCurrentDateTime(GSM_DateTime *Date)
Definition: misc.c:184
GSM_Protocol_Functions * Functions
Definition: gsmstate.h:424
GSM_Device Device
Definition: gsmstate.h:1429

§ GSM_RegisterAllPhoneModules()

GSM_Error GSM_RegisterAllPhoneModules ( GSM_StateMachine s)

Tries to register all modules to find one matching current configuration.

Parameters
sState machine pointer.
Returns
Error code, ERR_NONE on success.

Definition at line 383 of file gsmstate.c.

References _GSM_StateMachine::ConnectionType, _GSM_StateMachine::CurrentConfig, GSM_Phone::Data, DUMMYPhone, ERR_NONE, ERR_UNKNOWNMODELSTRING, F_6230iCALLER, F_ALCATEL, F_FILES2, F_NOTES, F_OBEX, F_RADIO, F_SERIES40_30, F_SMS_FILES, F_TODO66, GSM_PhoneModel::features, 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, GetModelData(), GSM_AddPhoneFeature(), GSM_IsPhoneFeatureAvailable(), GSM_RegisterModule(), GSM_Config::Model, GSM_Phone_Data::Model, GSM_PhoneModel::model, GSM_Phone_Functions::models, _GSM_StateMachine::Phone, and smprintf().

Referenced by GSM_InitConnection_Log().

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 }
GSM_Config * CurrentConfig
Definition: gsmstate.h:1415
GSM_ConnectionType ConnectionType
Definition: gsmstate.h:1402
const char * model
Definition: gammu-info.h:764
static void GSM_RegisterModule(GSM_StateMachine *s, GSM_Phone_Functions *phone)
Definition: gsmstate.c:360
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
gboolean GSM_AddPhoneFeature(GSM_PhoneModel *model, GSM_Feature feature)
Definition: gsmphones.c:1039
GSM_Feature features[GSM_MAX_PHONE_FEATURES+1]
Definition: gammu-info.h:776
GSM_Phone_Data Data
Definition: gsmstate.h:1369
gboolean GSM_IsPhoneFeatureAvailable(GSM_PhoneModel *model, GSM_Feature feature)
Definition: gsmphones.c:1026
GSM_Phone_Functions * Functions
Definition: gsmstate.h:1373
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_SetConfigNum()

void GSM_SetConfigNum ( GSM_StateMachine s,
int  sections 
)

Gets number of active gammu configurations.

Parameters
sState machine data
sectionsNumber of sections.

Definition at line 1317 of file gsmstate.c.

References _GSM_StateMachine::ConfigNum, and MAX_CONFIG_NUM.

1318 {
1319  if (sections > MAX_CONFIG_NUM) return;
1320  s->ConfigNum = sections;
1321 }
#define MAX_CONFIG_NUM
Definition: gsmstate.h:1399

§ GSM_TerminateConnection()

GSM_Error GSM_TerminateConnection ( GSM_StateMachine s)

Terminates connection.

Parameters
sState machine data
Returns
Error code

Definition at line 949 of file gsmstate.c.

References _GSM_StateMachine::CurrentConfig, GSM_Phone::Data, _GSM_StateMachine::di, ERR_NONE, FALSE, GSM_Phone::Functions, GSM_CloseConnection(), GSM_SetDebugFileDescriptor(), _GSM_StateMachine::opened, _GSM_StateMachine::Phone, GSM_Phone_Functions::ShowStartInfo, smprintf(), GSM_Config::StartInfo, GSM_Phone_Data::StartInfoCounter, and GSM_Phone_Functions::Terminate.

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 }
GSM_Error(* Terminate)(GSM_StateMachine *s)
Definition: gsmstate.h:760
GSM_Config * CurrentConfig
Definition: gsmstate.h:1415
int StartInfoCounter
Definition: gsmstate.h:476
GSM_Error
Definition: gammu-error.h:23
GSM_Debug_Info di
Definition: gsmstate.h:1412
GSM_Error GSM_SetDebugFileDescriptor(FILE *fd, gboolean closable, GSM_Debug_Info *privdi)
Definition: debug.c:127
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
gboolean StartInfo
gboolean opened
Definition: gsmstate.h:1413
GSM_Phone_Data Data
Definition: gsmstate.h:1369
GSM_Phone_Functions * Functions
Definition: gsmstate.h:1373
GSM_Error(* ShowStartInfo)(GSM_StateMachine *s, gboolean enable)
Definition: gsmstate.h:769
int smprintf(GSM_StateMachine *s, const char *format,...)
Definition: debug.c:261

§ GSM_WaitFor()

GSM_Error GSM_WaitFor ( GSM_StateMachine s,
unsigned const char *  buffer,
size_t  length,
int  type,
int  timeout,
GSM_Phone_RequestID  request 
)

Wait for reply from the phone.

Parameters
sState machine pointer.
bufferData to write to phone.
lengthLength of data in buffer.
typeType of request (for protocols where it makes sense).
timeoutHow long to wait for reply.
requestID of request
Returns
Error code, ERR_NONE on sucecss.

Definition at line 1029 of file gsmstate.c.

References _GSM_StateMachine::CurrentConfig, D_ERROR, GSM_Phone::Data, GSM_Phone_Data::DispatchError, ERR_NONE, ERR_TIMEOUT, F_RESET_AFTER_TIMEOUT, FALSE, GSM_Protocol::Functions, GSM_Phone::Functions, GSM_IsPhoneFeatureAvailable(), GSM_Reset(), GSM_WaitForOnce(), ID_None, ID_Reset, GSM_Phone_Data::ModelInfo, _GSM_StateMachine::Phone, _GSM_StateMachine::Protocol, _GSM_StateMachine::ReplyNum, GSM_Phone_Data::RequestID, GSM_Phone_Functions::ShowStartInfo, smprintf_level(), GSM_Config::StartInfo, GSM_Phone_Data::StartInfoCounter, and GSM_Protocol_Functions::WriteMessage.

Referenced by NOKIA_EncodeDateTime().

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 }
GSM_Config * CurrentConfig
Definition: gsmstate.h:1415
int StartInfoCounter
Definition: gsmstate.h:476
GSM_Error GSM_Reset(GSM_StateMachine *s, gboolean hard)
Definition: api.c:333
GSM_Error
Definition: gammu-error.h:23
GSM_Error DispatchError
Definition: gsmstate.h:689
GSM_Error GSM_WaitForOnce(GSM_StateMachine *s, unsigned const char *buffer, size_t length, int type, int timeout)
Definition: gsmstate.c:986
GSM_Error(* WriteMessage)(GSM_StateMachine *s, unsigned const char *buffer, int length, int type)
Definition: gsmstate.h:347
GSM_PhoneModel * ModelInfo
Definition: gsmstate.h:449
int smprintf_level(GSM_StateMachine *s, GSM_DebugSeverity severity, const char *format,...)
Definition: debug.c:278
GSM_Phone Phone
Definition: gsmstate.h:1431
#define FALSE
Definition: gammu-types.h:25
gboolean StartInfo
GSM_Phone_RequestID RequestID
Definition: gsmstate.h:685
GSM_Protocol Protocol
Definition: gsmstate.h:1430
GSM_Phone_Data Data
Definition: gsmstate.h:1369
gboolean GSM_IsPhoneFeatureAvailable(GSM_PhoneModel *model, GSM_Feature feature)
Definition: gsmphones.c:1026
GSM_Phone_Functions * Functions
Definition: gsmstate.h:1373
GSM_Protocol_Functions * Functions
Definition: gsmstate.h:424
GSM_Error(* ShowStartInfo)(GSM_StateMachine *s, gboolean enable)
Definition: gsmstate.h:769
Definition: debug.h:91

§ GSM_WaitForOnce()

GSM_Error GSM_WaitForOnce ( GSM_StateMachine s,
unsigned const char *  buffer,
size_t  length,
int  type,
int  timeout 
)

Definition at line 986 of file gsmstate.c.

References _GSM_StateMachine::Abort, GSM_Protocol_Message::Buffer, GSM_Phone::Data, GSM_Phone_Data::DispatchError, ERR_ABORTED, ERR_TIMEOUT, GSM_ReadDevice(), ID_None, GSM_Protocol_Message::Length, _GSM_StateMachine::Phone, GSM_Phone_Data::RequestID, GSM_Phone_Data::SentMsg, TRUE, and GSM_Protocol_Message::Type.

Referenced by GSM_WaitFor().

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 }
GSM_Error DispatchError
Definition: gsmstate.h:689
int GSM_ReadDevice(GSM_StateMachine *s, gboolean waitforreply)
Definition: gsmstate.c:919
volatile gboolean Abort
Definition: gsmstate.h:1423
GSM_Phone Phone
Definition: gsmstate.h:1431
GSM_Protocol_Message * SentMsg
Definition: gsmstate.h:680
GSM_Phone_RequestID RequestID
Definition: gsmstate.h:685
GSM_Phone_Data Data
Definition: gsmstate.h:1369
#define TRUE
Definition: gammu-types.h:28
unsigned char * Buffer
Definition: protocol.h:22

Variable Documentation

§ DUMMYPhone

GSM_Phone_Functions DUMMYPhone

Definition at line 1964 of file dummy.c.

Referenced by GSM_RegisterAllPhoneModules(), and GSM_TryGetModel().

§ NAUTOPhone

GSM_Phone_Functions NAUTOPhone

Referenced by GSM_TryGetModel().

§ ProxyDevice

GSM_Device_Functions ProxyDevice

Proxy device functions.

Definition at line 212 of file proxy.c.

Referenced by GSM_RegisterAllConnections().