Exemplo n.º 1
0
//--------------------------------------------------------------------------
// Send 1 bit of communication to the 1-Wire Net and verify that the
// bit read from the 1-Wire Net is the same (write operation).
// Delay delay msec and return to normal
//
static GOOD_OR_BAD DS1WM_PowerBit(const BYTE byte, BYTE * resp, const UINT delay, const struct parsedname *pn)
{
	GOOD_OR_BAD ret = gbBAD ; // default
	struct connection_in * in = pn->selected_connection ;
	uint8_t control_register ;
	
	// Set power, bitmode on
	control_register = DS1WM_control(in) ;
	UT_setbit( &control_register,e_ds1wm_stp_sply, 1 ) ;
	UT_setbit( &control_register,e_ds1wm_bit_ctl, 1 ) ;
	in->master.ds1wm.byte_mode = 0 ;
	DS1WM_control(in) = control_register ;

	if ( GOOD( DS1WM_sendback_byte( &byte, resp, in ) ) && GOOD( DS1WM_wait_for_write(in) ) ) {
		UT_delay(delay);
		ret = gbGOOD ;
	}

	// Set power, bitmode off
	control_register = DS1WM_control(in) ;
	UT_setbit( &control_register,e_ds1wm_stp_sply, 0 ) ;
	UT_setbit( &control_register,e_ds1wm_bit_ctl, 0 ) ;
	in->master.ds1wm.byte_mode = 1 ;
	DS1WM_control(in) = control_register ;

	return ret ;
}
Exemplo n.º 2
0
/* Open a DS9490  -- low level code (to allow for repeats)  */
static GOOD_OR_BAD DS9490_redetect_low(struct connection_in * in)
{
	// discover devices
	libusb_device **device_list;
	int n_devices = libusb_get_device_list( Globals.luc, &device_list) ;
	int i_device ;
	
	if ( n_devices < 1 ) {
		LEVEL_CONNECT("Could not find a list of USB devices");
		if ( n_devices<0 ) {
			LEVEL_DEBUG("<%s>",libusb_error_name(n_devices));
		}
		return gbBAD;
	}

	for ( i_device = 0 ; i_device < n_devices ; ++i_device ) {
		libusb_device * current = device_list[i_device] ;
		if ( GOOD( USB_match( current ) ) ) {
			// try to open the DS9490
			if ( BAD(DS9490_open_and_name( current, in )) ) {
				LEVEL_CONNECT("Cannot open USB bus master, Find next...");
				continue;
			}
			if ( GOOD( DS9490_redetect_match( in ) ) ) {
				break ;
			}
			DS9490_close(in);
		}
	}
	
	libusb_free_device_list(device_list, 1);
	return (in->master.usb.lusb_handle!=NULL) ? gbGOOD : gbBAD ;
}
Exemplo n.º 3
0
/* Create the Parsename structure and create the buffer */
struct one_wire_query * OWQ_create_from_path(const char *path)
{
	int sz = sizeof( struct one_wire_query ) + OWQ_DEFAULT_READ_BUFFER_SIZE;
	struct one_wire_query * owq = owmalloc( sz );
	
	LEVEL_DEBUG("%s", path);

	if ( owq== NO_ONE_WIRE_QUERY) {
		LEVEL_DEBUG("No memory to create object for path %s",path) ;
		return NO_ONE_WIRE_QUERY ;
	}
	
	memset(owq, 0, sz);
	OWQ_cleanup(owq) = owq_cleanup_owq ;
	
	if ( GOOD( OWQ_parsename(path,owq) ) ) {
		if ( GOOD( OWQ_allocate_array(owq)) ) {
			/*   Add a 1 byte buffer by default. This distinguishes from filesystem calls at end of buffer */
			/*   Read bufer is provided by OWQ_assign_read_buffer or OWQ_allocate_read_buffer */
			OWQ_buffer(owq) = (char *) (& owq[1]) ; // point just beyond the one_wire_query struct
			OWQ_size(owq) = OWQ_DEFAULT_READ_BUFFER_SIZE ;
			return owq ;
		}
		OWQ_destroy(owq);
	}
	return NO_ONE_WIRE_QUERY ;
}
Exemplo n.º 4
0
/* Create the Parsename structure and load the relevant fields */
GOOD_OR_BAD OWQ_create(const char *path, struct one_wire_query *owq)
{
	LEVEL_DEBUG("%s", path);

	if ( GOOD( OWQ_parsename(path,owq) ) ) {
		if ( GOOD( OWQ_allocate_array(owq)) ) {
			return gbGOOD ;
		}
		OWQ_destroy(owq);
	}
	return gbBAD ;
}
Exemplo n.º 5
0
/* Starts with a statically allocated owq space */
GOOD_OR_BAD OWQ_create_plus(const char *path, const char *file, struct one_wire_query *owq)
{
	LEVEL_DEBUG("%s + %s", path, file);

	OWQ_cleanup(owq) = owq_cleanup_none ;
	if ( GOOD( OWQ_parsename_plus(path,file,owq) ) ) {
		if ( GOOD( OWQ_allocate_array(owq)) ) {
			return gbGOOD ;
		}
		OWQ_destroy(owq);
	}
	return gbBAD ;
}
Exemplo n.º 6
0
HRESULT CPkcs7::HashAndSetImageFile(DWORD dwDigestLevel, HANDLE hFile,
										LPCOLESTR wszFile, HCRYPTPROV hprov, ALG_ID algidHash)
