コード例 #1
0
ファイル: testport.c プロジェクト: axelmuhr/Helios-NG
int main()
{
	Port a;
	MCB m;
	word timeout = OneSec*5;
	word start, end;
	word e;

	a = NewPort();

	forever
	{
		InitMCB(&m,MsgHdr_Flags_preserve,a,NullPort,1); /* IOCTimeout */
		m.Timeout = timeout;

		start = _cputime(); /* times in centiseconds */
		e = PutMsg(&m);
		end = _cputime();

		if ((end - start) > ((timeout/10000) + 500) || (end - start) < 0)
		{
			printf("PutMsg TIMEOUT ERROR returned %lx - ", e);
			IOdebug("PutMsg TIMEOUT ERROR 500 != %x centisecs\n",end-start);
		}
		printf("Timeout in %ld centisecs\n",end-start);
	}
}
コード例 #2
0
ファイル: ow_ds2482.c プロジェクト: GrandHsu/iicontrollibs
/* return GOOD if any found */
static GOOD_OR_BAD DS2482_detect_sys( int any, enum ds2482_address chip_num, struct port_in *pin_original)
{
    DIR * i2c_list_dir ;
    struct dirent * i2c_bus ;
    int found = 0 ;
    struct port_in * pin_current = pin_original ;

    // We'll look in this directory for available i2c adapters.
    // This may be linux 2.6 specific
    i2c_list_dir = opendir( SYSFS_I2C_Path ) ;
    if ( i2c_list_dir == NULL ) {
        ERROR_CONNECT( "Cannot open %d to find available i2c devices",SYSFS_I2C_Path ) ;
        // Use the cruder approach of trying all possible numbers
        return DS2482_detect_dir( any, chip_num, pin_original ) ;
    }

    /* cycle through entries in /sys/class/i2c-adapter */
    while ( (i2c_bus=readdir(i2c_list_dir)) != NULL ) {
        char dev_name[128] ; // room for /dev/name
        int sn_ret ;

        UCLIBCLOCK ;
        sn_ret = snprintf( dev_name, 128, "/dev/%s", i2c_bus->d_name ) ;
        UCLIBCUNLOCK ;
        if ( sn_ret < 0 ) {
            break ;
        }

        // Now look for the ds2482's
        if ( BAD( DS2482_detect_bus( chip_num, dev_name, pin_current ) ) ) {
            continue ; // none found on this i2c bus
        }

        // at least one found on this i2c bus
        ++found ;
        if ( any ) { // found one -- that's enough
            closedir( i2c_list_dir ) ;
            return gbGOOD ;
        }

        // ALL? then set up a new connection_in slot for the next one
        pin_current = NewPort(pin_current) ;
        if ( pin_current == NULL ) {
            break ;
        }
    }

    closedir( i2c_list_dir ) ;

    if ( found==0 ) {
        return gbBAD ;
    }

    if ( pin_current != pin_original ) {
        RemovePort( pin_current ) ;
    }
    return gbGOOD ;
}
コード例 #3
0
ファイル: ow_ds9490.c プロジェクト: M-o-a-T/owfs
/* 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 ;
}
コード例 #4
0
ファイル: ow_ds2482.c プロジェクト: GrandHsu/iicontrollibs
/* returns GOOD if any adpters found */
static GOOD_OR_BAD DS2482_detect_dir( int any, enum ds2482_address chip_num, struct port_in *pin_original)
{
    int found = 0 ;
    struct port_in * pin_current = pin_original ;
    int bus = 0 ;
    int sn_ret ;

    for ( bus=0 ; bus<99 ; ++bus ) {
        char dev_name[128] ;

        UCLIBCLOCK ;
        sn_ret = snprintf( dev_name, 128-1, "/dev/i2c-%d", bus ) ;
        UCLIBCUNLOCK ;
        if ( sn_ret < 0 ) {
            break ;
        }

        if ( access(dev_name, F_OK) < 0 ) {
            continue ;
        }

        // Now look for the ds2482's
        if ( BAD( DS2482_detect_bus( chip_num, dev_name, pin_current ) ) ) {
            continue ;
        }

        // at least one found
        ++found ;
        if ( any ) {
            return gbGOOD ;
        }

        // ALL? then set up a new connection_in slot
        pin_current = NewPort(pin_current) ;
        if ( pin_current == NULL ) {
            break ;
        }
    }

    if ( found == 0 ) {
        return gbBAD ;
    }

    if ( pin_original != pin_current ) {
        RemovePort(pin_current) ;
    }
    return gbGOOD ;
}
コード例 #5
0
ファイル: ow_multicast.c プロジェクト: GrandHsu/iicontrollibs
GOOD_OR_BAD FS_FindHA7(void)
{
	struct addrinfo *ai;
	struct addrinfo hint;
	struct addrinfo *now;
	int number_found = 0;
	int getaddr_error ;

	LEVEL_DEBUG("Attempting udp multicast search for the HA7Net bus master at %s:%s",HA7_DISCOVERY_ADDRESS,HA7_DISCOVERY_PORT);
	Setup_HA7_hint( &hint ) ;
	if ((getaddr_error = getaddrinfo(HA7_DISCOVERY_ADDRESS, HA7_DISCOVERY_PORT, &hint, &ai))) {
		LEVEL_CONNECT("Couldn't set up HA7 broadcast message %s", gai_strerror(getaddr_error));
		return gbBAD;
	}

	for (now = ai; now; now = now->ai_next) {
		ASCII name[INET_ADDRSTRLEN+20]; // tcp quad + port
		struct port_in * pin ;
		struct connection_in *in;

		if ( Get_HA7_response( now, name ) ) {
			continue ;
		}

		pin = NewPort(NO_CONNECTION) ;
		if (pin == NULL) {
			continue;
		}
		in = pin->first ;

		pin->type = ct_tcp ;
		pin->init_data = owstrdup(name);
		DEVICENAME(in) = owstrdup(name);
		pin->busmode = bus_ha7net;

		LEVEL_CONNECT("HA7Net bus master discovered at %s",DEVICENAME(in));
		++number_found ;
	}
	freeaddrinfo(ai);
	return number_found > 0 ? gbGOOD : gbBAD ;
}
コード例 #6
0
ファイル: ow_ds2482.c プロジェクト: GrandHsu/iicontrollibs
/* Includes  a fix from Pascal Baerten */
static GOOD_OR_BAD DS2482_detect_bus(enum ds2482_address chip_num, char * i2c_device, struct port_in * pin_original)
{
    switch (chip_num) {
    case ds2482_any:
        // usual case, find the first adapter
        return DS2482_detect_single( 0, 7, i2c_device, pin_original ) ;
    case ds2482_all:
        // Look through all the possible i2c addresses
    {
        int start_chip = 0 ;
        struct port_in * all_pin = pin_original ;
        do {
            if ( BAD( DS2482_detect_single( start_chip, 7, i2c_device, all_pin ) ) ) {
                if ( pin_original == all_pin ) { //first time
                    return gbBAD ;
                }
                LEVEL_DEBUG("Cleaning excess allocated i2c structure");
                RemovePort(all_pin); //Pascal Baerten :this removes the false DS2482-100 provisioned
                return gbGOOD ;
            }
            start_chip = all_pin->first->master.i2c.i2c_index + 1 ;
            if ( start_chip > 7 ) {
                return gbGOOD ;
            }
            all_pin = NewPort(all_pin) ;
            if ( all_pin == NULL ) {
                return gbBAD ;
            }
        } while (1) ;
    }
    break ;
    default:
        // specific i2c address
        return DS2482_detect_single( chip_num, chip_num, i2c_device, pin_original ) ;
    }
}
コード例 #7
0
ファイル: csync.c プロジェクト: jamjr/Helios-NG
PUBLIC INT Sync (IN STRING PathTo)

