예제 #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;
}
예제 #2
0
int main(int argc, char **argv)
{
	int rc = 0;
	GSM_Debug_Info *debug_info;

	debug_info = GSM_GetGlobalDebug();
	GSM_SetDebugFileDescriptor(stderr, FALSE, debug_info);
	GSM_SetDebugLevel("textall", debug_info);

	rc |= single_test("CAL33, CAL52,SQWE", ERR_NONE);
	rc |= single_test("CAL33, FOO,SQWE", ERR_BADFEATURE);
	rc |= single_test("CAL33, NO_ATOBEX ,SQWE", ERR_NONE);
	rc |=
	    single_test
	    ("CAL33, NO_ATOBEX ,SQWE, CAL33, NO_ATOBEX ,SQWE, CAL52,CAL33, NO_ATOBEX ,SQWE, CAL33, NO_ATOBEX ,SQWE, CAL52,CAL33, NO_ATOBEX ,SQWE, CAL33, NO_ATOBEX ,SQWE, CAL52",
	     ERR_MOREMEMORY);

	return rc;
}
예제 #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;
}
예제 #4
0
	0x85, 0x82, 0x0C, 0x02, 0x08, 0x07, 0x91, 0x64, 0x07, 0x05, 0x80, 0x99, 0xF9, 0x80, 0x0D, 0x09,
	0x0A, 0x08, 0x0D, 0x02, 0x00, 0x07, 0x0B, 0x02, 0x00, 0x00, 0x08, 0x05, 0x01, 0xFF, 0x00,
};

/* This is not part of API! */
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 */
예제 #5
0
/**
 * @name action_send_messages:
 */