// Set the content to be, indirectly, the indicated raw file, using the indicated 
// hash algorithm.
//
	{
	PKCS7_IMAGEFILEDATA fd;
	m_pworld->Init(fd);
	fd.dwDigestLevel		= dwDigestLevel;
	fd.file.link.tag		= CERT_LINK_TYPE_FILE;
	fd.file.link.wszFile	= (LPWSTR)wszFile;
	HRESULT hr = S_OK;

	if (hFile != INVALID_HANDLE_VALUE)
		hr = HashImageFile(dwDigestLevel, hFile, hprov, algidHash, fd.file.digest);
	else
		hr = HashImageFile(dwDigestLevel, wszFile, hprov, algidHash, fd.file.digest);
	if (hr == S_OK)
		hr = put_ContentImageFile(&fd);

	#ifdef _DEBUG
	if (hr == S_OK)
		{
		GOOD(VerifyImageFile(dwDigestLevel, hFile, wszFile, hprov, algidHash));
		}
	#endif

	return hr;
	}
Exemplo n.º 7
0
/* Wrapper to perform a cache function and add statistics */
static GOOD_OR_BAD Add_Stat(struct cache_stats *scache, GOOD_OR_BAD result)
{
	if ( GOOD(result) ) {
		STAT_ADD1(scache->adds);
	}
	return result;
}
Exemplo n.º 8
0
enum Netlink_Read_Status W1_Process_Response( void (* nrs_callback)( struct netlink_parse * nlp, void * v, const struct parsedname * pn), SEQ_OR_ERROR seq, void * v, const struct parsedname * pn )
{
	struct connection_in * in = pn->selected_connection ;
	FILE_DESCRIPTOR_OR_ERROR file_descriptor ;
	int bus ;

	if ( seq == SEQ_BAD ) {
		return nrs_bad_send ;
	}

	if ( in == NO_CONNECTION ) {
		// Send to main netlink rather than a particular bus
		file_descriptor = FILE_DESCRIPTOR_BAD ;
		bus = 0 ;
	} else {
		// Bus-specifc
		file_descriptor = in->master.w1.netlink_pipe[fd_pipe_read] ;
		bus = in->master.w1.id ;
	}

