Beispiel #1
0
/*
 * Display the mechanism list for a kernel hardware provider.
 * This implements part of the "cryptoadm list -m" command.
 */
int
list_mechlist_for_hard(char *provname)
{
	mechlist_t	*pmechlist = NULL;
	char		devname[MAXNAMELEN];
	int		inst_num;
	int		count;
	int		rc = SUCCESS;

	if (provname == NULL) {
		return (FAILURE);
	}

	/*
	 * Check if the provider is valid. If it is valid, get the number of
	 * mechanisms also.
	 */
	if (check_hardware_provider(provname, devname, &inst_num, &count) ==
	    FAILURE) {
		return (FAILURE);
	}

	/* Get the mechanism list for the kernel hardware provider */
	if ((rc = get_dev_info(devname, inst_num, count, &pmechlist)) ==
	    SUCCESS) {
		(void) filter_mechlist(&pmechlist, RANDOM);
		print_mechlist(provname, pmechlist);
		free_mechlist(pmechlist);
	}

	return (rc);
}
Beispiel #2
0
/*
data:{"sn":"02ffff99909009"
}*/
int lbapp::dev_login(param_list * pl){

	log_out(log_debug, "dev_login:: %s\n", pl->content);
	//sn��
	cJSON * jssn = cJSON_GetObjectItem(pl->jsdata, "sn");
	if (!jssn || jssn->type != cJSON_String){
		log_out(log_error, "dev_login::sn invalid\n");
		post_ack(pl->n, device_login_ldb_ack, pl->serial, ERROR_PARAM, "no sn");
		return -1;
	}
	
	//У����Ϣ
	device_s ds = {0};
	int ret = get_dev_info(jssn->valuestring, ds);
	if(ret < 0){
		log_out(log_debug, "dev_login::get_dev_info fail\n");
		post_ack(pl->n, device_login_ldb_ack, pl->serial, ERROR_INVALID_SN, "invalid sn");
		return -1;
	}

	uint now = (uint)time(NULL);
	//�����Ƿ�����
	if(ds.expire < now){
		log_out(log_error, "dev_login::license expire %u\n", ds.expire);
		post_ack(pl->n, device_login_ldb_ack, pl->serial, ERROR_LICENSE_EXPOIRE, "license timeout");
		return -1;
	}

	//������¼������
	ipaddr peeraddr = pl->n->get_peeraddr();
	real_node *rnode = svr_hash::instance_devmgr()->search_node(jssn->valuestring);
	if(!rnode){
		log_out(log_error, "dev_login::no available server\n");
		post_ack(pl->n, device_login_ldb_ack, pl->serial, ERROR_ALLOCATE_SERVER, "no available server");
		return -1;
	}

	//����token
	char key[64] = {0};
	sprintf(key, "%08X%08X%08X",ds.device, ds.company, now + 300);

	char token[128] = {0};
	sim_encrypt(key, token);

	char sendbuf[256] = {0};
	sprintf(sendbuf, "{\"token\":\"%s\",\"devmgr\":\"%s\"}",token, rnode->identify);

	post_ack(pl->n, device_login_ldb_ack, pl->serial, ERROR_OK, "ok", sendbuf);
	log_out(log_debug, "dev_login::ok json(%s)\n", sendbuf);

	return 0;
}
Beispiel #3
0
/*
data:{"sn":"02ffff99909009"
}*/
int lbapp::dev_login(param_list * pl){

	ipaddr & peeraddr = pl->n->get_peeraddr();
	log_out(log_debug, "dev_login::from(%s:%d) %s\n", peeraddr.ip, peeraddr.port, pl->content);
	
	cJSON * jssn = cJSON_GetObjectItem(pl->jsdata, "sn");
	if (!jssn || jssn->type != cJSON_String || !strlen(jssn->valuestring)){
		log_out(log_error, "dev_login::sn invalid\n");
		post_ack(pl->n, device_login_ldb_ack, pl->serial, ERROR_PARAM, "invalid sn");
		return -1;
	}
	
	//防止登录太频繁
	uint now = (uint)time(NULL);
	if(login_session::instance()->check_frequently(jssn->valuestring, now) < 0){
		log_out(log_warn, "dev_login::sn(%s) login too frequently < %us\n", jssn->valuestring, frequently_min);	
		post_ack(pl->n, device_login_ldb_ack, pl->serial, ERROR_TOO_FREQUENTLY, "too frequently");
		return -1;
	}
	
	device_s ds;
	int ret = get_dev_info(jssn->valuestring, ds);
	if(ret < 0){
		log_out(log_debug, "dev_login::get_dev_info fail\n");
		post_ack(pl->n, device_login_ldb_ack, pl->serial, ERROR_INVALID_SN, "invalid sn");
		return -1;
	}

	char encrypt_token[max_token_len] = {0};
	sim_encrypt(jssn->valuestring, encrypt_token);

	char sendbuf[256] = {0};
	sprintf(sendbuf, "{\"token\":\"%s\",\"devmgr\":\"%s\"}",encrypt_token, ds.mgr);

	post_ack(pl->n, device_login_ldb_ack, pl->serial, ERROR_OK, "ok", sendbuf);
	log_out(log_debug, "dev_login::ok json(%s)\n", sendbuf);

	return 0;
}
static int
raw3215_find_dev(int number)
{
	s390_dev_info_t dinfo;
	int irq;
	int count;

	irq = get_irq_first();
	count = 0;
        while (count <= number && irq != -ENODEV) {
                if (get_dev_info(irq, &dinfo) == -ENODEV)
                        break;
                if (dinfo.devno == console_device ||
                    dinfo.sid_data.cu_type == 0x3215) {
                        count++;
                    if (count > number)
                        return irq;
                }
                irq = get_irq_next(irq);
        }
        return -1;            /* console not found */
}
Beispiel #5
0
static int
mod_generic_ioctl(struct inode *ino, struct file *file,
		  unsigned int cmd, unsigned long arg)
{
	struct dev_info *di;
	int rc, flags = 0, rvalp = 0;
	cred_t *cr = NULL;

	di = get_dev_info(MKDEV(imajor(ino), iminor(ino)));
	if (di == NULL)
		return -EINVAL;

	rc = di->di_ops->devo_cb_ops->cb_ioctl(di->di_dev,
	                                       (int)cmd, (intptr_t)arg,
	                                       flags, cr, &rvalp);
	/*
	 * The Solaris the kernel returns positive error codes to indicate
	 * a failure.  Under linux the kernel is expected to return a
	 * small negative value which is trapped by libc and used to
	 * set errno correctly.  For this reason we negate the Solaris
	 * return code to ensure errno gets set correctly.
	 */
	return -rc;
}
static int
cryptoadm_ioctl(dev_t dev, int cmd, intptr_t arg, int mode, cred_t *c,
    int *rval)
{
	int error;
#define	ARG	((caddr_t)arg)

	switch (cmd) {
	case CRYPTO_LOAD_DEV_DISABLED:
	case CRYPTO_LOAD_SOFT_DISABLED:
	case CRYPTO_LOAD_SOFT_CONFIG:
	case CRYPTO_UNLOAD_SOFT_MODULE:
	case CRYPTO_POOL_CREATE:
	case CRYPTO_POOL_WAIT:
	case CRYPTO_POOL_RUN:
	case CRYPTO_LOAD_DOOR:
	case CRYPTO_FIPS140_SET:
		if ((error = drv_priv(c)) != 0)
			return (error);
	default:
		break;
	}

	switch (cmd) {
	case CRYPTO_GET_DEV_LIST:
		return (get_dev_list(dev, ARG, mode, rval));

	case CRYPTO_GET_DEV_INFO:
		return (get_dev_info(dev, ARG, mode, rval));

	case CRYPTO_GET_SOFT_LIST:
		return (get_soft_list(dev, ARG, mode, rval));

	case CRYPTO_GET_SOFT_INFO:
		return (get_soft_info(dev, ARG, mode, rval));

	case CRYPTO_LOAD_DEV_DISABLED:
		return (load_dev_disabled(dev, ARG, mode, rval));

	case CRYPTO_LOAD_SOFT_DISABLED:
		return (load_soft_disabled(dev, ARG, mode, rval));

	case CRYPTO_LOAD_SOFT_CONFIG:
		return (load_soft_config(dev, ARG, mode, rval));

	case CRYPTO_UNLOAD_SOFT_MODULE:
		return (unload_soft_module(dev, ARG, mode, rval));

	case CRYPTO_POOL_CREATE:
		/*
		 * The framework allocates and initializes the pool.
		 * So, this is a no op. We are keeping this ioctl around
		 * to be used for any future threadpool related work.
		 */
		if (audit_active)
			audit_cryptoadm(CRYPTO_POOL_CREATE, NULL, NULL,
			    0, 0, 0, 0);
		return (0);

	case CRYPTO_POOL_WAIT: {
		int nthrs = 0, err;

		if ((err = kcf_svc_wait(&nthrs)) == 0) {
			if (copyout((caddr_t)&nthrs, ARG, sizeof (int))
			    == -1)
				err = EFAULT;
		}
		if (audit_active)
			audit_cryptoadm(CRYPTO_POOL_WAIT, NULL, NULL,
			    0, 0, 0, err);
		return (err);
	}

	case CRYPTO_POOL_RUN: {
		int err;

		err = kcf_svc_do_run();
		if (audit_active)
			audit_cryptoadm(CRYPTO_POOL_RUN, NULL, NULL,
			    0, 0, 0, err);
		return (err);
	}

	case CRYPTO_LOAD_DOOR:
		return (load_door(dev, ARG, mode, rval));
	case CRYPTO_FIPS140_STATUS:
		return (fips140_actions(dev, ARG, mode, rval, cmd));
	case CRYPTO_FIPS140_SET: {
		int err;

		err = fips140_actions(dev, ARG, mode, rval, cmd);
		if (audit_active)
			audit_cryptoadm(CRYPTO_FIPS140_SET, NULL, NULL,
			    0, 0, 0, err);
		return (err);
	}
	}

	return (EINVAL);
}
Beispiel #7
0
/*
 * List all the providers. And for each provider, list the mechanism list.
 * Called for "cryptoadm list -m" or "cryptoadm list -mv" .
 */