/******************************************************************************
**
**  PURPOSE:
**    Locates the file server with <PathTo> and sends a "private" message to the
**    server to signal a file system synchronisation request.
**
**  PARAMETERS:
**
**    In:
**      <PathTo>  Path to the file server
**
**  RETURN:
**    SyncOK      No error occured
**
**  EXAMPLE:
**
**    In:
**      <PathTo> = "/helios/bin/fs"
** 
**    Return:
**      SyncOK
**
*** endspec *******************************************************************/

{
  MCB   Mcb;
  word  E;
  Port  Reply;
  word  ControlV [IOCMsgMax];
  byte  DataV [IOCDataMax];
 
/******************************************************************************* 
**
**  -Get a port for the reply message
**  -Basic initialisation of the MessageControlBlock
**
*******************************************************************************/
 	
 Reply = NewPort ();			

 InitMCB (&Mcb, MsgHdr_Flags_preserve, MyTask->IOCPort, Reply, FC_GSP | SS_HardDisk | FG_Private | FO_ForceSync);

/******************************************************************************* 
**
**  -Preparing control and data vector
**
*******************************************************************************/

  Mcb.Control = ControlV;	
  Mcb.Data    = DataV; 	   
  MarshalCommon (&Mcb, Null (Object), PathTo);

/******************************************************************************* 
**
**  -Send the message to the server
**  -Expect the server's reply (infinite wait)
**  -Release the port
**  -Normal termination
**
*******************************************************************************/
					
 E = PutMsg (&Mcb);

 InitMCB (&Mcb, MsgHdr_Flags_preserve, Reply, NullPort, 0);
 Mcb.Timeout = MaxInt;
 GetMsg (&Mcb);

 FreePort (Reply);
 
 return (SyncOK);
}
コード例 #8
0
ファイル: ioc.c プロジェクト: jamjr/Helios-NG
PUBLIC Stream *
Open(
     Object *	object,
     string	name,
     word	mode )
{
	word rc = Err_Null;
	Stream *stream = NULL;
	MCB *mcb;
	IOCReply1 *rep;
	word stlen;
	Port reply;

#ifdef SYSDEB
	SysDebug(ioc)("Open(%O,%N,%x)",object,name,mode);
#endif

	if( CheckObject(object,C_Locate) != Err_Null ) return Null(Stream);

	reply = NewPort();

	mcb = NewMsgBuf(0);
	rep = (IOCReply1 *)mcb->Control;

	InitMCB(mcb,MsgHdr_Flags_preserve,
		MyTask->IOCPort,reply,FC_GSP|FG_Open|object->FnMod);

	MarshalCommon(mcb,object,name);

	MarshalWord(mcb,mode);

	if( (rc = IOCMsg(mcb,NULL)) < Err_Null ) goto Done;

	stlen = sizeof(Stream) + (word)strlen(mcb->Data+rep->Pathname) + SafetyMargin;

	stream = (Stream *)Malloc(stlen);

	if( stream == NULL ) 
	{
		rc = EC_Error|SS_SysLib|EG_NoMemory|EO_Stream;
		goto Done;
	}
	else memclr( (void *)stream, (int)stlen );

	if( SetupStream( stream, mcb ) )
	{
		stream->Flags |= mode&Flags_SaveMode;
		InitSemaphore( &stream->Mutex, 1 );
		stream->Pos = 0;
	}

	AddStream( stream );	

	rc = Err_Null;
	
	if( mode & Flags_Append ) Seek(stream, S_End, 0);
    Done:
#ifdef SYSDEB
	SysDebug(ioc)("Open: %E stream: %S",rc,stream);
#endif
	FreeMsgBuf(mcb);

	if( rc < Err_Null ) FreePort(reply);

	object->Result2 = rc;
	return stream;
}
コード例 #9
0
ファイル: ioc.c プロジェクト: jamjr/Helios-NG
PUBLIC Object *
Create(
       Object *	object,
       string	name,
       word	type,
       word	size,
       byte *	data )
{
	word rc = Err_Null;
	Object *obj = Null(Object);
	MCB *mcb;
	IOCReply1 *rep;
	word oblen;
	Port reply;

#ifdef SYSDEB
	SysDebug(ioc)("Create(%O,%N,%T,%d,%P)",object,name,type,size,data);
#endif

	if ( CheckObject(object,C_Locate) != Err_Null )
	  {
	    return NULL;
	  }

	reply = NewPort();

	mcb = NewMsgBuf(0);
	rep = (IOCReply1 *)mcb->Control;
	
	InitMCB(mcb,MsgHdr_Flags_preserve,
		MyTask->IOCPort,reply,FC_GSP|FG_Create|object->FnMod);

	MarshalCommon(mcb,object,name);

	MarshalWord(mcb,type);
	MarshalWord(mcb,size);
	MarshalOffset(mcb);
	MarshalData(mcb,size,data);

	mcb->Timeout = object->Timeout;
	
	/* IOdebug( "Create: sending message" ); */
	
	if ( (rc = IOCMsg(mcb, NULL)) < Err_Null )
	  {
	    /* IOdebug( "Create: message send failed" ); */
	    
	    goto Done;
	  }
	
	/* IOdebug( "Create: message sent" ); */
	
	oblen = sizeof(Object) + (word)strlen(mcb->Data+rep->Pathname) + SafetyMargin;

	obj = (Object *)Malloc(oblen);
	
	if ( obj == NULL )
	  {
	    rc = EC_Error|SS_SysLib|EG_NoMemory|EO_Object;
		
	    goto Done;
	  }	
	else memclr( (void *)obj, (int)oblen );

	obj->Type    = rep->Type;
	obj->Flags   = rep->Flags;
	obj->Access  = rep->Access;
	obj->Reply   = reply;
	obj->FnMod   = rc & SS_Mask;
	obj->Timeout = IOCTimeout;
	
	strcpy(obj->Name,mcb->Data+rep->Pathname);

	AddObject( obj );

	rc = Err_Null;

    Done:
#ifdef SYSDEB
	SysDebug(ioc)("Create: %E object: %O",rc,obj);
	if( mcb->MsgHdr.Reply != NullPort ) SysDebug(error)("Create: Non-Null Reply port %x",mcb->MsgHdr.Reply);
#endif
	if( mcb->MsgHdr.Reply != NullPort ) FreePort(mcb->MsgHdr.Reply);

	FreeMsgBuf(mcb);

	if( rc < Err_Null ) FreePort(reply);

	object->Result2 = rc;
	
	return obj;	
}
コード例 #10
0
ファイル: ioc.c プロジェクト: jamjr/Helios-NG
PUBLIC Object *
Locate(
       Object *	object,
       STRING	name )
{
	word rc = Err_Null;
	Object *obj = Null(Object);
	MCB *mcb;
	IOCReply1 *rep;
	word oblen;
	Port reply;
	word fnmod = 0;


#ifdef SYSDEB
	SysDebug(ioc)("Locate(%O,%N)",object,name);
#endif
	/* Locate can be called with a null object pointer */
	
	if( object != NULL ) 
	{	
		if( CheckObject(object,C_Locate) != Err_Null )
		  {
		    return NULL;
		  }
		
		fnmod = object->FnMod;
	}

	reply = NewPort();

	mcb = NewMsgBuf(0);
	rep = (IOCReply1 *)mcb->Control;

	InitMCB(mcb,MsgHdr_Flags_preserve,
		MyTask->IOCPort,reply,FC_GSP|FG_Locate|fnmod);

	MarshalCommon(mcb,object,name);

	if( (rc = IOCMsg(mcb,NULL)) < Err_Null )
	  {
	    goto Done;
	  }

	oblen = sizeof(Object) + (word)strlen(mcb->Data+rep->Pathname) + SafetyMargin;

	obj = (Object *)Malloc(oblen);
	
	if( obj == NULL )
	{
		rc = EC_Error|SS_SysLib|EG_NoMemory|EO_Object;

		goto Done;
	}
	else memclr( (void *)obj, (int)oblen );

	obj->Type    = rep->Type;
	obj->Flags   = rep->Flags;
	obj->Access  = rep->Access;
	obj->Reply   = reply;
	obj->FnMod   = rc & SS_Mask;
	obj->Timeout = IOCTimeout;
	
	strcpy(obj->Name,mcb->Data+rep->Pathname);

	AddObject( obj );

	rc = Err_Null;

    Done:
#ifdef SYSDEB
	SysDebug(ioc)("Locate: %E object: %O",rc,obj);
	if( mcb->MsgHdr.Reply != NullPort ) SysDebug(error)("Locate: Non-Null Reply port %x",mcb->MsgHdr.Reply);
#endif
	if( mcb->MsgHdr.Reply != NullPort ) FreePort(mcb->MsgHdr.Reply);

	FreeMsgBuf(mcb);

	if( object != Null(Object) ) object->Result2 = rc;

	if( rc < Err_Null ) FreePort(reply);

	return obj;
}
コード例 #11
0
ファイル: vsap.c プロジェクト: 2dot4/Psiphon3-for-Linux
static int do_bind(int sock,PVStr(lport),PCStr(opts),int *sharedp,PVStr(sockname),int toC)
{	int svsock;
	CStr(host,MaxHostNameLen);
	CStr(ports,256);
	int port;
	int nlisten;
	int wcc;
	int sockid;

	*sharedp = 0;
	host[0] = 0;
	ports[0] = 0;
	port = 0;
	nlisten = 0;

	if( lport[0] == '/' ){
		svsock = server_open_un("vsap",AVStr(lport),1);
		daemonlog("E","## SVPORT %s [%d]\n",lport,svsock);
		if( svsock < 0 ){
		wcc = SockPrintf(toC,"%s %d not bound-1\r\n",VER,NO_BIND);
		return -1;
		}
		strcpy(sockname,lport);
		*sharedp = 1;
		goto BOUND;
	}

	if( strchr(lport,':') )
		Xsscanf(lport,"%[^:]:%s",AVStr(host),AVStr(ports));
	else	Xsscanf(lport,"%s",AVStr(ports));
	port = atoi(ports);

	if( strncmp(opts,"-l=",3) == 0 )
		nlisten = atoi(opts+3);

	daemonlog("D","bind: %s:%d nlisten=%d\n",host,port,nlisten);

	if( 0 <= (svsock = ServSockOf(host,port)) ){
		daemonlog("D","## SVPORT %d\n",svsock);
		*sharedp = 1;
	}else
	if( 0 <= (svsock = ReservedPortSock(host,port)) ){
		daemonlog("D","## RESV_PORT %d\n",svsock);
		*sharedp = 1;
	}else
	if( lSINGLEP()
	 && 0 <= (svsock = findopen_port("VSAP",AVStr(host),port,nlisten)) ){
		daemonlog("D","## SHARED_PORT %d\n",svsock);
		*sharedp = 1;
	}else
	if( 0 <= (svsock = NewPort(lport,AVStr(host),port,toC,nlisten)) ){
		daemonlog("D","## NEW_PORT %d\n",svsock);
		*sharedp = 0;
	}else{
		wcc = SockPrintf(toC,"%s %d not bound-2 %s\r\n",VER,NO_BIND,
			lport);
		return -1;
	}
	gethostName(svsock,AVStr(sockname),"%A:%P");

BOUND:
	sockid = add_svsock(svsock);
	wcc = SockPrintf(toC,"%s %d %d %s bound.\r\n",VER,OK_BIND,
		sockid,sockname);
	return svsock;
}
コード例 #12
0
ファイル: termwm.c プロジェクト: jamjr/Helios-NG
int 
main ( int argc, char *argv[] )
{
    char	*tname;
    char	wmname[100];
    MCB		m;
    word	e;
    word	Control_V[IOCMsgMax];
    byte	Data_V[IOCDataMax];
    Port	reply;
  
    					/* Check args for plausibility	*/
    if ( argc == 1 )
    {
    	strncpy ( wmname, Heliosno ( stdin )->Name, 99 );
    	wmname[99] = '\0';
    	* ( strrchr ( wmname, c_dirchar ) ) = '\0';
    }
    else
    {
    	strncpy ( wmname, argv[1], 99 );
    	wmname[99] = '\0';
    	if ( argc > 2 )
 	fprintf (stderr, "%s : Further arguments are ignored !\n",
 		 argv[0] );
    }
    
/*    printf ( "%s: window server is \"%s\".\n", argv[0], wmname );	*/
        
 /*-----------------  Prepare MCB for marshalling  ---------------------*/
 

    reply = NewPort ();			/* Basic initialisation of the	*/
					/* MesssageControlBlock		*/
    InitMCB ( &m, MsgHdr_Flags_preserve, MyTask->IOCPort, reply,
 	   FC_GSP + FG_Terminate);
 	   				/* Preparing control and data	*/
    m.Control = Control_V;		/* vector			*/
    m.Data    = Data_V; 	   
    MarshalCommon ( &m, Null ( Object ), wmname );          
    MarshalString ( &m, tname );

/*    printf ( "%s sending request.\n", argv[0] );			*/
/*    fflush ( stdout );						*/
    
    e = PutMsg ( &m );			/* Send message to the server	*/
    if ( e != Err_Null )
    {
 	fprintf (stderr, "%s : Can't send message to server %s :%x\n",
 		 argv[0], wmname, e);
 	return 1;
    }
 					/* Wait for reply		*/
 					/* from the window server...	*/
    InitMCB ( &m, MsgHdr_Flags_preserve, reply, NullPort, 0 );
    m.Timeout = MaxInt;

/*    printf ( "%s waiting for reply.\n", argv[0] );			*/
/*    fflush ( stdout );						*/
    
    e = GetMsg ( &m );
    FreePort ( reply );
 
    if ( m.MsgHdr.FnRc == FC_GSP + SS_Window + FG_Terminate )
	return 0;

    else
    {
 	fprintf (stderr,"%s: Failed to terminate %s - %08x\n",
 		 argv[0], wmname, m.MsgHdr.FnRc ); 
	return 1;
    }
}