	while ( GOOD( W1PipeSelect_timeout(file_descriptor)) ) {
		struct netlink_parse nlp ;
		nlp.nlm = NULL ;
		
		LEVEL_DEBUG("Loop waiting for netlink piped message");
		if ( BAD( Get_and_Parse_Pipe( file_descriptor, &nlp )) ) {
			LEVEL_DEBUG("Error reading pipe for w1_bus_master%d",bus);
			// Don't need to free since nlm not set if BAD
			return nrs_error ;
		}
		if ( NL_SEQ(nlp.nlm->nlmsg_seq) != (unsigned int) seq ) {
			LEVEL_DEBUG("Netlink sequence number out of order");
			owfree(nlp.nlm) ;
			continue ;
		}
		if ( nlp.w1m->status != 0) {
			owfree(nlp.nlm) ;
			return nrs_nodev ;
		}
		if ( nrs_callback == NULL ) { // status message
			owfree(nlp.nlm) ;
			return nrs_complete ;
		}

		LEVEL_DEBUG("About to call nrs_callback");
		nrs_callback( &nlp, v, pn ) ;
		LEVEL_DEBUG("Called nrs_callback");
		owfree(nlp.nlm) ;
		if ( nlp.cn->ack != 0 ) {
			if ( nlp.w1m->type == W1_LIST_MASTERS ) {
				continue ; // look for more data
			}
			if ( nlp.w1c && (nlp.w1c->cmd==W1_CMD_SEARCH || nlp.w1c->cmd==W1_CMD_ALARM_SEARCH) ) {
				continue ; // look for more data
			}
		}
		nrs_callback = NULL ; // now look for status message
	}
	return nrs_timeout ;
}
Exemplo n.º 9
0
/* send A/D conversion command */
static GOOD_OR_BAD OW_convert( int simul_good, int delay, struct parsedname *pn)
{
	BYTE convert[] = { _1W_CONVERT, 0x0F, 0x00, 0xFF, 0xFF, };
	struct transaction_log tpower[] = {
		TRXN_START,
		TRXN_WR_CRC16(convert, 3, 0),
		TRXN_END,
	};
	struct transaction_log tdead[] = {
		TRXN_START,
		TRXN_WRITE3(convert),
		TRXN_READ1(&convert[3]),
		TRXN_POWER( &convert[4], delay ) ,
		TRXN_CRC16(convert, 5),
		TRXN_END,
	};

	/* See if a conversion was globally triggered */
	if ( GOOD(OW_get_power(pn) ) ) {
		if ( simul_good ) { 
			return FS_Test_Simultaneous( simul_volt, delay, pn) ;
		} 
		// Start conversion
		// 6 msec for 16bytex4channel (5.2)
		RETURN_BAD_IF_BAD(BUS_transaction(tpower, pn));
		UT_delay(delay);			/* don't need to hold line for conversion! */
	} else {
		// Start conversion
		// 6 msec for 16bytex4channel (5.2)
		RETURN_BAD_IF_BAD(BUS_transaction(tdead, pn)) ;
	}
	return gbGOOD;
}
Exemplo n.º 10
0
/* See if a cached location is accurate -- called with "Known Bus" set */
INDEX_OR_ERROR ReCheckPresence(struct parsedname *pn)
{
	INDEX_OR_ERROR bus_nr;
	
	if (NotRealDir(pn)) {
		return INDEX_DEFAULT;
	}
	
	if ((pn->selected_device == DeviceSimultaneous)
		|| (pn->selected_device == DeviceThermostat)) {
		return INDEX_DEFAULT;
	}
	
	if (KnownBus(pn)) {
		if ( INDEX_VALID( CheckThisConnection(pn->known_bus->index,pn) ) ) {
			return pn->known_bus->index ;
		}
	}
	
	if ( GOOD( Cache_Get_Device(&bus_nr, pn)) ) {
		LEVEL_DEBUG("Found device on bus %d",bus_nr);
		if ( INDEX_VALID( CheckThisConnection(bus_nr,pn) ) ) {
			SetKnownBus(bus_nr, pn);
			return bus_nr ;
		}
	}
	
	UnsetKnownBus(pn);
	Cache_Del_Device(pn) ;
	return CheckPresence(pn);
}
Exemplo n.º 11
0
static void ENET_scan_for_adapters(void)
{
	struct enet_list elist ;
	struct enet_member * em ;

	MONITOR_RLOCK ;
	
	LEVEL_DEBUG("ENET SCAN!");

	enet_list_init( &elist ) ;
	Find_ENET_all( &elist ) ;

	em = elist.head ;
	if ( em == NULL ) {
	} else {
		while ( em != NULL ) {
			struct port_in * pnew = AllocPort( NULL ) ;
			if ( pnew == NULL ) {
				break ;
			}
			if ( GOOD(OWServer_Enet_setup( em->name, em->version, pnew )) ) {
				// Add the device, but no need to check for bad match
				Add_InFlight( NULL, pnew ) ;
			}
			em = em->next ;
		}
	}

	enet_list_kill( &elist ) ;

	MONITOR_RUNLOCK ;
}
Exemplo n.º 12
0
// Switch to overdrive speed -- 3 tries
static GOOD_OR_BAD DS9490_overdrive(const struct parsedname *pn)
{
	BYTE sp = _1W_OVERDRIVE_SKIP_ROM;
	BYTE resp;
	int i;

	// we need to change speed to overdrive
	for (i = 0; i < 3; i++) {
		LEVEL_DATA("set overdrive speed. Attempt %d",i);
		if ( BAD( gbRESET(BUS_reset(pn)) ) ) {
			continue;
		}
		if ( BAD( DS9490_sendback_data(&sp, &resp, 1, pn) ) || (_1W_OVERDRIVE_SKIP_ROM != resp) ) {
			LEVEL_DEBUG("error setting overdrive %.2X/0x%02X", _1W_OVERDRIVE_SKIP_ROM, resp);
			continue;
		}
		if ( GOOD( USB_Control_Msg(MODE_CMD, MOD_1WIRE_SPEED, ONEWIREBUSSPEED_OVERDRIVE, pn)) ) {
			LEVEL_DEBUG("speed is now set to overdrive");
			return gbGOOD;
		}
	}

	LEVEL_DEBUG("Error setting overdrive after 3 retries");
	return gbBAD;
}
Exemplo n.º 13
0
/* All general stored data will be assigned to this "head" channel */
static GOOD_OR_BAD HeadChannel(struct connection_in *head)
{
    /* Intentionally put the wrong index */
    head->master.i2c.index = 1;

    if ( BAD(DS2482_channel_select(head)) ) {	/* Couldn't switch */
        head->master.i2c.index = 0;	/* restore correct value */
        LEVEL_CONNECT("DS2482-100 (Single channel)");
        if ( GOOD(DS2483_test(head->pown->file_descriptor)) ) {
            head->master.i2c.type = ds2483 ;
        } else {
            head->master.i2c.type = ds2482_100 ;
        }

        return gbGOOD;				/* happy as DS2482-100 */
    }

    // It's a DS2482-800 (8 channels) to set up other 7 with this one as "head"
    LEVEL_CONNECT("DS2482-800 (Eight channels)");
    /* Must be a DS2482-800 */
    head->master.i2c.channels = 8;
    head->master.i2c.type = ds2482_800 ;
    head->Adapter = adapter_DS2482_800;

    return CreateChannels(head);
}
Exemplo n.º 14
0
HRESULT CPkcs7::put_ContentInfo(PKCS7_CONTENTINFO* pinfo)
// Set the content info from its DER encoding. Note that the data
// itself may in fact be omitted.
	{
	HRESULT hr = S_OK;
	ASSERT(m_pSignedData);
	ContentInfo& info = m_pSignedData->contentInfo;
	m_pworld->Free(info);
	m_pworld->Assign(info.contentType, pinfo->pidContentType);
	if (pinfo->data.pBlobData)
		{
		info.bit_mask |= content_present;
		if (m_pworld->Copy(info.content, pinfo->data.cbSize, pinfo->data.pBlobData))
			;
		else
			hr = E_OUTOFMEMORY;
		}

	#ifdef _DEBUG
	if (hr == S_OK)
		{
		PKCS7_CONTENTINFO newInfo;
		GOOD(get_ContentInfo(&newInfo));
		ObjectID id1, id2;
		m_pworld->Assign(id1, pinfo->pidContentType);
		m_pworld->Assign(id2, newInfo.pidContentType);
		ASSERT(id1 == id2);
		ASSERT(IsEqual(pinfo->data, newInfo.data));
		FreeTaskMem(newInfo);
		}
	#endif

	return hr;
	}