static int
list_mechlist_for_all(boolean_t verbose)
{
	crypto_get_dev_list_t	*pdevlist_kernel = NULL;
	uentrylist_t		*pliblist = NULL;
	uentrylist_t		*plibptr = NULL;
	entry_t			*pent = NULL;
	mechlist_t		*pmechlist = NULL;
	char			provname[MAXNAMELEN];
	char			devname[MAXNAMELEN];
	int			inst_num;
	int			count;
	int			i;
	int			rv;
	int			rc = SUCCESS;

	/* get user-level providers */
	(void) printf(gettext("\nUser-level providers:\n"));
	/*
	 * TRANSLATION_NOTE
	 * Strictly for appearance's sake, this line should be as long as
	 * the length of the translated text above.
	 */
	(void) printf(gettext("=====================\n"));
	if (get_pkcs11conf_info(&pliblist) != SUCCESS) {
		cryptoerror(LOG_STDERR, gettext("failed to retrieve "
		    "the list of user-level providers.\n"));
		rc = FAILURE;
	}

	plibptr = pliblist;
	while (plibptr != NULL) {
		/* skip metaslot and fips-140 entry */
		if ((strcmp(plibptr->puent->name, METASLOT_KEYWORD) != 0) &&
		    (strcmp(plibptr->puent->name, FIPS_KEYWORD) != 0)) {
			(void) printf(gettext("\nProvider: %s\n"),
			    plibptr->puent->name);
			rv = list_mechlist_for_lib(plibptr->puent->name,
			    mecharglist, NULL, B_FALSE, verbose, B_TRUE);
			if (rv == FAILURE) {
				rc = FAILURE;
			}
		}
		plibptr = plibptr->next;
	}
	free_uentrylist(pliblist);

	/* get kernel software providers */
	(void) printf(gettext("\nKernel software providers:\n"));

	/*
	 * TRANSLATION_NOTE
	 * Strictly for appearance's sake, this line should be as long as
	 * the length of the translated text above.
	 */
	(void) printf(gettext("==========================\n"));
	if (getzoneid() == GLOBAL_ZONEID) {
		/* get kernel software providers from kernel ioctl */
		crypto_get_soft_list_t		*psoftlist_kernel = NULL;
		uint_t				sl_soft_count;
		char				*psoftname;
		int				i;
		entrylist_t			*pdevlist_conf = NULL;
		entrylist_t			*psoftlist_conf = NULL;

		if (get_soft_list(&psoftlist_kernel) == FAILURE) {
			cryptoerror(LOG_ERR, gettext("Failed to retrieve the "
			    "software provider list from kernel."));
			return (FAILURE);
		}
		sl_soft_count = psoftlist_kernel->sl_soft_count;

		if (get_kcfconf_info(&pdevlist_conf, &psoftlist_conf)
		    == FAILURE) {
			cryptoerror(LOG_ERR,
			    "failed to retrieve the providers' "
			    "information from file kcf.conf - %s.",
			    _PATH_KCF_CONF);
			free(psoftlist_kernel);
			return (FAILURE);
		}

		for (i = 0, psoftname = psoftlist_kernel->sl_soft_names;
		    i < sl_soft_count;
		    ++i, psoftname += strlen(psoftname) + 1) {
			pent = getent_kef(psoftname, pdevlist_conf,
			    psoftlist_conf);
			if ((pent == NULL) || (pent->load)) {
				rv = list_mechlist_for_soft(psoftname,
				    NULL, NULL);
				if (rv == FAILURE) {
					rc = FAILURE;
				}
			} else {
				(void) printf(gettext("%s: (inactive)\n"),
				    psoftname);
			}
		}

		free(psoftlist_kernel);
		free_entrylist(pdevlist_conf);
		free_entrylist(psoftlist_conf);

	} else {
		/* kcf.conf not there in non-global zone, use /dev/cryptoadm */
		entrylist_t	*pdevlist_zone = NULL;
		entrylist_t	*psoftlist_zone = NULL;
		entrylist_t	*ptr;

		if (get_admindev_info(&pdevlist_zone, &psoftlist_zone) !=
		    SUCCESS) {
			cryptoerror(LOG_STDERR, gettext("failed to retrieve "
			    "the list of kernel software providers.\n"));
			rc = FAILURE;
		}

		for (ptr = psoftlist_zone; ptr != NULL; ptr = ptr->next) {
			rv = list_mechlist_for_soft(ptr->pent->name,
			    pdevlist_zone, psoftlist_zone);
			if (rv == FAILURE) {
				(void) printf(gettext(
				    "%s: failed to get the mechanism list.\n"),
				    ptr->pent->name);
				rc = FAILURE;
			}
		}

		free_entrylist(pdevlist_zone);
		free_entrylist(psoftlist_zone);
	}

	/* Get kernel hardware providers and their mechanism lists */
	(void) printf(gettext("\nKernel hardware providers:\n"));
	/*
	 * TRANSLATION_NOTE
	 * Strictly for appearance's sake, this line should be as long as
	 * the length of the translated text above.
	 */
	(void) printf(gettext("==========================\n"));
	if (get_dev_list(&pdevlist_kernel) != SUCCESS) {
		cryptoerror(LOG_STDERR, gettext("failed to retrieve "
		    "the list of hardware providers.\n"));
		return (FAILURE);
	}

	for (i = 0; i < pdevlist_kernel->dl_dev_count; i++) {
		(void) strlcpy(devname,
		    pdevlist_kernel->dl_devs[i].le_dev_name, MAXNAMELEN);
		inst_num = pdevlist_kernel->dl_devs[i].le_dev_instance;
		count = pdevlist_kernel->dl_devs[i].le_mechanism_count;
		(void) snprintf(provname, sizeof (provname), "%s/%d", devname,
		    inst_num);
		if (get_dev_info(devname, inst_num, count, &pmechlist) ==
		    SUCCESS) {
			(void) filter_mechlist(&pmechlist, RANDOM);
			print_mechlist(provname, pmechlist);
			free_mechlist(pmechlist);
		} else {
			(void) printf(gettext("%s: failed to get the mechanism"
			    " list.\n"), provname);
			rc = FAILURE;
		}
	}
	free(pdevlist_kernel);
	return (rc);
}
Beispiel #8
0
/*
 * Disable a kernel hardware provider.
 * This implements the "cryptoadm disable" command for
 * kernel hardware providers.
 */
