Exemple #1
0
/* If initialised in debug mode, stdin/out is used instead
   of ptys for interface. */
int gn_vm_initialise(const char *iname, const char *bindir, int debug_mode, int GSMInit)
{
	static struct gn_statemachine State;
	sm = &State;
	queue.n = 0;
	queue.head = 0;
	queue.tail = 0;

	CommandMode = true;

	if (debug_mode == true) {
		UseSTDIO = true;
	} else {
		UseSTDIO = false;
	}

	if (GSMInit) {
		dprintf("Initialising GSM\n");
		if (gn_cfg_phone_load(iname, sm) != GN_ERR_NONE) return false;
		if ((VM_GSMInitialise(sm) != GN_ERR_NONE)) {
			fprintf (stderr, _("gn_vm_initialise - VM_GSMInitialise failed!\n"));
			return (false);
		}
	}
	GSMInit = false;

	if (VM_PtySetup(bindir) < 0) {
		fprintf (stderr, _("gn_vm_initialise - VM_PtySetup failed!\n"));
		return (false);
	}

	if (gn_atem_initialise(PtyRDFD, PtyWRFD, sm) != true) {
		fprintf (stderr, _("gn_vm_initialise - gn_atem_initialise failed!\n"));
		return (false);
	}

	if (dp_Initialise(PtyRDFD, PtyWRFD) != true) {
		fprintf (stderr, _("gn_vm_initialise - dp_Initialise failed!\n"));
		return (false);
	}

	return (true);
}
Exemple #2
0
/* If initialised in debug mode, stdin/out is used instead
   of ptys for interface. */
bool gn_vm_initialise(const char *iname, bool GSMInit)
{
	static struct gn_statemachine State;
	sm = &State;
	queue.n = 0;
	queue.head = 0;
	queue.tail = 0;

	CommandMode = true;

	if (GSMInit) {
		dprintf("Initialising GSM\n");
		if (gn_cfg_phone_load(iname, sm) != GN_ERR_NONE) return false;
		if ((VM_GSMInitialise(sm) != GN_ERR_NONE)) {
			fprintf (stderr, _("gn_vm_initialise - VM_GSMInitialise failed!\n"));
			return (false);
		}
	}
	GSMInit = false;

	if (VM_PtySetup() < 0) {
		fprintf (stderr, _("gn_vm_initialise - VM_PtySetup failed!\n"));
		return (false);
	}

	if (gn_atem_initialise(sm) != true) {
		fprintf (stderr, _("gn_vm_initialise - gn_atem_initialise failed!\n"));
		return (false);
	}

	if (dp_Initialise() != true) {
		fprintf (stderr, _("gn_vm_Initialise - dp_Initialise failed!\n"));
		return (false);
	}

	return (true);
}
Exemple #3
0
int main(int argc, char *argv[])
{
	const char *aux;
	static bool atexit_registered = false;
	struct gn_statemachine temp_state;

	/* For GNU gettext */
#ifdef ENABLE_NLS
	setlocale(LC_ALL, "");
	bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
	textdomain(GETTEXT_PACKAGE);
#endif

	short_version();

	/* Handle command line arguments. */
	switch (argc) {
	case 1:
		/* Default */
		DebugMode = false;
		break;
	case 2:
		if (strcmp(argv[1], "--version") == 0) {
			/* Display version, copyright and build information. */
			version();
			exit(0);
		} else if (strcmp(argv[1], "--debug") == 0) {
			/* Use stdin/stdout for I/O */
			DebugMode = true;
			break;
		} else if (strcmp(argv[1], "--help") == 0) {
			usage();
			exit(0);
		}
		/* FALL TROUGH */
	default:
		usage();
		exit(1);
	}

	aux = gn_lib_cfg_get("global", "model");
	if (!aux) {
		fprintf(stderr, "%s\n", gn_error_print(GN_ERR_NOCONFIG));
		exit(1);
		}

	if (strncmp(aux, "5110", 4) &&
	    strncmp(aux, "5130", 4) &&
	    strncmp(aux, "6110", 4) &&
	    strncmp(aux, "6130", 4) &&
	    strncmp(aux, "6150", 4)) {
		fprintf(stderr, _("gnokiid purpose is to work only with the phones that do not have AT Hayes\ncommands interpreter.\n"));
		exit(1);
	}

	BinDir = gn_lib_cfg_get("global", "bindir");
	if (!BinDir) BinDir = gn_lib_cfg_get("gnokiid", "bindir");
	if (!BinDir) BinDir = SBINDIR;

	if (gn_cfg_phone_load("", &temp_state) != GN_ERR_NONE) exit(-1);

	gn_elog_handler = NULL;

	if (temp_state.config.use_locking) {
		lockfile = gn_device_lock(temp_state.config.port_device);
		if (lockfile == NULL) {
			fprintf(stderr, _("Lock file error. Exiting.\n"));
			exit(1);
		}
	}

	/* register cleanup function */
	if (!atexit_registered) {
		atexit_registered = true;
		atexit(busterminate);
	}

	while (1) {
		if (gn_vm_initialise("", BinDir, DebugMode, true) == false) {
			exit (-1);
		}

		GTerminateThread = false;

		gn_vm_loop();
	}

	exit (0);
}
Exemple #4
0
static QString businit(void)
{
	gn_error error;
	char *aux;

	if (gn_cfg_read(&BinDir)<0 || !gn_cfg_phone_load("", &state))
		return i18n("GNOKII isn't yet configured.");

	gn_data_clear(&data);

	aux = gn_cfg_get(gn_cfg_info, "global", "use_locking");
	// Defaults to 'no'
	if (aux && !strcmp(aux, "yes")) {
		lockfile = gn_device_lock(state.config.port_device);
		if (lockfile == NULL) {
			return i18n("Lock file error.\n "
			"Please exit all other running instances of gnokii and try again.");
		}
	}

	// Initialise the code for the GSM interface.
	int old_dcd = state.config.require_dcd; // work-around for older gnokii versions
	state.config.require_dcd = false;
	error = gn_gsm_initialise(&state);
	GNOKII_CHECK_ERROR(error);
	state.config.require_dcd = old_dcd;
	if (error != GN_ERR_NONE) {
		busterminate();
		return i18n("Mobile phone interface initialization failed:\n%1").arg(gn_error_print(error));
	}

	// model
	gn_data_clear(&data);
	data.model = model;
	model[0] = 0;
	error = gn_sm_functions(GN_OP_GetModel, &data, &state);
	GNOKII_CHECK_ERROR(error);
	if (model[0] == 0)
		strcpy(model, i18n("unknown").utf8());
	data.model = NULL;

	// revision
	data.revision = revision;
	revision[0] = 0;
	error = gn_sm_functions(GN_OP_GetRevision, &data, &state);
	GNOKII_CHECK_ERROR(error);
	data.revision = NULL;

	// imei	
	data.imei = imei;
	imei[0] = 0;
	error = gn_sm_functions(GN_OP_GetImei, &data, &state);
	GNOKII_CHECK_ERROR(error);
	data.imei = NULL;

	GNOKII_DEBUG( QString("Found mobile phone: Model: %1, Revision: %2, IMEI: %3\n")
				.arg(model).arg(revision).arg(imei) ); 

	PhoneProductId = QString("%1-%2-%3-%4").arg(APP).arg(model).arg(revision).arg(imei);

	return QString::null;
}