Exemplo n.º 15
0
HRESULT CPkcs7::HashAndSetJavaClassFile(HANDLE hFile, LPCWSTR wszFile, HCRYPTPROV hprov, ALG_ID algidHash)
	{
	PKCS7_FILEDATA rf;
	m_pworld->Init(rf);
	if (wszFile)
		{
		rf.link.tag		= CERT_LINK_TYPE_FILE;
		rf.link.wszFile	= (LPWSTR)wszFile;
		}
	else
		rf.link.tag		= CERT_LINK_TYPE_NONE;

	HRESULT hr = HashJavaClassFile(hFile, wszFile, hprov, algidHash, rf.digest);

	if (hr == S_OK)
		{
		hr = put_ContentJavaClassFile(&rf);
		}

	#ifdef _DEBUG
	if (hr == S_OK)
		{
		GOOD(VerifyJavaClassFile(hFile, wszFile, hprov, algidHash));
		}
	#endif

	return hr;
	}
Exemplo n.º 16
0
/* When the errors stop the USB device from functioning -- close and reopen.
 * If it fails, re-scan the USB bus and search for the old adapter */
static GOOD_OR_BAD DS9490_reconnect(const struct parsedname *pn)
{
	GOOD_OR_BAD ret;
	struct connection_in * in = pn->selected_connection ;

	if ( in->master.usb.specific_usb_address ) { 
		// special case where a usb bus:dev pair was given
		// only connect to the same spot
		return DS9490_redetect_specific_adapter( in ) ; 
	}

	/* Have to protect usb_find_busses() and usb_find_devices() with
	 * a lock since libusb could crash if 2 threads call it at the same time.
	 * It's not called until DS9490_redetect_low(), but I lock here just
	 * to be sure DS9490_close() and DS9490_open() get one try first. */
	LIBUSBLOCK;
	DS9490_close( in ) ;
	ret = DS9490_redetect_low(in) ;
	LIBUSBUNLOCK;

	if ( GOOD(ret) ) {
		LEVEL_DEFAULT("Found USB DS9490 bus master after USB rescan as [%s]", SAFESTRING(DEVICENAME(in)));
	}
	return ret;
}
Exemplo n.º 17
0
static GOOD_OR_BAD Bundle_pack(const struct transaction_log *tl, const struct parsedname *pn)
{
	const struct transaction_log *t_index;
	struct transaction_bundle s_tb;
	struct transaction_bundle *tb = &s_tb;

	Bundle_init(tb, pn);

	for (t_index = tl; t_index->type != trxn_end; ++t_index) {
		switch (Pack_item(t_index, tb)) {
		case gbGOOD:
			LEVEL_DEBUG("Item added");
			break;
		case gbBAD:
			LEVEL_DEBUG("Item cannot be bundled");
			RETURN_BAD_IF_BAD(Bundle_ship(tb, pn)) ;
			RETURN_BAD_IF_BAD(BUS_transaction_single(t_index, pn)) ;
			break;
		case gbOTHER:
			LEVEL_DEBUG("Item too big");
			RETURN_BAD_IF_BAD(Bundle_ship(tb, pn)) ;
			if ( GOOD( Pack_item(t_index, tb) ) ) {
				break;
			}
			RETURN_BAD_IF_BAD(BUS_transaction_single(t_index, pn)) ;
			break;
		}
	}
	return Bundle_ship(tb, pn);
}
Exemplo n.º 18
0
// Look on a given connection for the device
static INDEX_OR_ERROR CheckThisConnection(int bus_nr, struct parsedname *pn)
{
	struct parsedname s_pn_copy;
	struct parsedname * pn_copy = &s_pn_copy ;
	struct connection_in * in = find_connection_in(bus_nr) ;
	INDEX_OR_ERROR connection_result = INDEX_BAD ;

	if ( in == NO_CONNECTION ) {
		return INDEX_BAD ;
	}
	
	memcpy(pn_copy, pn, sizeof(struct parsedname));	// shallow copy
	pn_copy->selected_connection = in;
	
	if ( BAD( TestConnection(pn_copy) ) ) {
		// Connection currently disconnected
		return INDEX_BAD;
	} else if (BusIsServer(in)) {
		// Server
		if ( INDEX_VALID( ServerPresence(pn_copy) ) ) {
			connection_result =  in->index;
		}
	} else if ( in->iroutines.flags & ADAP_FLAG_sham ) {
		return INDEX_BAD ;
	} else if ( in->iroutines.flags & ADAP_FLAG_presence_from_dirblob ) {
		// local connection with a dirblob (like fake, mock, ...)
		if ( GOOD( PresenceFromDirblob( pn_copy ) ) ) {
			connection_result =  in->index ;
		}
	} else {
		// local connection but need to ask directly
		struct transaction_log t[] = {
			TRXN_NVERIFY,
			TRXN_END,
		};
		if ( GOOD( BUS_transaction(t, pn_copy) ) ) {
			connection_result =  in->index ;
		}
	}
	if ( connection_result == INDEX_BAD ) {
		LEVEL_DEBUG("Presence of "SNformat" NOT found on bus %s",SNvar(pn_copy->sn),SAFESTRING(DEVICENAME(in))) ;
	} else {
		LEVEL_DEBUG("Presence of "SNformat" FOUND on bus %s",SNvar(pn_copy->sn),SAFESTRING(DEVICENAME(in))) ;
		Cache_Add_Device(in->index,pn_copy->sn) ; // add or update cache */
	}
	return connection_result ;
}
Exemplo n.º 19
0
HRESULT CPkcs7::remove_Certificate(LONG iCert)
// Remove the indicated certificate info from the list
	{
	if (m_cCertActive)
		{
		return E_FAIL;
		}
	ASSERT(m_pSignedData); if (!m_pSignedData) return E_POINTER;
	#ifdef _DEBUG
	 	LONG cStart;
		GOOD(get_CertificateCount(&cStart));
	#endif
	LONG cCert;
	ExtendedCertificatesAndCertificates plink;
	cCert = 0;
	for (plink        = (ExtendedCertificatesAndCertificates)(&m_pSignedData->certificates); 
		 plink->next != NULL; 
		 plink        = plink->next)
		{
		ExtendedCertificatesAndCertificates plinkNext = plink->next;
		if (plinkNext->value.choice == certificate_chosen)
			{
			if (cCert == iCert || (iCert == -1 && plinkNext->next == NULL))
				{
				plink->next = plinkNext->next;
				plinkNext->next = NULL;
				m_pworld->Free(plinkNext);
				#ifdef _DEBUG
					{
					LONG cEnd;
					GOOD(get_CertificateCount(&cEnd));
					VERIFY(cStart == cEnd + 1);
					}
				#endif
				return S_OK;
				}
			cCert++;
			}
		}
	return E_INVALIDARG;
	}