int
disable_kef_hardware(char *provname, boolean_t rndflag, boolean_t allflag,
    mechlist_t *dislist)
{
	crypto_load_dev_disabled_t	*pload_dev_dis = NULL;
	mechlist_t			*infolist = NULL;
	entry_t				*pent = NULL;
	boolean_t			new_dev_entry = B_FALSE;
	char				devname[MAXNAMELEN];
	int				inst_num;
	int				count;
	int				fd = -1;
	int				rc = SUCCESS;

	if (provname == NULL) {
		return (FAILURE);
	}

	/*
	 * Check if the provider is valid. If it is valid, get the number of
	 * mechanisms also.
	 */
	if (check_hardware_provider(provname, devname, &inst_num, &count)
	    == FAILURE) {
		return (FAILURE);
	}

	/* Get the mechanism list for the kernel hardware provider */
	if (get_dev_info(devname, inst_num, count, &infolist) == FAILURE) {
		return (FAILURE);
	}

	/*
	 * Get the entry of this hardware provider from the config file.
	 * If there is no entry yet, create one for it.
	 */
	if ((pent = getent_kef(provname, NULL, NULL)) == NULL) {
		if ((pent = create_entry(provname)) == NULL) {
			cryptoerror(LOG_STDERR, gettext("out of memory."));
			free_mechlist(infolist);
			return (FAILURE);
		}
		new_dev_entry = B_TRUE;
	}

	/*
	 * kCF treats random as an internal mechanism. So, we need to
	 * filter it from the mechanism list here, if we are NOT disabling
	 * or enabling the random feature. Note that we map random feature at
	 * cryptoadm(1M) level to the "random" mechanism in kCF.
	 */
	if (!rndflag) {
		(void) filter_mechlist(&dislist, RANDOM);
	}

	/* Calculate the new disabled list */
	if (disable_mechs(&pent, infolist, allflag, dislist) == FAILURE) {
		free_mechlist(infolist);
		free_entry(pent);
		return (FAILURE);
	}
	free_mechlist(infolist);

	/* If no mechanisms are to be disabled, return */
	if (pent->dis_count == 0) {
		free_entry(pent);
		return (SUCCESS);
	}

	/* Update the config file with the new entry or the updated entry */
	if (new_dev_entry) {
		rc = update_kcfconf(pent, ADD_MODE);
	} else {
		rc = update_kcfconf(pent, MODIFY_MODE);
	}

	if (rc == FAILURE) {
		free_entry(pent);
		return (FAILURE);
	}

	/* Inform kernel about the new disabled mechanism list */
	if ((pload_dev_dis = setup_dev_dis(pent)) == NULL) {
		free_entry(pent);
		return (FAILURE);
	}
	free_entry(pent);

	if ((fd = open(ADMIN_IOCTL_DEVICE, O_RDWR)) == -1) {
		cryptoerror(LOG_STDERR, gettext("failed to open %s: %s"),
		    ADMIN_IOCTL_DEVICE, strerror(errno));
		free(pload_dev_dis);
		return (FAILURE);
	}

	if (ioctl(fd, CRYPTO_LOAD_DEV_DISABLED, pload_dev_dis) == -1) {
		cryptodebug("CRYPTO_LOAD_DEV_DISABLED ioctl failed: %s",
		    strerror(errno));
		free(pload_dev_dis);
		(void) close(fd);
		return (FAILURE);
	}

	if (pload_dev_dis->dd_return_value != CRYPTO_SUCCESS) {
		cryptodebug("CRYPTO_LOAD_DEV_DISABLED ioctl return_value = "
		    "%d", pload_dev_dis->dd_return_value);
		free(pload_dev_dis);
		(void) close(fd);
		return (FAILURE);
	}

	free(pload_dev_dis);
	(void) close(fd);
	return (SUCCESS);
}
Beispiel #9
0
/*
 * Display the policy information for a kernel hardware provider.
 * This implements part of the "cryptoadm list -p" command.
 *
 * Parameters phardlist and psoftlist are supplied by getent_kef().
 * If NULL, this function obtains it by calling get_kcfconf_info() via
 * getent_kef() internally.
 * Parameter pdevlist is supplied by check_kernel_for_hard().
 * If NULL, this function obtains it by calling get_dev_list() via
 * check_kernel_for_hard() internally.
 */
