/** * @name gammu_create: */ gammu_state_t *gammu_create(const char *config_path) { gammu_state_t *s = allocate(sizeof(*s)); INI_Section *ini; GSM_InitLocales(NULL); if ((s->err = GSM_FindGammuRC(&ini, config_path)) != ERR_NONE) { goto cleanup; } s->sm = GSM_AllocStateMachine(); GSM_Config *cfg = GSM_GetConfig(s->sm, 0); if ((s->err = GSM_ReadConfig(ini, cfg, 0)) != ERR_NONE) { goto cleanup_state; } INI_Free(ini); GSM_SetConfigNum(s->sm, 1); if ((s->err = GSM_InitConnection(s->sm, 1)) != ERR_NONE) { goto cleanup_state; } /* Success */ return s; cleanup_state: GSM_FreeStateMachine(s->sm); cleanup: free(s); return NULL; }
void single_check(const char *device, const char *connection, const char *model, GSM_Error expected) { GSM_Config *smcfg; GSM_Error error; GSM_Debug_Info *debug_info; /* Allocates state machine */ s = GSM_AllocStateMachine(); test_result(s != NULL); debug_info = GSM_GetDebug(s); GSM_SetDebugGlobal(TRUE, debug_info); smcfg = GSM_GetConfig(s, 0); strcpy(smcfg->Model, model); smcfg->Device = strdup(device); smcfg->UseGlobalDebugFile = TRUE; smcfg->Connection = strdup(connection); smcfg->PhoneFeatures[0] = F_PBK_ENCODENUMBER; smcfg->PhoneFeatures[1] = 0; GSM_SetConfigNum(s, 1); error = GSM_InitConnection(s, 1); test_result(error == expected); /* Free state machine */ GSM_FreeStateMachine(s); }
int main(int argc, char **argv) { GSM_Debug_Info *debug_info; GSM_Phone_ATGENData *Priv; GSM_Phone_Data *Data; unsigned char buffer[BUFFER_SIZE]; FILE *f; size_t len; GSM_StateMachine *s; GSM_Protocol_Message msg; GSM_Error error; GSM_NetworkInfo NetworkInfo; /* Check parameters */ if (argc != 2) { printf("Not enough parameters!\nUsage: at-creg-reply comm.dump\n"); return 1; } /* Open file */ f = fopen(argv[1], "r"); if (f == NULL) { printf("Could not open %s\n", argv[1]); return 1; } /* Read data */ len = fread(buffer, 1, sizeof(buffer) - 1, f); if (!feof(f)) { printf("Could not read whole file %s\n", argv[1]); fclose(f); return 1; } /* Zero terminate data */ buffer[len] = 0; /* Close file */ fclose(f); /* Configure state machine */ debug_info = GSM_GetGlobalDebug(); GSM_SetDebugFileDescriptor(stderr, FALSE, debug_info); GSM_SetDebugLevel("textall", debug_info); /* Allocates state machine */ s = GSM_AllocStateMachine(); test_result(s != NULL); debug_info = GSM_GetDebug(s); GSM_SetDebugGlobal(TRUE, debug_info); /* Initialize AT engine */ Data = &s->Phone.Data; Data->ModelInfo = GetModelData(NULL, NULL, "unknown", NULL); Data->NetworkInfo = &NetworkInfo; Data->RequestID = ID_GetNetworkInfo; Priv = &s->Phone.Data.Priv.ATGEN; Priv->ReplyState = AT_Reply_OK; Priv->SMSMode = SMS_AT_PDU; Priv->Charset = AT_CHARSET_UCS2; /* Init message */ msg.Type = 0; msg.Length = len; msg.Buffer = buffer; SplitLines(msg.Buffer, msg.Length, &Priv->Lines, "\x0D\x0A", 2, "\"", 1, TRUE); /* Parse it */ error = ATGEN_ReplyGetNetworkLAC_CID(msg, s); /* This is normally done by ATGEN_Terminate */ FreeLines(&Priv->Lines); GetLineString(NULL, NULL, 0); /* Free state machine */ GSM_FreeStateMachine(s); gammu_test_result(error, "ATGEN_ReplyGetCNMIMode"); printf("Network: %d\nLAC: %s\nCID: %s\n", NetworkInfo.State, NetworkInfo.LAC, NetworkInfo.CID); return 0; }
extern GSM_Error N6510_ReplyGetSMSMessage(GSM_Protocol_Message msg, GSM_StateMachine * s); int main(int argc UNUSED, char **argv UNUSED) { GSM_Debug_Info *debug_info; GSM_StateMachine *s; GSM_Protocol_Message msg; GSM_Error error; GSM_MultiSMSMessage sms; debug_info = GSM_GetGlobalDebug(); GSM_SetDebugFileDescriptor(stderr, FALSE, debug_info); GSM_SetDebugLevel("textall", debug_info); /* Allocates state machine */ s = GSM_AllocStateMachine(); test_result(s != NULL); debug_info = GSM_GetDebug(s); GSM_SetDebugGlobal(TRUE, debug_info); GSM_SetDebugFileDescriptor(stderr, FALSE, debug_info); GSM_SetDebugLevel("textall", debug_info); s->Phone.Data.ModelInfo = GetModelData(NULL, NULL, "unknown", NULL); /* Init message */ msg.Type = 0x14; msg.Length = sizeof(data); msg.Buffer = data; s->Phone.Data.GetSMSMessage = &sms;
THREAD_RETURN SearchPhoneThread(void * arg) { int j; OneDeviceInfo *Info = arg; GSM_Error error; GSM_StateMachine *search_gsm; GSM_Config *smcfg; GSM_Config *globalcfg; /* Iterate over all connections */ for (j = 0; strlen(Info->Connections[j].Connection) != 0; j++) { /* Allocate state machine */ search_gsm = GSM_AllocStateMachine(); if (search_gsm == NULL) return THREAD_RETURN_VAL; /* Get configuration pointers */ smcfg = GSM_GetConfig(search_gsm, 0); globalcfg = GSM_GetConfig(gsm, 0); /* We share some configuration with global one */ smcfg->UseGlobalDebugFile = globalcfg->UseGlobalDebugFile; smcfg->DebugFile = strdup(globalcfg->DebugFile); strcpy(smcfg->DebugLevel, globalcfg->DebugLevel); /* Configure the tested state machine */ smcfg->Device = strdup(Info->Device); smcfg->Connection = strdup(Info->Connections[j].Connection); smcfg->SyncTime = FALSE; smcfg->Model[0] = 0; smcfg->LockDevice = FALSE; smcfg->StartInfo = FALSE; /* We have only one configured connection */ GSM_SetConfigNum(search_gsm, 1); /* Let's connect */ error = GSM_InitConnection(search_gsm, 1); printf(_("Connection \"%s\" on device \"%s\"\n"), Info->Connections[j].Connection, Info->Device); /* Did we succeed? Show info */ if (error == ERR_NONE) { SearchPrintPhoneInfo(search_gsm); } else { SearchPrintf("\t%s\n", GSM_ErrorString(error)); } if (error != ERR_DEVICEOPENERROR) { GSM_TerminateConnection(search_gsm); } if (error == ERR_DEVICEOPENERROR) break; /* Free allocated buffer */ GSM_FreeStateMachine(search_gsm); } return THREAD_RETURN_VAL; }
int main(int argc, char **argv) { GSM_Debug_Info *debug_info; GSM_Phone_ATGENData *Priv; GSM_Phone_Data *Data; unsigned char buffer[BUFFER_SIZE]; FILE *f; size_t len; GSM_StateMachine *s; GSM_Protocol_Message msg; GSM_Error error; GSM_MultiSMSMessage sms; GSM_SMSDConfig *smsd; #if 0 GSM_SMS_Backup bkp; #endif /* Check parameters */ if (argc != 2 && argc != 3) { printf("Not enough parameters!\nUsage: sms-at-parse comm.dump [PDU|TXT|TXTDETAIL]\n"); return 1; } /* Open file */ f = fopen(argv[1], "r"); if (f == NULL) { printf("Could not open %s\n", argv[1]); return 1; } /* Read data */ len = fread(buffer, 1, sizeof(buffer) - 1, f); if (!feof(f)) { printf("Could not read whole file %s\n", argv[1]); fclose(f); return 1; } smsd = SMSD_NewConfig("test"); /* Zero terminate data */ buffer[len] = 0; /* Close file */ fclose(f); /* Configure state machine */ debug_info = GSM_GetGlobalDebug(); GSM_SetDebugFileDescriptor(stderr, FALSE, debug_info); GSM_SetDebugLevel("textall", debug_info); /* Allocates state machine */ s = GSM_AllocStateMachine(); test_result(s != NULL); debug_info = GSM_GetDebug(s); GSM_SetDebugGlobal(TRUE, debug_info); /* Initialize AT engine */ Data = &s->Phone.Data; Data->ModelInfo = GetModelData(NULL, NULL, "unknown", NULL); Priv = &s->Phone.Data.Priv.ATGEN; Priv->ReplyState = AT_Reply_OK; Priv->Charset = AT_CHARSET_GSM; if (argc == 3 && strcmp(argv[2], "TXT") == 0) { Priv->SMSMode = SMS_AT_TXT; Priv->SMSTextDetails = FALSE; } else if (argc == 3 && strcmp(argv[2], "TXTDETAIL") == 0) { Priv->SMSMode = SMS_AT_TXT; Priv->SMSTextDetails = TRUE; } else { Priv->SMSMode = SMS_AT_PDU; } /* Init message */ msg.Type = 0; msg.Length = len; msg.Buffer = buffer; SplitLines(msg.Buffer, msg.Length, &Priv->Lines, "\x0D\x0A", 2, "\"", 1, TRUE); /* Pointer to store message */ s->Phone.Data.GetSMSMessage = &sms; /* Parse it */ error = ATGEN_ReplyGetSMSMessage(&msg, s); sms.SMS[0].Memory = MEM_SM; #if 0 bkp.SMS[0] = &sms.SMS[0]; bkp.SMS[1] = NULL; GSM_AddSMSBackupFile("/tmp/back", &bkp); #endif /* Display message */ if (error == ERR_NONE) { DisplayMultiSMSInfo(&sms, FALSE, TRUE, NULL, NULL); DisplayMultiSMSInfo(&sms, TRUE, TRUE, NULL, NULL); printf("Parts: %d, count: %d, ID16: %d, ID8: %d\n", sms.SMS[0].UDH.AllParts, sms.Number, sms.SMS[0].UDH.ID16bit, sms.SMS[0].UDH.ID8bit); SMSD_RunOnReceiveEnvironment(&sms, smsd, "1"); } /* This is normally done by ATGEN_Terminate */ FreeLines(&Priv->Lines); GetLineString(NULL, NULL, 0); /* Free state machine */ GSM_FreeStateMachine(s); gammu_test_result(error, "ATGEN_ReplyGetSMSMessage"); return 0; }
int main(int argc, char **argv) { GSM_Debug_Info *debug_info; GSM_Phone_ATGENData *Priv; GSM_Phone_Data *Data; unsigned char buffer[BUFFER_SIZE]; FILE *f; size_t len; GSM_StateMachine *s; GSM_Protocol_Message msg; GSM_Error error; GSM_SMSC SMSC; /* Check parameters */ if (argc != 2) { printf("Not enough parameters!\nUsage: get-smsc-at comm.dump\n"); return 1; } /* Open file */ f = fopen(argv[1], "r"); test_result(f != NULL); /* Read data */ len = fread(buffer, 1, sizeof(buffer) - 1, f); test_result(feof(f)); /* Zero terminate data */ buffer[len] = 0; /* Close file */ fclose(f); /* Configure state machine */ debug_info = GSM_GetGlobalDebug(); GSM_SetDebugFileDescriptor(stderr, FALSE, debug_info); GSM_SetDebugLevel("textall", debug_info); /* Allocates state machine */ s = GSM_AllocStateMachine(); test_result(s != NULL); debug_info = GSM_GetDebug(s); GSM_SetDebugGlobal(TRUE, debug_info); GSM_SetDebugFileDescriptor(stderr, FALSE, debug_info); GSM_SetDebugLevel("textall", debug_info); /* Initialize AT engine */ Data = &s->Phone.Data; Data->ModelInfo = GetModelData(NULL, NULL, "unknown", NULL); Priv = &s->Phone.Data.Priv.ATGEN; Priv->ReplyState = AT_Reply_OK; Priv->SMSMode = SMS_AT_PDU; Priv->Charset = AT_CHARSET_UCS2; /* Init message */ msg.Type = 0; msg.Length = len; msg.Buffer = buffer; SplitLines(msg.Buffer, msg.Length, &Priv->Lines, "\x0D\x0A", 2, "\"", 1, TRUE); /* Pointer to store message */ s->Phone.Data.SMSC = &SMSC; /* Parse it */ error = ATGEN_ReplyGetSMSC(msg, s); /* This is normally done by ATGEN_Terminate */ FreeLines(&Priv->Lines); GetLineString(NULL, NULL, 0); /* Free state machine */ GSM_FreeStateMachine(s); printf("%s\n", GSM_ErrorString(error)); return (error == ERR_NONE) ? 0 : 1; }