Exemplo n.º 20
0
MRI_IMAGE * mri_extract_from_mask( MRI_IMAGE *imin , byte *mask , int invert )
{
   byte bmmm = (invert == 0) ? 1 : 0 ;
   int ii,jj , ngood , nvox ;
   float *iar , *oar ;
   MRI_IMAGE *outim ;

ENTRY("mri_extract_mask") ;

   if( imin == NULL || mask == NULL ) RETURN(NULL) ;  /* bad user == luser */

   /*-- not float?  create a float image and recurse! --*/

   if( imin->kind != MRI_float ){
     MRI_IMAGE *qim = mri_to_float(imin) ;
     outim = mri_extract_from_mask( qim , mask , invert ) ;
     mri_free(qim) ;
     RETURN(outim) ;
   }

   /*-- count up the good voxels --*/

   nvox = imin->nvox ;
   for( ngood=ii=0 ; ii < nvox ; ii++ ) if( GOOD(ii) ) ngood++ ;
   if( ngood == 0 ) RETURN(NULL) ;

   /*-- create the output --*/

   outim = mri_new( ngood , 1 , MRI_float ) ;
   oar   = MRI_FLOAT_PTR(outim) ;
   iar   = MRI_FLOAT_PTR(imin) ;

   /*-- fill the output --*/

   for( jj=ii=0 ; ii < nvox ; ii++ ) if( GOOD(ii) ) oar[jj++] = iar[ii] ;

   RETURN(outim) ;
}
Exemplo n.º 21
0
HRESULT CPkcs7::remove_SignerInfo(LONG iInfo)
// Remove the indicated signer info from the list
	{
	if (m_cSignerInfoActive)
		{
		return E_FAIL;
		}
	ASSERT(m_pSignedData); if (!m_pSignedData) return E_POINTER;
	#ifdef _DEBUG
		LONG cStart;
		GOOD(get_SignerInfoCount(&cStart));
	#endif
	LONG count;
	SignerInfos infos;
	count = 0;
	for (infos        = (SignerInfos)(&m_pSignedData->signerInfos); 
		 infos->next != NULL; 
		 infos        = infos->next)
		{
		SignerInfos infosNext = infos->next;
		if (count == iInfo || (iInfo == -1 && infosNext->next == NULL))
			{
			infos->next = infosNext->next;
			infosNext->next = NULL;
			m_pworld->Free(infosNext);
			#ifdef _DEBUG
				{
				LONG cEnd;
				GOOD(get_SignerInfoCount(&cEnd));
				VERIFY(cStart == cEnd + 1);
				}
			#endif
			return S_OK;
			}
		count++;
		}
	return E_INVALIDARG;
	}
