Exemple #1
0
void _device_init(void)
{
	kprintf("\nHAL: _device_init()");
#ifdef NOC_INTERCONNECT
	ni_init();
#endif
#ifdef USTACK
	en_init();
#endif
}
Exemple #2
0
int main(int argc, char **argv)
{
	ni_teamd_client_t *tdc;
	const char *command, *param1, *param2;
	char *val = NULL;
	ni_json_t *json;
	int rv = 0;

	if (argc < 3) {
		printf("Usage: teamd-test ifname command [param1] [param2]\n");
		return -2;
	}
	command = argv[2];
	param1 = argv[3];
	param2 = argv[4];

	if (ni_init("teamd-test") < 0)
		return -1;
	ni_config_teamd_enable(NI_CONFIG_TEAMD_CTL_DETECT_ONCE);

	tdc = ni_teamd_client_open(argv[1]);

	if (ni_string_eq(command, "state-item-get"))
		rv = ni_teamd_ctl_state_get_item(tdc, param1, &val);
	else if (ni_string_eq(command, "state-item-set"))
		rv = ni_teamd_ctl_state_set_item(tdc, param1, param2);
	else if (ni_string_eq(command, "state-dump"))
		rv = ni_teamd_ctl_state_dump(tdc, &val);
	else if (ni_string_eq(command, "config-dump"))
		rv = ni_teamd_ctl_config_dump(tdc, FALSE, &val);
	else if (ni_string_eq(command, "config-dump-actual"))
		rv = ni_teamd_ctl_config_dump(tdc, TRUE, &val);

	printf("%s\n", val ? val : ni_format_boolean(!!rv));

	if (val && (json = ni_json_parse_string(val))) {
		ni_stringbuf_t buf = NI_STRINGBUF_INIT_DYNAMIC;

		ni_json_format_string(&buf, json, NULL);
		printf("type<%s>: %s\n",
			ni_json_type_name(ni_json_type(json)), buf.string);
		ni_stringbuf_destroy(&buf);
		ni_json_free(json);
	} else if (val) {
		printf("json parsing error\n");
	}

	ni_string_free(&val);
	return rv;
}
Exemple #3
0
NI_Code ni_put_msg( void )
{
    LDVCode ldv_error = LDV_OK;
    time_t  deadline;
    timeval TV;

    deadline =  time( NULL ) + niWAIT_TIME;

    // print_array(&msg_out,msg_out.ni_hdr.q.length + sizeof( NI_Hdr ), "%02X "); // karl test

    /* Loop until the network interface accepts the output, or timeout. */
    for( ;; ) {
        ldv_error = ldv_write( ni_handle, &msg_out,
                                msg_out.ni_hdr.q.length + sizeof( NI_Hdr ) );
            /* Attempt to write to the network interface. */

        if( ldv_error == LDV_OK ) break;
        if( ldv_error != LDV_NO_BUF_AVAIL
         && ldv_error != LDV_DEVICE_BUSY ) break;    // non-recoverable
                /* exit loop for fatal err */
        if ( time( NULL ) > deadline )             // see if deadline passed
            /* No response from network interface. */
            return( NI_TIMEOUT );
    }

    if( verbose_flag ) {
	   if(gettimeofday(&TV,0)==0)
           fprintf(LogFilePtr,"Sent a LONTALK Message @ = %sUSeconds = %ld Error = %d\n",ctime(&TV.tv_sec), TV.tv_usec, ldv_error);
       else
           fprintf(LogFilePtr, "\nSent a LONTALK error = %d\n", ldv_error );

        if( ldv_error == LDV_OK )
            ni_msg_display( &msg_out );
    }

    if( ldv_error == LDV_OK ) return( NI_OK );

        /* Network driver returned error, print it, and reopen driver */
    ni_ldv_error_display( "Network driver error on write", ldv_error );
    if ( ni_init( current_device_name ) != NI_OK )
        if (verbose_flag) fprintf(LogFilePtr, "\nCould not reopen network interface.\n" );
    else
        if (verbose_flag) fprintf(LogFilePtr, "\nReopened network interface.\n" );
    return( NI_DRIVER_ERROR );
}
Exemple #4
0
static ni_status
start_service(ni_name tag)
{
    ni_name master;
    ni_name mastertag;
    ni_status status;
    ni_name dbname;
    struct in_addr inaddr;

    system_log(LOG_DEBUG, "directory cleanup");
    dir_cleanup(tag);
    dir_getnames(tag, &dbname, NULL, NULL);

    system_log(LOG_DEBUG, "initializing server");
    status = ni_init(dbname, &db_ni);
    ni_name_free(&dbname);
    if (status != NI_OK)
    {
        system_log(LOG_ERR, "ni_init failed: %s", ni_error(status));
        return (status);
    }

    system_log(LOG_DEBUG, "checksum = %u", ni_getchecksum(db_ni));

    /* "local" is never a clone */
    if (strcmp(tag, "local"))
    {
        if (getmaster(db_ni, &master, &mastertag))
        {
            inaddr.s_addr = getaddress(db_ni, master);
            if (!sys_is_my_address(&inaddr)) i_am_clone++;
            if (!ni_name_match(tag, mastertag)) i_am_clone++;
            ni_name_free(&master);
            ni_name_free(&mastertag);
        }
    }

    if (forcedIsRoot == 0)
        forcedIsRoot = get_forced_root(db_ni);

    system_log(LOG_DEBUG, "registering tag %s", tag);
    status = register_it(tag);
    return (status);
}
Exemple #5
0
NI_Code ni_get_msg( time_t wait ) {   /* how long to wait for input */

    LDVCode ldv_error = LDV_OK;
    time_t  deadline;
    timeval TV;

//    printf("In ni_getmsg handle= 0x0%x\n",ni_handle);
    
    if( wait ) deadline = time( NULL ) + wait;

    /* Loop until the network interface provides a message, or timeout */
    for( ;; ) {
        ldv_error = ldv_read( ni_handle, &msg_in, sizeof( msg_in ) );
        /* Check for network interface input */

       // printf("ldv_error=%d \n",ldv_error);

        if( ldv_error == LDV_OK )
	    {
//            fprintf(LogFilePtr, "\n KARL TEST:\n" );
//    	    print_array( &msg_in, msg_in.ni_hdr.q.length+2, "%02X " );
 //      	    print_array( &msg_in, sizeof(msg_in), "%02X " );

	        break;
	     
	    }

        if( ldv_error != LDV_NO_MSG_AVAIL
         && ldv_error != LDV_DEVICE_BUSY ) break;   // non-recoverable

        if( ! wait || time( NULL ) > deadline )
                return( NI_TIMEOUT );       /* no message received */
    }

    if( ldv_error != LDV_OK ) {
        if (verbose_flag) fprintf(LogFilePtr,"LDV_ERROR != LDV_OK  ldv_error = %d \n", ldv_error);
    
        /* Network driver returned error, print it, and reopen driver */
        if (verbose_flag) ni_ldv_error_display( "Network driver error on read", ldv_error );
        if ( ni_init( current_device_name ) != NI_OK )
             if (verbose_flag) fprintf(LogFilePtr, "\nCould not reopen network interface.\n" );
        else
             if (verbose_flag) fprintf(LogFilePtr, "\nReopened network interface.\n" );
        return( NI_DRIVER_ERROR );
    }

    if( msg_in.ni_hdr.q.q_cmd == niCOMM ) {     // incoming message
        if( verbose_flag ) {
	
	   	   if(gettimeofday(&TV,0)==0)
              if (verbose_flag) fprintf(LogFilePtr,"\nReceived a LONTALK Message @ = %sUSeconds = %ld Error = %d\n",ctime(&TV.tv_sec), TV.tv_usec, ldv_error);
           else
              if (verbose_flag) fprintf(LogFilePtr, "\nReceived a LONTALK error = %d\n", ldv_error );

            if( ldv_error == LDV_OK )  ni_msg_display( &msg_in );
        }
        return( NI_OK );
    }
        // something other than an incoming message

    if( msg_in.ni_hdr.noq.cmd == niRESET )
    {
        if (verbose_flag) fprintf(LogFilePtr, "Received uplink local reset\n" );
        ni_send_immediate( niFLUSH_CANCEL );
    }
    else
        if (verbose_flag) fprintf(LogFilePtr, "Received uplink command 0x%x\n", msg_in.ni_hdr.noq.cmd );

    return( NI_UPLINK_CMD );  /* not a message */
}