int action_send_messages(gammu_state_t **sp,
                         int argc, char *argv[]) {

  int rv = 0;
  char **argp = &argv[1];

  if (argc <= 2) {
    print_usage_error(U_ERR_ARGS_MISSING);
    return 1;
  }

  if (argc % 2 != 1) {
    print_usage_error(U_ERR_ARGS_ODD);
    return 2;
  }

  /* Lazy initialization of libgammu */
  gammu_state_t *s = gammu_create_if_necessary(sp);

  if (!s) {
    print_operation_error(OP_ERR_INIT);
    rv = 3; goto cleanup;
  }

  /* Allocate */
  smsc_t *smsc = allocate(sizeof(*smsc));
  multimessage_t *sms = allocate(sizeof(*sms));
  multimessage_info_t *info = allocate(sizeof(*info));

  /* Find SMSC number */
  smsc->Location = 1;

  if ((s->err = GSM_GetSMSC(s->sm, smsc)) != ERR_NONE) {
    print_operation_error(OP_ERR_SMSC);
    rv = 4; goto cleanup_sms;
  }

  transmit_status_t status;
  initialize_transmit_status(&status);

  GSM_SetSendSMSStatusCallback(
    s->sm, _message_transmit_callback, &status
  );

  boolean_t is_start = TRUE;
  unsigned int message_index = 0;

  printf("[");

  /* For each message... */
  while (*argp != NULL) {

    GSM_ClearMultiPartSMSInfo(info);
    GSM_Debug_Info *debug = GSM_GetGlobalDebug();

    /* Copy/convert destination phone number */
    char *sms_destination_number = convert_utf8_utf16be(*argp++, FALSE);

    if (!sms_destination_number) {
      status.err = "Invalid UTF-8 sequence in destination number";
      goto cleanup_end;
    }

    string_info_t nsi;
    utf16be_string_info(sms_destination_number, &nsi);

    /* Check size of phone number:
        We'll be decoding this in to a fixed-sized buffer. */

    if (nsi.units >= GSM_MAX_NUMBER_LENGTH) {
      status.err = "Phone number is too long";
      goto cleanup_transmit_status;
    }

    /* Missing message text:
        This shouldn't happen since we check `argc` above,
        but I'm leaving this here in case we refactor later. */

    if (*argp == NULL) {
      status.err = "No message body provided";
      goto cleanup_transmit_status;
    }

    /* UTF-8 message content */
    char *sms_message = *argp++;

    /* Convert message from UTF-8 to UTF-16-BE:
        Every symbol is two bytes long; the string is then
        terminated by a single 2-byte UTF-16 null character. */

    char *sms_message_utf16be = convert_utf8_utf16be(sms_message, FALSE);

    if (!sms_message_utf16be) {
      status.err = "Invalid UTF-8 sequence";
      goto cleanup_transmit_status;
    }

    /* Prepare message info structure:
        This information is used to encode the possibly-multipart SMS. */

    info->Class = 1;
    info->EntriesNum = 1;
    info->Entries[0].ID = SMS_ConcatenatedTextLong;
    info->Entries[0].Buffer = (uint8_t *) sms_message_utf16be;
    info->UnicodeCoding = !utf16be_is_gsm_string(sms_message_utf16be);

    if ((s->err = GSM_EncodeMultiPartSMS(debug, info, sms)) != ERR_NONE) {
      status.err = "Failed to encode message";
      goto cleanup_sms_text;
    }

    status.parts_sent = 0;
    status.parts_total = sms->Number;

    /* For each SMS part... */
    for (unsigned int i = 0; i < sms->Number; i++) {

      status.finished = FALSE;
      status.message_part_index = i;

      sms->SMS[i].PDU = SMS_Submit;

      /* Copy destination phone number:
           This is a fixed-size buffer; size was already checked above. */

      CopyUnicodeString(sms->SMS[i].SMSC.Number, smsc->Number);

      CopyUnicodeString(
        sms->SMS[i].Number, (unsigned char *) sms_destination_number
      );

      /* Transmit a single message part */
      if ((s->err = GSM_SendSMS(s->sm, &sms->SMS[i])) != ERR_NONE) {
        status.parts[i].err = "Message transmission failed";
        continue;
      }

      for (;;) {
        /* Wait for reply */
        GSM_ReadDevice(s->sm, TRUE);

        if (status.finished) {
          break;
        }
      }

      if (!status.parts[i].transmitted) {
        status.parts[i].err = "Message delivery failed";
        continue;
      }

      status.parts_sent++;
    }

    cleanup_sms_text:
      status.message_index = ++message_index;
      free(sms_message_utf16be);

    cleanup_transmit_status:
      print_json_transmit_status(s, sms, &status, is_start);
      free(sms_destination_number);

    cleanup_end:
      is_start = FALSE;
  }

  cleanup_sms:

    free(sms);
    free(smsc);
    free(info);
    printf("]\n");
  
  cleanup:

    return rv;
}
예제 #6
0
파일: vcard-read.c 프로젝트: AndyLavr/gammu
int main(int argc, char **argv)
{
	size_t pos = 0;
	GSM_MemoryEntry pbk;
	GSM_Error error;
	FILE *f;
	size_t len;
	gboolean generate = FALSE;
	GSM_Backup backup;
	int i;
	GSM_Debug_Info *debug_info;

	/* Configure debugging */
	debug_info = GSM_GetGlobalDebug();
	GSM_SetDebugFileDescriptor(stderr, FALSE, debug_info);
	GSM_SetDebugLevel("textall", debug_info);

	/* Check parameters */
	if (argc != 3 && argc != 4) {
		printf("Not enough parameters!\nUsage: vcard-read file.vcf file.backup\n");
		return 1;
	}

	/* Check for generating option */
	if (argc == 4 && strcmp(argv[3], "generate") == 0) {
		generate = TRUE;
	}

	/* 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 string */
	buffer[len] = 0;

	/* We don't need file any more */
	fclose(f);

	/* Parse vCard */
	error = GSM_DecodeVCARD(NULL, buffer, &pos, &pbk, SonyEricsson_VCard21);
	gammu_test_result(error, "GSM_DecodeVCARD");

	/* Encode vCard back */
	pos = 0;
	error = GSM_EncodeVCARD(NULL, vcard_buffer, sizeof(vcard_buffer), &pos, &pbk, TRUE, SonyEricsson_VCard21);
	gammu_test_result(error, "GSM_EncodeVCARD");

	/*
	 * Best would be to compare here, but we never can get
	 * absolutely same as original.
	 */
	printf("ORIGINAL:\n%s\n----\nENCODED:\n%s\n", buffer, vcard_buffer);

	/* Generate file if we should */
	if (generate) {
		GSM_ClearBackup(&backup);
		strcpy(backup.Creator, "vCard tester");
		pbk.Location = 0;
		backup.PhonePhonebook[0] = &pbk;
		backup.PhonePhonebook[1] = NULL;
		error = GSM_SaveBackupFile(argv[2], &backup, TRUE);
		gammu_test_result(error, "GSM_SaveBackupFile");
	}

	/* Read file content */
	GSM_ClearBackup(&backup);
	error = GSM_ReadBackupFile(argv[2], &backup, GSM_Backup_GammuUCS2);
	gammu_test_result(error, "GSM_ReadBackupFile");

	/* Compare size */
	test_result(pbk.EntriesNum == backup.PhonePhonebook[0]->EntriesNum);

	/* Compare content */
	for (i = 0; i < pbk.EntriesNum; i++) {
		test_result(pbk.Entries[i].EntryType == backup.PhonePhonebook[0]->Entries[i].EntryType);
		printf("Entry type: %d\n", pbk.Entries[i].EntryType);
		switch (pbk.Entries[i].EntryType) {
			case PBK_Number_General:
			case PBK_Number_Mobile:
			case PBK_Number_Fax:
			case PBK_Number_Pager:
			case PBK_Number_Other:
			case PBK_Number_Messaging:
			case PBK_Number_Video:
			case PBK_Text_Note:
			case PBK_Text_Postal:
			case PBK_Text_Email:
			case PBK_Text_Email2:
			case PBK_Text_URL:
			case PBK_Text_LUID:
			case PBK_Text_Name:
			case PBK_Text_LastName:
			case PBK_Text_FirstName:
			case PBK_Text_SecondName:
			case PBK_Text_FormalName:
			case PBK_Text_NamePrefix:
			case PBK_Text_NameSuffix:
			case PBK_Text_NickName:
			case PBK_Text_Company:
			case PBK_Text_JobTitle:
			case PBK_Text_StreetAddress:
			case PBK_Text_City:
			case PBK_Text_State:
			case PBK_Text_Zip:
			case PBK_Text_Country:
			case PBK_Text_Custom1:
			case PBK_Text_Custom2:
			case PBK_Text_Custom3:
			case PBK_Text_Custom4:
			case PBK_Text_UserID:
			case PBK_Text_PictureName:
			case PBK_PushToTalkID:
			case PBK_Text_VOIP:
			case PBK_Text_SWIS:
			case PBK_Text_WVID:
			case PBK_Text_SIP:
			case PBK_Text_DTMF:
				test_result(mywstrncmp(pbk.Entries[i].Text, backup.PhonePhonebook[0]->Entries[i].Text, 0) == TRUE);
				break;
			case PBK_Photo:
				test_result((pbk.Entries[i].Picture.Length ==
					     backup.PhonePhonebook[0]->Entries[i].Picture.Length) &&
					    memcmp(pbk.Entries[i].Picture.Buffer, backup.PhonePhonebook[0]->Entries[i].Picture.Buffer, pbk.Entries[i].Picture.Length) == 0);
				free(pbk.Entries[i].Picture.Buffer);
				break;
			case PBK_Date:
			case PBK_LastModified:
				break;
			case PBK_Category:
			case PBK_Private:
			case PBK_RingtoneID:
			case PBK_PictureID:
			case PBK_CallLength:
			case PBK_Caller_Group:
				test_result(pbk.Entries[i].Number == backup.PhonePhonebook[0]->Entries[i].Number);
				break;
		}
	}

	error = PrintMemoryEntry(&pbk, NULL);
	gammu_test_result(error, "PrintMemoryEntry");

	/* Free data */
	GSM_FreeBackup(&backup);

	/* We're done */
	return 0;
}
예제 #7
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;
}
예제 #8
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;
}