24 #include "../helper/string.h" 26 #if defined(HAVE_GETPWUID) && defined(HAVE_GETUID) 27 #include <sys/types.h> 32 #if defined(WIN32) || defined(DJGPP) 35 #define _WIN32_IE 0x0501 39 #define FALLBACK_GAMMURC "gammurc" 40 #define GAMMURC_NAME "\\gammurc" 42 #define FALLBACK_GAMMURC "/etc/gammurc" 43 #define GAMMURC_NAME "/.gammurc" 45 #define XDG_GAMMURC_NAME "/gammu/config" 49 #define PATH_MAX (MAX_PATH) 53 #if defined(WIN32) || defined(DJGPP) 54 # define DEFAULT_DEVICE "com2:" 56 # define DEFAULT_DEVICE "/dev/ttyUSB0" 58 #define DEFAULT_MODEL "" 59 #define DEFAULT_CONNECTION "at" 60 #define DEFAULT_SYNCHRONIZE_TIME FALSE 61 #define DEFAULT_DEBUG_FILE "" 62 #define DEFAULT_DEBUG_LEVEL "" 63 #define DEFAULT_LOCK_DEVICE FALSE 64 #define DEFAULT_START_INFO FALSE 200 char *buff, *nodtr_pos, *nopower_pos;
203 buff = strdup(connection);
216 nodtr_pos = strcasestr(buff,
"-nodtr");
217 if (nodtr_pos != NULL) {
223 nopower_pos = strcasestr(buff,
"-nopower");
224 if (nopower_pos != NULL) {
230 for (i = 0; i <
sizeof(
GSM_Connections) /
sizeof(GSM_Connections[0]); i++) {
232 if (strcasecmp(GSM_Connections[i].Name, buff) == 0) {
240 if (nodtr_pos != NULL) {
266 #ifdef GSM_ENABLE_MBUS2 269 #ifdef GSM_ENABLE_FBUS2 272 #ifdef GSM_ENABLE_FBUS2DLR3 275 #ifdef GSM_ENABLE_DKU5FBUS2 278 #ifdef GSM_ENABLE_FBUS2PL2303 281 #ifdef GSM_ENABLE_FBUS2BLUE 284 #ifdef GSM_ENABLE_FBUS2IRDA 287 #if defined(GSM_ENABLE_DKU2PHONET) && defined(GSM_ENABLE_USBDEVICE) 290 #ifdef GSM_ENABLE_DKU2PHONET 293 #ifdef GSM_ENABLE_DKU2AT 299 #ifdef GSM_ENABLE_PHONETBLUE 302 #ifdef GSM_ENABLE_IRDAGNAPBUS 305 #ifdef GSM_ENABLE_IRDAPHONET 308 #ifdef GSM_ENABLE_IRDAAT 311 #ifdef GSM_ENABLE_IRDAOBEX 314 #ifdef GSM_ENABLE_BLUEGNAPBUS 317 #ifdef GSM_ENABLE_BLUEGNAPBUS 320 #ifdef GSM_ENABLE_BLUEFBUS2 323 #ifdef GSM_ENABLE_BLUEPHONET 326 #ifdef GSM_ENABLE_BLUEAT 329 #ifdef GSM_ENABLE_BLUEOBEX 332 #ifdef GSM_ENABLE_PROXY 333 #ifdef GSM_ENABLE_S60 336 #ifdef GSM_ENABLE_BLUEGNAPBUS 339 #ifdef GSM_ENABLE_FBUS2 342 #ifdef GSM_ENABLE_DKU2PHONET 345 #ifdef GSM_ENABLE_ATGEN 348 #ifdef GSM_ENABLE_OBEXGEN 353 smprintf(s,
"Connection %s is know but was disabled on compile time\n", connection);
390 #ifdef GSM_ENABLE_ATGEN 393 #ifdef GSM_ENABLE_ALCATEL 396 smprintf(s,
"[Module - \"%s\"]\n",ALCATELPhone.models);
401 #ifdef GSM_ENABLE_ATOBEX 404 smprintf(s,
"[Module - \"%s\"]\n",ATOBEXPhone.models);
409 smprintf(s,
"[Module - \"%s\"]\n",ATGENPhone.models);
415 #ifdef GSM_ENABLE_OBEXGEN 417 smprintf(s,
"[Module - \"%s\"]\n",OBEXGENPhone.models);
423 #ifdef GSM_ENABLE_BACKUP 432 #ifdef GSM_ENABLE_GNAPGEN 434 smprintf(s,
"[Module - \"%s\"]\n",GNAPGENPhone.models);
439 #ifdef GSM_ENABLE_S60 441 smprintf(s,
"[Module - \"%s\"]\n",S60Phone.models);
447 #ifdef GSM_ENABLE_NOKIA6510 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");
469 smprintf(s,
"WARNING: Guessed phone as S40/30 compatible (RM series)!\n");
482 smprintf(s,
"WARNING: Guessed phone as S40/30 compatible (RH series)!\n");
495 smprintf(s,
"[Module - \"%s\"]\n", N6510Phone.models);
504 #ifdef GSM_ENABLE_ATGEN 511 #ifdef GSM_ENABLE_BACKUP 514 #ifdef GSM_ENABLE_OBEXGEN 517 #ifdef GSM_ENABLE_GNAPGEN 520 #ifdef GSM_ENABLE_S60 523 #ifdef GSM_ENABLE_NOKIA3320 526 #ifdef GSM_ENABLE_NOKIA3650 529 #ifdef GSM_ENABLE_NOKIA650 532 #ifdef GSM_ENABLE_NOKIA6110 535 #ifdef GSM_ENABLE_NOKIA6510 538 #ifdef GSM_ENABLE_NOKIA7110 541 #ifdef GSM_ENABLE_NOKIA9210 544 #ifdef GSM_ENABLE_ALCATEL 547 #ifdef GSM_ENABLE_ATOBEX 566 if (error !=
ERR_NONE)
return error;
597 if (error !=
ERR_NONE)
return error;
601 if (error !=
ERR_NONE)
return error;
628 if (error !=
ERR_NONE)
return error;
632 smprintf(s,
"[Module - \"auto\"]\n");
634 #ifdef GSM_ENABLE_BACKUP 639 #ifdef GSM_ENABLE_ATGEN 648 #ifdef GSM_ENABLE_OBEXGEN 655 #ifdef GSM_ENABLE_GNAPGEN 662 #ifdef GSM_ENABLE_S60 668 #if defined(GSM_ENABLE_NOKIA_DCT3) || defined(GSM_ENABLE_NOKIA_DCT4) 692 smprintf(s,
"ERROR: Could not find proper module for autodetection!\n");
698 if (error !=
ERR_NONE)
return error;
702 if (error !=
ERR_NONE)
return error;
706 if (error !=
ERR_NONE)
return error;
776 if (strlen(
GetOS()) != 0) {
788 GSM_LogError(s,
"Init:GSM_RegisterAllConnections" , error);
828 smprintf(s,
"Configured model %s is not known, retrying with autodetection!\n",
834 GSM_LogError(s,
"Init:GSM_RegisterAllPhoneModules" , error);
922 unsigned char buff[65536]={
'\0'};
923 int res=0,count=0,i=0;
943 for (count = 0; count < res; count++) {
967 if (error !=
ERR_NONE)
return error;
987 size_t length,
int type,
int timeout)
997 sentmsg.
Buffer = (
unsigned char *)malloc(length);
998 memcpy(sentmsg.
Buffer, buffer, length);
1024 }
while (i < timeout);
1030 size_t length,
int type,
int timeout,
1049 for (reply = 0; reply < s->
ReplyNum; reply++) {
1085 while (Reply[i].requestID !=
ID_None) {
1088 if (Reply[i].msgtype[0] == 0 && Reply[i].subtypechar == 0) {
1089 if (Reply[i].subtype == msg->
Type) {
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) {
1105 if (strlen(Reply[i].msgtype) < msg->
Length) {
1106 if (strncmp(Reply[i].msgtype,msg->
Buffer,strlen(Reply[i].msgtype))==0) {
1115 Reply[i].requestID == Data->
RequestID ||
1146 if (Reply != NULL) {
1156 error = Reply[reply].
Function(msg, s);
1157 if (Reply[reply].requestID == Phone->
RequestID) {
1188 smprintf(s,
". Please report the error, see <https://wammu.eu/support/bugs/>. Thank you\n");
1205 dbgprintf(NULL,
"Open config: \"%s\"\n", path);
1214 #if defined(HAVE_GETPWUID) && defined(HAVE_GETUID) 1215 struct passwd *pwent;
1220 if (force_config != NULL) {
1226 if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, configfile))) {
1235 envpath = getenv(
"XDG_CONFIG_HOME");
1237 strcpy(configfile, envpath);
1243 envpath = getenv(
"HOME");
1245 strcpy(configfile, envpath);
1246 strcat(configfile,
"/.config");
1255 envpath = getenv(
"HOME");
1257 strcpy(configfile, envpath);
1264 #if defined(HAVE_GETPWUID) && defined(HAVE_GETUID) 1266 pwent = getpwuid(getuid());
1267 if (pwent != NULL) {
1268 strcpy(configfile, pwent->pw_dir);
1282 envpath = getenv(
"HOMEDRIVE");
1284 strcat(configfile, envpath);
1287 envpath = getenv(
"HOMEPATH");
1289 strcat(configfile, envpath);
1307 return &(s->
Config[num]);
1328 char *tmp = NULL, *home = NULL;
1331 if (*
string[0] !=
'~')
return;
1334 home = getenv(
"HOME");
1335 if (home == NULL)
return;
1338 tmp = (
char *)malloc(strlen(home) + strlen(*
string) + 2);
1339 if (tmp == NULL)
return;
1343 strcat(tmp, *
string + 1);
1353 unsigned char section[50]={0};
1362 if (cfg_info == NULL) {
1369 snprintf(section,
sizeof(section) - 1,
"gammu");
1371 snprintf(section,
sizeof(section) - 1,
"gammu%i", num);
1375 for (h = cfg_info; h != NULL; h = h->
Next) {
1427 if (Temp == NULL || strcmp(Temp,
"auto") == 0) {
1430 if (strlen(Temp) >=
sizeof(cfg->
Model))
1431 Temp[
sizeof(cfg->
Model) - 1] =
'\0';
1432 strcpy(cfg->
Model,Temp);
1476 if (strlen(Temp) >=
sizeof(cfg->
TextCall))
1477 Temp[
sizeof(cfg->
TextCall) - 1] =
'\0';
1496 if (strlen(Temp) >=
sizeof(cfg->
TextMemo))
1497 Temp[
sizeof(cfg->
TextMemo) - 1] =
'\0';
1549 smprintf(s,
"type 0x%02X/length 0x%02lX/%ld",
1550 type, (
long)messagesize, (
long)messagesize);
1575 smprintf(s,
"%c",(
int)(messagesize/256));
1576 smprintf(s,
"%c",(
int)(messagesize%256));
1578 for (i=0;i<messagesize;i++) {
1597 unsigned char *lpMsgBuf = NULL;
1605 if (GetLastError() != 0) {
1613 FORMAT_MESSAGE_ALLOCATE_BUFFER |
1614 FORMAT_MESSAGE_FROM_SYSTEM |
1615 FORMAT_MESSAGE_IGNORE_INSERTS,
1618 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
1623 for (i=0;i<(int)strlen(lpMsgBuf);i++) {
1624 if (lpMsgBuf[i] == 13 || lpMsgBuf[i] == 10) {
1628 smprintf(s,
"[System error - %s, %i, \"%s\"]\n", description, (
int)GetLastError(), (LPCTSTR)lpMsgBuf);
1629 LocalFree(lpMsgBuf);
1641 smprintf(s,
"[System error - %s, %i, \"%s\"]\n",description,errno,strerror(errno));
1693 if (s == NULL)
return;
1721 return s == NULL ? NULL : &(s->
di);
void GSM_DumpMessageBinary(GSM_StateMachine *s, unsigned const char *message, size_t messagesize, int type)
GSM_Error(* Terminate)(GSM_StateMachine *s)
GSM_Config * CurrentConfig
gboolean EnableIncomingUSSD
GSM_Error GSM_SetDebugFunction(GSM_Log_Function info, void *data, GSM_Debug_Info *privdi)
void GSM_SetIncomingCallCallback(GSM_StateMachine *s, IncomingCallCallback callback, void *user_data)
gboolean UseGlobalDebugFile
IncomingUSSDCallback IncomingUSSD
void GSM_SetIncomingSMSCallback(GSM_StateMachine *s, IncomingSMSCallback callback, void *user_data)
GSM_Error GSM_InitConnection_Log(GSM_StateMachine *s, int ReplyNum, GSM_Log_Function log_function, void *user_data)
void DumpMessage(GSM_Debug_Info *d, const unsigned char *message, const size_t messagesize)
GSM_Error GSM_InitConnection(GSM_StateMachine *s, int ReplyNum)
GSM_StateMachine * GSM_AllocStateMachine(void)
IncomingCBCallback IncomingCB
void * IncomingCallUserData
GSM_Error GSM_OpenConnection(GSM_StateMachine *s)
void GSM_SetConfigNum(GSM_StateMachine *s, int sections)
void * IncomingUSSDUserData
GSM_Phone_Functions NAUTOPhone
void GSM_DumpMessageTextRecv(GSM_StateMachine *s, unsigned const char *message, size_t messagesize, int type)
GSM_Reply_Function * UserReplyFunctions
GSM_ConnectionType ConnectionType
GSM_Error(* PostConnect)(GSM_StateMachine *s)
#define DEFAULT_DEBUG_FILE
GSM_Error(* CloseDevice)(GSM_StateMachine *s)
GSM_Debug_Info * GSM_GetDI(GSM_StateMachine *s)
GSM_Config Config[MAX_CONFIG_NUM+1]
GSM_Log_Function log_function
char VerDate[GSM_MAX_VERSION_DATE_LENGTH+1]
int FindSerialSpeed(const char *buffer)
GSM_Error GSM_Reset(GSM_StateMachine *s, gboolean hard)
GSM_Error(* StateMachine)(GSM_StateMachine *s, unsigned char rx_char)
GSM_Error(* Function)(GSM_Protocol_Message *msg, GSM_StateMachine *s)
gboolean GSM_IsConnected(GSM_StateMachine *s)
SendSMSStatusCallback SendSMSStatus
GSM_Error GSM_DispatchMessage(GSM_StateMachine *s)
gboolean EnableIncomingCB
GSM_Error(* SetDateTime)(GSM_StateMachine *s, GSM_DateTime *date_time)
static void GSM_RegisterConnection(GSM_StateMachine *s, unsigned int connection, GSM_Device_Functions *device, GSM_Protocol_Functions *protocol)
static GSM_Error CheckReplyFunctions(GSM_StateMachine *s, GSM_Reply_Function *Reply, int *reply)
int GSM_ReadDevice(GSM_StateMachine *s, gboolean waitforreply)
void(* SendSMSStatusCallback)(GSM_StateMachine *s, int status, int MessageReference, void *user_data)
void * SendSMSStatusUserData
gboolean EnableIncomingCall
GSM_Error GSM_WaitForOnce(GSM_StateMachine *s, unsigned const char *buffer, size_t length, int type, int timeout)
GSM_Error GSM_SetDebugFileDescriptor(FILE *fd, gboolean closable, GSM_Debug_Info *privdi)
GSM_Error(* WriteMessage)(GSM_StateMachine *s, unsigned const char *buffer, int length, int type)
char Version[GSM_MAX_VERSION_LENGTH+1]
static const GSM_ConnectionInfo GSM_Connections[]
gboolean unlock_device(GSM_StateMachine *s, char **lock_file)
void(* GSM_Log_Function)(const char *text, void *data)
char Manufacturer[GSM_MAX_MANUFACTURER_LENGTH+1]
void GSM_SetIncomingUSSDCallback(GSM_StateMachine *s, IncomingUSSDCallback callback, void *user_data)
GSM_PhoneModel * ModelInfo
void StripSpaces(char *buff)
int smprintf_level(GSM_StateMachine *s, GSM_DebugSeverity severity, const char *format,...)
static void GSM_RegisterModule(GSM_StateMachine *s, GSM_Phone_Functions *phone)
void GSM_DumpMessageBinary_Custom(GSM_StateMachine *s, unsigned const char *message, size_t messagesize, int type, int direction)
GSM_Error(* GetModel)(GSM_StateMachine *s)
GSM_Error(* GetManufacturer)(GSM_StateMachine *s)
void GSM_ExpandUserPath(char **string)
GSM_Error(* OpenDevice)(GSM_StateMachine *s)
GSM_Error(* Initialise)(GSM_StateMachine *s)
void(* IncomingUSSDCallback)(GSM_StateMachine *s, GSM_USSDMessage *ussd, void *user_data)
GSM_Error(* GetFirmware)(GSM_StateMachine *s)
GSM_Feature PhoneFeatures[GSM_MAX_PHONE_FEATURES+1]
GSM_Debug_Info GSM_global_debug
GSM_PhoneModel * GetModelData(GSM_StateMachine *s, const char *model, const char *number, const char *irdamodel)
GSM_Error GSM_CloseConnection(GSM_StateMachine *s)
void(* IncomingCallCallback)(GSM_StateMachine *s, GSM_Call *call, void *user_data)
gboolean INI_GetBool(INI_Section *cfg, const unsigned char *section, const unsigned char *key, gboolean fallback)
GSM_Protocol_Message * SentMsg
gboolean GSM_AddPhoneFeature(GSM_PhoneModel *model, GSM_Feature feature)
GSM_PhoneModel * GSM_GetModelInfo(GSM_StateMachine *s)
GSM_Error INI_ReadFile(const char *FileName, gboolean Unicode, INI_Section **result)
GSM_Error GSM_WaitFor(GSM_StateMachine *s, unsigned const char *buffer, size_t length, int type, int timeout, GSM_Phone_RequestID request)
GSM_Device_Functions NoneDevice
int GSM_GetConfigNum(const GSM_StateMachine *s)
void GSM_LogError(GSM_StateMachine *s, const char *message, const GSM_Error err)
GSM_Protocol_Functions NoProtocol
GSM_Phone_RequestID RequestID
GSM_Error GSM_AbortOperation(GSM_StateMachine *s)
int(* ReadDevice)(GSM_StateMachine *s, void *buf, size_t nbytes)
void GSM_OSErrorInfo(GSM_StateMachine *s, const char *description)
GSM_Feature features[GSM_MAX_PHONE_FEATURES+1]
GSM_Error GSM_TerminateConnection(GSM_StateMachine *s)
GSM_Error GSM_SetDebugFile(const char *info, GSM_Debug_Info *privdi)
GSM_Device_Functions * Functions
IncomingCallCallback IncomingCall
GSM_Error GSM_SetFeatureString(GSM_Feature *list, const char *string)
GSM_Error GSM_FindGammuRC(INI_Section **result, const char *force_config)
void(* IncomingCBCallback)(GSM_StateMachine *s, GSM_CBMessage *cb, void *user_data)
GSM_Config * GSM_GetConfig(GSM_StateMachine *s, int num)
GSM_Device_Functions ProxyDevice
const GSM_ConnectionType Connection
void * IncomingCBUserData
#define DEFAULT_DEBUG_LEVEL
void GSM_GetCurrentDateTime(GSM_DateTime *Date)
GSM_Error(* Terminate)(GSM_StateMachine *s)
gboolean GSM_IsPhoneFeatureAvailable(GSM_PhoneModel *model, GSM_Feature feature)
gboolean GSM_SetDebugLevel(const char *info, GSM_Debug_Info *privdi)
GSM_Phone_Functions * Functions
unsigned char * INI_GetValue(INI_Section *cfg, const unsigned char *section, const unsigned char *key, const gboolean Unicode)
#define DEFAULT_SYNCHRONIZE_TIME
GSM_Error(* Initialise)(GSM_StateMachine *s)
#define DEFAULT_LOCK_DEVICE
GSM_Phone_Functions DUMMYPhone
GSM_Error GSM_TryReadGammuRC(const char *path, INI_Section **result)
unsigned char * SectionName
#define DEFAULT_START_INFO
#define DEFAULT_CONNECTION
void * IncomingSMSUserData
GSM_Error GSM_ReadConfig(INI_Section *cfg_info, GSM_Config *cfg, int num)
GSM_Reply_Function * ReplyFunctions
GSM_Error GSM_RegisterAllPhoneModules(GSM_StateMachine *s)
void GSM_DumpMessageBinaryRecv(GSM_StateMachine *s, unsigned const char *message, size_t messagesize, int type)
GSM_Protocol_Functions * Functions
GSM_ConnectionType GSM_GetUsedConnection(GSM_StateMachine *s)
void GSM_SetIncomingCBCallback(GSM_StateMachine *s, IncomingCBCallback callback, void *user_data)
GSM_Error GSM_TryGetModel(GSM_StateMachine *s)
void GSM_SetSendSMSStatusCallback(GSM_StateMachine *s, SendSMSStatusCallback callback, void *user_data)
gboolean EnableIncomingSMS
void GSM_FreeStateMachine(GSM_StateMachine *s)
static GSM_Error GSM_RegisterAllConnections(GSM_StateMachine *s, const char *connection)
char Model[GSM_MAX_MODEL_LENGTH+1]
void(* IncomingSMSCallback)(GSM_StateMachine *s, GSM_SMSMessage *sms, void *user_data)
GSM_Debug_Info GSM_none_debug
GSM_Error(* ShowStartInfo)(GSM_StateMachine *s, gboolean enable)
GSM_Protocol_Message * RequestMsg
volatile size_t MessagesCount
IncomingSMSCallback IncomingSMS
void GSM_DumpMessageText(GSM_StateMachine *s, unsigned const char *message, size_t messagesize, int type)
char ProductCodeCache[50]
int smprintf(GSM_StateMachine *s, const char *format,...)
GSM_Error lock_device(GSM_StateMachine *s, const char *port, char **lock_name)
void GSM_DumpMessageText_Custom(GSM_StateMachine *s, unsigned const char *message, size_t messagesize, int type, const char *text)
GSM_Debug_Info * GSM_GetDebug(GSM_StateMachine *s)