Exemplo n.º 22
0
/* Open a DS9490  -- low level code (to allow for repeats)  */
static GOOD_OR_BAD DS9490_detect_all_adapters(struct port_in * pin_first)
{
	// discover devices
	struct port_in * pin = pin_first ;
	libusb_device **device_list;
	int n_devices = libusb_get_device_list( Globals.luc, &device_list) ;
	int i_device ;
	
	if ( n_devices < 1 ) {
		LEVEL_CONNECT("Could not find a list of USB devices");
		if ( n_devices<0 ) {
			LEVEL_DEBUG("<%s>",libusb_error_name(n_devices));
		}
		return gbBAD ;
	}

	for ( i_device = 0 ; i_device < n_devices ; ++i_device ) {
		libusb_device * current = device_list[i_device] ;
		if ( GOOD( USB_match( current ) ) ) {
			struct connection_in * in = pin->first ;
			if ( BAD(DS9490_open_and_name( current, in)) ) {
				LEVEL_DEBUG("Cannot open USB device %.d:%.d", libusb_get_device_address(current), libusb_get_bus_number(current) );
				continue ;
			} else if ( BAD(DS9490_ID_this_master(in)) ) {
				DS9490_close(in) ;
				LEVEL_DEBUG("Cannot access USB device %.d:%.d", libusb_get_device_address(current), libusb_get_bus_number(current) );
				continue;
			} else{
				pin = NewPort(NULL) ; // no reason to copy anything
				if ( pin == NULL ) {
					return gbGOOD ;
				}
				// set up the new connection for the next adapter
				DS9490_setroutines(in);
			}
		}
	}
	
	libusb_free_device_list(device_list, 1);

	if ( pin == pin_first ) {
		LEVEL_CONNECT("No USB DS9490 bus masters used");
		return gbBAD;
	}
	// Remove the extra connection
	RemovePort(pin);
	return gbGOOD ;
}
Exemplo n.º 23
0
SIZE_OR_ERROR FS_get(const char *path, char **return_buffer, size_t * buffer_length)
{
	SIZE_OR_ERROR size = 0 ;		/* current buffer string length */
	OWQ_allocate_struct_and_pointer( owq ) ;

	/* Check the parameters */
	if (return_buffer == NULL) {
		//  No buffer for read result.
		return -EINVAL;
	}

	if (path == NULL) {
		path = "/";
	}

	*return_buffer = NULL;				// default return string on error

	if ( BAD( OWQ_create(path, owq) ) ) {	/* Can we parse the input string */
		return -ENOENT;
	}

	if ( IsDir( PN(owq) ) ) { /* A directory of some kind */
		struct charblob cb ;
		CharblobInit(&cb) ;
		getdir( &cb, owq ) ;
		size = CharblobLength(&cb) ;
		*return_buffer = copy_buffer( CharblobData(&cb), size ) ;
		CharblobClear( &cb ) ;
	} else { /* A regular file  -- so read */
		if ( GOOD(OWQ_allocate_read_buffer(owq)) ) { // make the space in the buffer
			size = FS_read_postparse(owq) ;
			*return_buffer = copy_buffer( OWQ_buffer(owq), size ) ;
		}
	}
	// the buffer is allocated by getdir or getval
	OWQ_destroy(owq);

	/* Check the parameters */
	if (*return_buffer == NULL) {
		//  no data.
		return -EINVAL;
	}

	if ( buffer_length != NULL ) {
		*buffer_length = size ;
	}
	return size ;
}
Exemplo n.º 24
0
/* Open a DS9490  -- low level code (to allow for repeats)  */
static GOOD_OR_BAD DS9490_detect_specific_adapter(int bus_nr, int dev_nr, struct connection_in * in)
{
	// discover devices
	libusb_device **device_list;
	int n_devices = libusb_get_device_list( Globals.luc, &device_list) ;
	int i_device ;
	
	if ( n_devices < 1 ) {
		LEVEL_CONNECT("Could not find a list of USB devices");
		if ( n_devices<0 ) {
			LEVEL_DEBUG("<%s>",libusb_error_name(n_devices));
		}
		return gbBAD ;
	}

	// Mark this connection as taking only this address pair. Important for reconnections.
	in->master.usb.specific_usb_address = 1 ;

	for ( i_device = 0 ; i_device < n_devices ; ++i_device ) {
		libusb_device * current = device_list[i_device] ;
		if ( GOOD( USB_match( current ) ) ) {
			if ( libusb_get_bus_number(current) != bus_nr ) {
				continue ;
			}
			
			if ( libusb_get_device_address(current) != dev_nr ) {
				continue ;
			}
			
			if ( BAD(DS9490_open_and_name( current, in)) ) {
				LEVEL_DEBUG("Cannot open USB device %.d:%.d", libusb_get_device_address(current), libusb_get_bus_number(current) );
				break ;
			} else if ( BAD(DS9490_ID_this_master(in)) ) {
				DS9490_close(in) ;
				LEVEL_DEBUG("Cannot access USB device %.d:%.d", libusb_get_device_address(current), libusb_get_bus_number(current) );
				break ;
			} else{
				libusb_free_device_list(device_list, 1);
				return gbGOOD ;
			}
		}
	}
	
	libusb_free_device_list(device_list, 1);

	LEVEL_CONNECT("No USB DS9490 bus master found matching %d:%d", bus_nr,dev_nr);
	return gbBAD;
}
Exemplo n.º 25
0
static GOOD_OR_BAD DS9490_ProgramPulse(const struct parsedname *pn)
{
	GOOD_OR_BAD ret;

	// set pullup to strong5 or program
	// set the strong pullup duration to infinite
	ret = USB_Control_Msg(COMM_CMD, COMM_PULSE | COMM_TYPE | COMM_IM, 0, pn);
	if ( GOOD(ret) ) {
		UT_delay_us(520);		// 520 usec (480 usec would be enough)
	}

	if ( BAD(DS9490_HaltPulse(pn)) ) {
		LEVEL_DEBUG("Couldn't reset the program pulse level back to normal");
		return gbBAD;
	}
	return ret ;
}
Exemplo n.º 26
0
HRESULT CPkcs7::put_IndirectDataContent(ObjectID& idToUse, BLOB& blob, DIGESTINFO& digest)
// Inverse to succeeding function
	{
	HRESULT hr = S_OK;
	IndirectDataContent* pindirect = (IndirectDataContent*)m_pworld->Alloc(sizeof(IndirectDataContent));
	if (pindirect)
		{
		m_pworld->Init(*pindirect);
		hr = m_pworld->Assign(pindirect->messageDigest, digest);
		if (hr == S_OK)
			{
			pindirect->data.type = idToUse;
			pindirect->data.value.length   = blob.cbSize;
			pindirect->data.value.encoded  = blob.pBlobData;
			pindirect->data.bit_mask	   = blob.pBlobData ? value_present : 0;
			BLOB b;
			if (0 == m_pworld->Encode(IndirectDataContent_PDU, pindirect, &b))
				{
				PKCS7_CONTENTINFO content;
				content.pidContentType = (OSIOBJECTID*)&id_indirectdata;
				content.data = b;
				hr = put_ContentInfo(&content);
				m_pworld->Free(b);
				}
			else
				hr = DIGSIG_E_ENCODE;
			m_pworld->Init(pindirect->data.value);	// so we don't free it below
			}
		m_pworld->Free(pindirect);
		}

	#ifdef _DEBUG
	if (hr == S_OK)
		{
		BLOB b;
		DIGESTINFO d;
		GOOD(get_IndirectDataContent(idToUse, !!blob.pBlobData, b, d));
		ASSERT(IsEqual(b, blob));
		ASSERT(memcmp(&d, &digest, sizeof(d)) == 0);
		FreeTaskMem(b);
		}
	#endif

	return hr;
	}
