Ejemplo n.º 1
0
/**
 * @name gammu_create_if_necessary:
 */
gammu_state_t *gammu_create_if_necessary(gammu_state_t **sp) {

  if (*sp != NULL) {
    return *sp;
  }

  gammu_state_t *rv = gammu_create(app.gammu_configuration_path);

  if (!rv) {
    return NULL;
  }

  if (app.verbose) {

    /* Enable global debugging to stderr */
    GSM_Debug_Info *debug_info = GSM_GetGlobalDebug();
    GSM_SetDebugFileDescriptor(stderr, TRUE, debug_info);
    GSM_SetDebugLevel("textall", debug_info);

    /* Enable state machine debugging to stderr */
    debug_info = GSM_GetDebug(rv->sm);
    GSM_SetDebugGlobal(FALSE, debug_info);
    GSM_SetDebugFileDescriptor(stderr, TRUE, debug_info);
    GSM_SetDebugLevel("textall", debug_info);
  }

  *sp = rv;
  return rv;
}
Ejemplo n.º 2
0
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);
}
Ejemplo n.º 3
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_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;
}
Ejemplo n.º 4
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_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;
}
Ejemplo n.º 5
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;
}