int
list_policy_for_hard(char *provname,
	entrylist_t *phardlist, entrylist_t *psoftlist,
	crypto_get_dev_list_t *pdevlist)
{
	entry_t		*pent = NULL;
	boolean_t	in_kernel;
	mechlist_t	*pmechlist = NULL;
	char		devname[MAXNAMELEN];
	int		inst_num;
	int		count;
	int		rc = SUCCESS;
	boolean_t	has_random = B_FALSE;
	boolean_t 	has_mechs = B_FALSE;

	if (provname == NULL) {
		return (FAILURE);
	}

	/*
	 * Check if the provider is valid. If it is valid, get the number of
	 * mechanisms also.
	 */
	if (check_hardware_provider(provname, devname, &inst_num, &count) ==
	    FAILURE) {
		return (FAILURE);
	}

	/* Get the mechanism list for the kernel hardware provider */
	if ((rc = get_dev_info(devname, inst_num, count, &pmechlist)) ==
	    SUCCESS) {
		has_random = filter_mechlist(&pmechlist, RANDOM);

		if (pmechlist != NULL) {
			has_mechs = B_TRUE;
			free_mechlist(pmechlist);
		}
	} else {
		cryptoerror(LOG_STDERR, gettext(
		    "failed to retrieve the mechanism list for %s."),
		    devname);
		return (rc);
	}

	/*
	 * If the hardware provider has an entry in the kcf.conf file,
	 * some of its mechanisms must have been disabled.  Print out
	 * the disabled list from the config file entry.  Otherwise,
	 * if it is active, then all the mechanisms for it are enabled.
	 */
	if ((pent = getent_kef(provname, phardlist, psoftlist)) != NULL) {
		print_kef_policy(provname, pent, has_random, has_mechs);
		free_entry(pent);
		return (SUCCESS);
	} else {
		if (check_kernel_for_hard(provname, pdevlist,
		    &in_kernel) == FAILURE) {
			return (FAILURE);
		} else if (in_kernel == B_TRUE) {
			(void) printf(gettext(
			    "%s: all mechanisms are enabled."), provname);
			if (has_random)
				/*
				 * TRANSLATION_NOTE
				 * "random" is a keyword and not to be
				 * translated.
				 */
				(void) printf(gettext(" %s is enabled.\n"),
				    "random");
			else
				(void) printf("\n");
			return (SUCCESS);
		} else {
			cryptoerror(LOG_STDERR,
			    gettext("%s does not exist."), provname);
			return (FAILURE);
		}
	}
}
Beispiel #10
0
int main( int argc, char *argv[] )
{
//	unsigned long		in_buf;
//	char		 	*data_buff;
//	int ret;
 	int							c;
	optparams_t					oparams;
	int							fd;
	int							oflag;

	printf( "read_ft245 test program is started\n" );
	
	oparams.dev_name = strdup( "//9/dev/ft245" ); //!!!!
	oparams.fname = NULL;
	oparams.nonblock = 0;
	oparams.devinfo = 0;
	oparams.rx_timeout = 0;
	oparams.psize = 8;
	oparams.npackets = 30;
	oparams.verbose = 0;
	oparams.reset = 0;
	oparams.latency = 0;
	
	while ( ( c = getopt( argc, argv, "d:f:nivrs:p:t:l:" ) ) != -1 ) {
		switch( c )  {
			case 'd':
				oparams.dev_name = optarg;
				break;
			case 'f':
				oparams.fname = optarg;
				break;
			case 'n':
				oparams.nonblock = 1;
				break;
			case 'i':
				oparams.devinfo = 1;
				break;
			case 'v':
				oparams.verbose++;
				break;
			case 's':
				oparams.psize = strtoul( optarg, NULL, 0 );
				break;
			case 'p':
				oparams.npackets = strtoul( optarg, NULL, 0 );
				break;
			case 't':
				TM = 1;
				break;
			case 'r':
				oparams.reset = 1;
				break;
			case 'l':
				oparams.latency = strtoul( optarg, NULL, 0 );
				if ( oparams.latency == 0 ) {
					fprintf( stderr, "Command line: Bad latency value. Correct range is 1 - 255\n" );
					oparams.latency = 0;
				}
				break;
			default:
				fprintf( stderr, "Unsupported comand line option\n" );
				break;
		}
	}
	
	open_shmem();
	// open device in block or nonblock mode
	oflag = O_RDONLY | O_NONBLOCK;
		
	if ( ( fd = open( oparams.dev_name, oflag ) ) == -1 ) {
		fprintf( stderr, "open() failed. %s\n", strerror( errno ) );
		return ( -1 );
	}
	
	//if ( oparams.reset )		reset_device( fd );

	if ( oparams.devinfo ) 
		get_dev_info( fd );
	
	// timeout test
	if ( oparams.rx_timeout ) 
		set_rx_timeout( fd, oparams.rx_timeout );

	if ( oparams.latency ) 
		set_latency( fd, oparams.latency ); 
	
	printf( "Device latency time is %d\n", get_latency( fd ) );
	
	//if ( oparams.reset )	
	//reset_device( fd );
	
	printf( "Start data read. \n");

	read_data_nonblock1( fd, oparams.psize, oparams.npackets, oparams.fname );
	
	printf( "read_ft245 test program is finished %d\n",sum_ret );	

	close( fd );
	return( 0 );
}
Beispiel #11
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    port=new AbstractSerial(this);
    port->setTotalReadConstantTimeout(0);

    timer=new QTimer();
    settings_timer=new QTimer();

    connect(settings_timer,SIGNAL(timeout()),this,SLOT(on_set_all_calibrates_clicked()));

    p_uso=new proto_uso(this,port);
     QTextCodec::setCodecForTr(QTextCodec::codecForName("Windows-1251"));
    ui->tableWidget->setHorizontalHeaderItem(0, new QTableWidgetItem(tr("Название канала")));
    ui->tableWidget->setHorizontalHeaderItem(1, new QTableWidgetItem(tr("Тип канала")));
    ui->tableWidget->setHorizontalHeaderItem(2, new QTableWidgetItem(tr("Диапазон")));
    ui->tableWidget->setHorizontalHeaderItem(3, new QTableWidgetItem(tr("Фильтр")));
    ui->tableWidget->setHorizontalHeaderItem(4, new QTableWidgetItem(tr("Значение")));
    ui->tableWidget->setHorizontalHeaderItem(5, new QTableWidgetItem(tr("Калибровка 0")));
    ui->tableWidget->setHorizontalHeaderItem(6, new QTableWidgetItem(tr("Значение  0")));
    ui->tableWidget->setHorizontalHeaderItem(7, new QTableWidgetItem(tr("Калибровка 1")));
    ui->tableWidget->setHorizontalHeaderItem(8, new QTableWidgetItem(tr("Значение  1")));
    ui->tableWidget->setHorizontalHeaderItem(9, new QTableWidgetItem(tr("Калибр.")));
    ui->tableWidget->setHorizontalHeaderItem(10, new QTableWidgetItem(tr("Установить")));

    ui->tableWidget->setHorizontalHeaderItem(11, new QTableWidgetItem(tr("Разрядность")));
  //  ui->tableWidget->setHorizontalHeaderItem(12, new QTableWidgetItem(tr("Отключить канал")));
   // timer->start(1000);

    ui->tableWidget->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);


     connect(p_uso,SIGNAL(DEV_INFO_RESPONSED()),this,SLOT(on_dev_info_responsed()));
     connect(p_uso,SIGNAL(GET_ALL_DATA_RESPONSED()),this,SLOT(on_dev_get_data_responsed()));

     connect(ui->action_LOAD,SIGNAL(triggered()),this,SLOT(on_menu_load_settings_clicked()));
     connect(ui->action_SAVE,SIGNAL(triggered()),this,SLOT(on_menu_save_settings_clicked()));

     connect(timer,SIGNAL(timeout()),this,SLOT(Get_All_Data()));


     connect_dlg=new connect_dialog();
     connect(connect_dlg,SIGNAL(connect_device(quint8)),this,SLOT(on_connect_device(quint8)));


     for(quint8 i=0;i<20;i++)
     {
          chnl[i]=new CHANNEL();
     }

     strlist<<tr("0-2.56 В")<<tr("0-1.28 В")<<tr("0-640 мВ")<<tr("0-320 мВ")<<tr("0-160 мВ")<<tr("0-80 мВ")<<tr("0-40 мВ")<<tr("0-20 мВ");
     bitlist<<tr("24")<<tr("16");

     read_flag=false;


     d_info=new dev_info(this);//диалог информации об устройстве
     connect(d_info,SIGNAL(get_dev_info()),this,SLOT(on_dialog_get_dev_info()));
     connect(d_info,SIGNAL(set_dev_info()),this,SLOT(on_dialog_set_dev_info()));

     CalibrList.clear();

     connect(p_uso,SIGNAL(GET_CALIBRATE_RESPONSED(quint8,quint8,float,float)),this,SLOT(on_get_calibrate_responsed(quint8,quint8,float,float)));

     UnactiveInterface();
}