Exemplo n.º 27
0
ZERO_OR_ERROR FS_present(struct one_wire_query *owq)
{
	struct parsedname *pn = PN(owq);

	if (NotRealDir(pn) || pn->selected_device == DeviceSimultaneous || pn->selected_device == DeviceThermostat) {
		OWQ_Y(owq) = 1;
	} else if ( pn->selected_connection->iroutines.flags & ADAP_FLAG_presence_from_dirblob ) {
		OWQ_Y(owq) = GOOD( PresenceFromDirblob(pn) ) ;
	} else if ( pn->selected_connection->iroutines.flags & ADAP_FLAG_sham ) {
		OWQ_Y(owq) = 0 ;
	} else {
		struct transaction_log t[] = {
			TRXN_NVERIFY,
			TRXN_END,
		};
		OWQ_Y(owq) = BAD(BUS_transaction(t, pn)) ? 0 : 1;
	}
	return 0;
}
Exemplo n.º 28
0
/* Open a DS9490  -- low level code (to allow for repeats)  */
static GOOD_OR_BAD DS9490_detect_single_adapter(int usb_nr, struct connection_in * in)
{
	// discover devices
	libusb_device **device_list;
	int n_devices = libusb_get_device_list( Globals.luc, &device_list) ;
	int i_device ;
	
	if ( n_devices < 1 ) {
		LEVEL_CONNECT("Could not find a list of USB devices");
		if ( n_devices<0 ) {
			LEVEL_DEBUG("<%s>",libusb_error_name(n_devices));
		}
		return gbBAD ;
	}

	for ( i_device = 0 ; i_device < n_devices ; ++i_device ) {
		libusb_device * current = device_list[i_device] ;
		if ( GOOD( USB_match( current ) ) ) {
			--usb_nr ;
			if ( usb_nr > 0 ) {
				continue ;
			}
			
			if ( BAD(DS9490_open_and_name( current, in)) ) {
				LEVEL_DEBUG("Cannot open USB device %.d:%.d", libusb_get_device_address(current), libusb_get_bus_number(current) );
				break ;
			} else if ( BAD(DS9490_ID_this_master(in)) ) {
				DS9490_close(in) ;
				LEVEL_DEBUG("Cannot access USB device %.d:%.d", libusb_get_device_address(current), libusb_get_bus_number(current) );
				break ;
			} else{
				libusb_free_device_list(device_list, 1);
				return gbGOOD ;
			}
		}
	}
	
	libusb_free_device_list(device_list, 1);

	LEVEL_CONNECT("No USB DS9490 bus master found");
	return gbBAD;
}
Exemplo n.º 29
0
/* A few sequences start with teh bus already locked */
GOOD_OR_BAD BUS_transaction_nolock(const struct transaction_log *tl, const struct parsedname *pn)
{
	const struct transaction_log *t = tl;
	GOOD_OR_BAD ret = gbGOOD;

	if (pn->selected_connection->iroutines.flags & ADAP_FLAG_bundle) {
		return Bundle_pack(tl, pn);
	}

	do {
		//printf("Transact type=%d\n",t->type) ;
		ret = BUS_transaction_single(t, pn);
		if (ret == gbOTHER) {	// trxn_done flag
			ret = gbGOOD;			// restore no error code
			break;				// but stop looping anyways
		}
		++t;
	} while ( GOOD(ret) );
	return ret;
}
Exemplo n.º 30
0
/* Get a device that isn't a serial number -- see if it's an alias */
static enum parse_enum Parse_Alias(char *filename, enum parse_pass remote_status, struct parsedname *pn)
{
	INDEX_OR_ERROR bus ;
	
	// See if the alias is known in the permanent list. We get the serial number 
	if ( GOOD( Cache_Get_Alias_SN(filename,pn->sn)) ) {
		// Success! The alias is already registered and the serial
		//  number just now loaded in pn->sn
		return Parse_Alias_Known( filename, remote_status, pn ) ;
	}

	// By definition this is a remote device, or non-existent.
	pn->selected_device = &RemoteDevice ;

	// is alias name cached from previous query?
	bus = Cache_Get_Alias_Bus( filename ) ;
	if ( bus != INDEX_BAD ) {
		// This alias is cached in temporary list
		SetKnownBus(bus, pn);
		return parse_prop ;
	}

	// Look for alias in remote buses
	bus = RemoteAlias(pn) ;
	if ( bus == INDEX_BAD ) {
		return parse_error ;
	}
	
	// Found the alias (remotely)
	SetKnownBus(bus, pn);

	if ( pn->sn[0] == 0 && pn->sn[7]==0 ) { // no serial number owserver (older)
		Cache_Add_Alias_Bus(filename,bus) ;
	} else {
		Cache_Add_Alias( filename, pn->sn ) ;
		Cache_Add_Device( bus, pn->sn ) ;
		pn->selected_device = FS_devicefindhex(pn->sn[0], pn);
	}

	return parse_prop ;
}