Beispiel #1
0
/*
 * func_login logs the user into the remote host.
 */
void func_login( char *command)
{
   char *User=NULL;
 
   if( command && *command)
     User=&command[5];
   if( flag_connected )  {
     /* ignore leading whitespace */
     
     while(User && (*User == ' ' || *User == 't') && *User)
 User++;
     /* if user name was not provided via command line, read it in. */
     
     if(!User || !(*User) ) {
printf("Login:"******"n");   /* remove 'n' */
     }
     /*
      * send user name & password to server  & get reply message
      */
     sprintf(tmp_buffer,"USER %srn",User);
     send_ctrl_msg(tmp_buffer,strlen(tmp_buffer));
     k=get_host_reply();
     TranslateReply(k);
     getpassword( ftp_pass );
     sprintf(tmp_buffer,"PASS %srn",ftp_pass);
     send_ctrl_msg(tmp_buffer,strlen(tmp_buffer));
     k=get_host_reply();
     TranslateReply(k);
   }
   else
      printf("Not connected.n");
}
Beispiel #2
0
static int parse_siit_json(cJSON *json)
{
	bool global_found = false;
	bool pool6_found = false;
	bool eamt_found = false;
	bool blacklist_found = false;
	bool pool6791_found = false;
	bool *globals_found;
	int error;

	error = send_ctrl_msg(SEC_INIT);
	if (error)
		return error;

	globals_found = create_globals_found_array();
	if (!globals_found) {
		log_err("Out of memory.");
		return -ENOMEM;
	}

	for (json = json->child; json; json = json->next) {
		if (strcasecmp("global", json->string) == 0) {
			check_duplicates(&global_found, "global");
			error = handle_global(json, globals_found);
		} else if (strcasecmp("pool6", json->string) == 0) {
			check_duplicates(&pool6_found, "pool6");
			error = handle_pool6(json);
		} else if (strcasecmp("eamt", json->string) == 0) {
			check_duplicates(&eamt_found, "eamt");
			error = handle_eamt(json);
		} else if (strcasecmp("blacklist", json->string) == 0) {
			check_duplicates(&blacklist_found, "blacklist");
			error = handle_addr4_pool(json, SEC_BLACKLIST);
		} else if (strcasecmp("pool6791", json->string) == 0) {
			check_duplicates(&pool6791_found, "pool6791");
			error = handle_addr4_pool(json, SEC_POOL6791);
		} else if (strcasecmp("file_type", json->string) == 0) {
			/* No code. */
		} else {
			log_err("I don't know what '%s' is; Canceling.",
					json->string);
			error = -EINVAL;
		}

		if (error) {
			free(globals_found);
			return error;
		}
	}
	free(globals_found);

	return send_ctrl_msg(SEC_COMMIT);
}
Beispiel #3
0
static int parse_nat64_json(cJSON *json)
{
	bool global_found = false;
	bool pool6_found = false;
	bool pool4_found = false;
	bool bib_found = false;
	bool *globals_found;
	int error;

	error = send_ctrl_msg(SEC_INIT);
	if (error)
		return error;

	globals_found = create_globals_found_array();
	if (!globals_found) {
		log_err("Out of memory.");
		return -ENOMEM;
	}

	for (json = json->child; json; json = json->next) {
		if (strcasecmp("global", json->string) == 0) {
			check_duplicates(&global_found, "global");
			error = handle_global(json, globals_found);
		} else if (strcasecmp("pool6", json->string) == 0) {
			check_duplicates(&pool6_found, "pool6");
			error = handle_pool6(json);
		} else if (strcasecmp("pool4", json->string) == 0) {
			check_duplicates(&pool4_found, "pool4");
			error = handle_pool4(json);
		} else if (strcasecmp("bib", json->string) == 0) {
			check_duplicates(&bib_found, "bib");
			error = handle_bib(json);
		} else if (strcasecmp("file_type", json->string) == 0) {
			/* No code. */
		} else {
			log_err("I don't know what '%s' is; Canceling.",
					json->string);
			error = -EINVAL;
		}

		if (error) {
			log_info("Error: %d", error);
			free(globals_found);
			return error;
		}
	}
	free(globals_found);

	return send_ctrl_msg(SEC_COMMIT);
}
Beispiel #4
0
/*
 * func_list
 * perform directory listing i.e: ls
 */
void func_list( char *command)
{
   if( !flag_connected ) {
      printf("Not flag_connected.n");
      return;
   }
   /*
    * obtain a listening socket
    */
   if( get_listen_socket() < 0) {
       printf("Cannot obtain a listen socket.n");
       return;
   }
   
   /*
    * parse command
    */
   if( !strcmp(command,"ls") )  {
       sprintf(tmp_buffer,"NLSTrn");
   }
   else if( !strcmp(command,"dir") ) 
       sprintf(tmp_buffer,"LISTrn");
   else if( !strncmp(command, "ls ",3)) {
       while( *command == ' ') command++;
       sprintf(tmp_buffer,"LIST %srn",&command[3]);
   }
   /*
    * send command to server and get response
    */
   send_ctrl_msg(tmp_buffer,strlen(tmp_buffer));
   memset(tmp_buffer,0,1024);
   k=get_host_reply();
   TranslateReply(k);
   /*
    * accept server's connection
    */
   if(accept_connection() < 0) {
      printf("Cannot accept connection.n");
      return;
   }
   close_listen_socket();       /* close listening socket */
   /*
    * display directory listing.
    */
   while( data_msg(tmp_buffer,1024) > 0) {
       fflush(stdout);
       printf(tmp_buffer);
       memset(tmp_buffer,0,1024);
   }
   /*
    * read response
    */
   k=get_host_reply();
   TranslateReply(k);
}
Beispiel #5
0
/*
 * func_ascii_mode
 * set file transfer mode to ascii text
 */
void func_ascii_mode()
{
  if( !flag_connected ) {
      printf("Not flag_connected.n");
      return;
  }
   sprintf(tmp_buffer, "TYPE Arn");
   send_ctrl_msg(tmp_buffer,strlen(tmp_buffer));
   int k=get_host_reply();
   TranslateReply(k);
   printf("File transfer modes set to ascii.n");
   bMode = ASCII;
}
Beispiel #6
0
/*
 * func_binary_mode
 * set file transfer mode to binary
 */
void func_binary_mode()
{
  if( !flag_connected ) {
      printf("Not flag_connected.n");
      return;
  }
   sprintf(tmp_buffer, "TYPE Irn");
   send_ctrl_msg(tmp_buffer,strlen(tmp_buffer));
   int k=get_host_reply();
   TranslateReply(k);
   printf("File transfer modes set to binary.n");
   bMode = BINARY;
}
Beispiel #7
0
/*
 * func_close
 * closes connection to the ftp server
 */
void func_close( void )
{
   if( !flag_connected  ) {
     printf("Not connected.n");
    
   }
   else {
   send_ctrl_msg("quitrn",6);
   get_host_reply();
   close_control_connect();
   hControlSocket = -1;
   flag_connected = 0;
   }
}
Beispiel #8
0
void onSerRecv(uint8_t bytes)
{
    // int i;
    // PRINTF("Pong: ");
    // for(i=0; i<bytes; i++)
    // {
    //     PRINTF("%c", (char)serBuffer[i]);
    // }
    // PRINTF("\n");

    if(bytes>=1 && serBuffer[0] == 'r'){
        PRINTF("Ser: Restart!\n");
        flRestart = true;
        send_ctrl_msg(MSG_ACT_RESTART);
    }

}
Beispiel #9
0
// --------------------------------------------
// --------------------------------------------
void appMain(void)
{
    serialEnableRX(PRINTF_SERIAL_ID);
    // serialSetReceiveHandle(PRINTF_SERIAL_ID, onSerRecv);
    serialSetPacketReceiveHandle(PRINTF_SERIAL_ID, onSerRecv, serBuffer, SER_BUF_SIZE);

    radioSetReceiveHandle(onRadioRecv);
    radioOn();
    mdelay(200);

    // Send restart message to the phaser
    send_ctrl_msg(MSG_ACT_RESTART);

    while (1) {
        mdelay(RATE_DELAY);
        led0Toggle();
    }
}
Beispiel #10
0
/*
func_delete("DELE %srn", argv[1]);
*/
void func_delete(char *command)
{
   char *file=&command[6];
   if( !flag_connected ) {
       printf("Not flag_connected.n");
       return;
   }
   /*
    * ignore leading whitespace
    */
   while( *file && (*file == ' ' || *file == 't') ) 
       file++;
   /*
    * if file is not specified, read it in
    */
   if( ! (*file) ) {
      printf("Remote file name:");
      fgets(tmp_buffer,1024,stdin);
      (void)strtok(tmp_buffer,"n");
      file = (char *)strdup(tmp_buffer);
      while( *file && (*file) == ' ') 
       file++;
      if( !(*file) ) {
printf("Usage: delete remote-filen");
return;
      }
   }
   
   /*
    * send command to server and read response
    */
   sprintf(tmp_buffer, "DELE %srn",file);
   send_ctrl_msg(tmp_buffer,strlen(tmp_buffer));
   int k=get_host_reply();
   TranslateReply(k);
   printf("%s deleted.n", file);
   
}
Beispiel #11
0
/*
 * func_cdir
 * chang to another directory on the remote system
 */
void func_cdir( char *command)
{
   char *dir=&command[2];
   if( !flag_connected ) {
       printf("Not flag_connected.n");
       return;
   }
   /*
    * ignore leading whitespace
    */
   while( *dir && (*dir == ' ' || *dir == 't') ) 
       dir++;
   /*
    * if dir is not specified, read it in
    */
   if( ! (*dir) ) {
      printf("Remote directory:");
      fgets(tmp_buffer,1024,stdin);
      (void)strtok(tmp_buffer,"n");
      dir = (char *)strdup(tmp_buffer);
      while( *dir && (*dir) == ' ') 
       dir++;
      if( !(*dir) ) {
printf("Usage: cd remote-directoryn");
return;
      }
   }
   
   /*
    * send command to server and read response
    */
   sprintf(tmp_buffer, "CWD %srn",dir);
   send_ctrl_msg(tmp_buffer,strlen(tmp_buffer));
   int k=get_host_reply();
   TranslateReply(k);
}
Beispiel #12
0
// --------------------------------------------
// --------------------------------------------
void onRadioRecv(void)
{
    static bool flRxProcessing=false;
    if(flRxProcessing){
#ifdef PRINT_PACKETS
        PRINTF("RX Locked\n");
#endif
        return;
    }
    flRxProcessing=true;    // There is a chance for a small race condition

#ifdef PRINT_PACKETS
    uint32_t rxTime = getTimeMs();
#endif
    int16_t rxLen;
    rssi_t rssi;
    lqi_t lqi;

    rxIdx++;
    if( rxIdx < 0 ) rxIdx=0;


    led1Toggle();

    // rxLen = radioRecv( &(DB_REC(db)), DB_REC_SIZE(db));
    // DB_REC(db).recLen = rxLen;
    rxLen = radioRecv(&radioBuffer, sizeof(radioBuffer));
    rssi = radioGetLastRSSI();
    lqi = radioGetLastLQI();

#ifdef PRINT_PACKETS
    PRINTF("%d\t%d\t%d\t%d\t%ld\t", (int)rxIdx, (int)rxLen, (int)rssi, (int)lqi, (long)rxTime);
#endif
#ifdef PRINT_PACKETS
    if (rxLen < 0) {
        PRINTF("RX failed\n");
    }
    else if (rxLen > 0 ) {
        debugHexdump((uint8_t *) &radioBuffer, rxLen);
        // debugHexdump((uint8_t *) &(DB_REC(db)), rxLen);
    }
#endif
    if (rxLen < 0) {
        led2Toggle();
        flRxProcessing=false;
        return;
    }

    if( ! MSG_SIGNATURE_OK(radioBuffer) ) { flRxProcessing = false; return; }

    // Anticipated payload types.
    MSG_NEW_PAYLOAD_PTR(radioBuffer, phaser_ping_t, test_data_p);
    MSG_NEW_PAYLOAD_PTR(radioBuffer, phaser_control_t, ctrl_data_p);
    MSG_NEW_PAYLOAD_PTR(radioBuffer, msg_text_data_t, msg_text_p);
    MSG_NEW_PAYLOAD_PTR(radioBuffer, test_config_t, test_config_p);

    int act = MSG_ACT_CLEAR;
    bool flOK=true;

    switch( radioBuffer.id ){
    case PH_MSG_Test:
        MSG_CHECK_FOR_PAYLOAD(radioBuffer, phaser_ping_t, flOK=false );
        if( !flOK ){
            PRINTF("BadChk\n");
            break;
        }
        // Check if new experiment iteration started.
        if(lastExpIdx != test_data_p->expIdx && curExp){
            sendTestResults();
        }
        processTestMsg(test_data_p, rssi, lqi);
        break;
    
    case PH_MSG_Angle:
        if(curExp) sendTestResults();
        if( flRestart ){        // Best time to resend the restart message after the angle change
            send_ctrl_msg(MSG_ACT_RESTART);
            flRestart = false;
        }
        break;

    case PH_MSG_Control:
        MSG_CHECK_FOR_PAYLOAD(radioBuffer, phaser_control_t, break);
        if(curExp) sendTestResults();

        act = ctrl_data_p->action;
        if(act == MSG_ACT_START ){
            flRestart = false;  // Clear restart command attempt
        }
        printAction(act);
        break;

    case PH_MSG_Text:
        MSG_CHECK_FOR_PAYLOAD(radioBuffer, msg_text_data_t, break );
        PRINTF(msg_text_p->text);
        PRINTF("\n");
        break;

    case PH_MSG_Config:
        MSG_CHECK_FOR_PAYLOAD(radioBuffer, test_config_t, break );
        PRINTF("Config received:\n");
        // TODO: parse the config and print
        print_test_config(test_config_p);
    }


    flRxProcessing=false;
}
Beispiel #13
0
/* called to retrive a file from remote host */
void getfile( char *fname)
{
   FILE *fp=NULL;
   int fd, nTotal=0, nBytesRead=0, retval, aborted=0;
   char *abortstr = "ABORrn", ch;
   if( !fname || ! (*fname)) {
      printf("No file specified.n");
      return;
   }
   /*
    * open the file with current mode
    */
   if(! (fp=fopen(fname,(bMode==ASCII) ? "wt" : "wb"))) {
      perror("file open");
      return;
   }
   /*
    * obtain a listen socket
    */
   if( get_listen_socket() < 0) {
       fclose(fp);
       return;
   }
   
   /*
    * send command to server and read response
    */
   sprintf(tmp_buffer,"RETR %srn",fname);
   if(!send_ctrl_msg(tmp_buffer,strlen(tmp_buffer))) {
      fclose(fp);
      return;
   }
   int l= get_host_reply();
if(l==550)return;
   
   /*
    * accept server connection
    */
   if( accept_connection() <= 0) {
       fclose(fp);
       return;
   }
   /* 
    * now get file and store
    */
   
   fd = fileno(fp);
   printf("Type q and hit return to abortrn");
   while( (nBytesRead=data_msg(tmp_buffer,1024)) > 0) {
       
   
   write(fd,tmp_buffer,nBytesRead);
   nTotal+=nBytesRead;
   printf("%s : %d receivedr",fname,nTotal);
   if( check_input() ) {
        ch = getchar();
        if( ch != 'n') {
        while( getchar() != 'n') ;      /* read 'til new line */
        }
        if( ch == 'q') 
        aborted = 1;
   }
   
   /*
    * did we abort?
    */
   if( aborted ) {
  
   printf("rnAbort: Waiting for server to finish.");
   send_ctrl_msg(abortstr,strlen(abortstr));
   break;
   }
   }
   if( aborted ) {         // ignore everything if aborted.
   while( (nBytesRead=data_msg(tmp_buffer,1024)) > 0);
   get_host_reply();
   }
 /*  (void)signal(SIGINT,OldHandler); */
   printf("rn");
   close(fd);
   close_data_connection(hDataSocket);
 /*/  ControlCHit = 0; */
   get_host_reply();
}
Beispiel #14
0
/*
 * put_file
 */
void put_file( char *fname)
{
   FILE *fp=NULL;
   int fd, nTotal=0, nBytesRead=0, retval, aborted=0;
   char *abortstr = "ABORrn", ch;
  /* void (*OldHandler)(int); */
   if( !fname || ! (*fname)) {
      printf("No file specified.n");
      return;
   }
   if(! (fp=fopen(fname,(bMode==ASCII) ? "rt" : "rb"))) {
      perror("file open");
      return;
   }
   if( get_listen_socket() < 0) {
       fclose(fp);
       return;
   }
   
   /*
    * send command to server & read reply
    */
   sprintf(tmp_buffer,"STOR %srn",fname);
   if(!send_ctrl_msg(tmp_buffer,strlen(tmp_buffer))) {
      fclose(fp);
      return;
   }
   int m=get_host_reply();
   if(m==550)
return;
   /*
    * accept server connection
    */
   if( accept_connection() <= 0) {
       fclose(fp);
       return;
   }
   /* 
    * now send file
    */
   
   fd = fileno(fp);
   printf("Type q and hit return to abortrn");
   while( (nBytesRead=read(fd,tmp_buffer,1024)) > 0) {
      send_data_msg(tmp_buffer,nBytesRead);
      nTotal+=nBytesRead;
      printf("%s : %d sentr",fname,nTotal);
   if( check_input() ) {
        ch = getchar();
        if( ch != 'n') {
        while( getchar() != 'n') ;      /* read 'til new line */
        }
        if( ch == 'q') 
        aborted = 1;
   }
   /*
    * send an abort command to server if we aborted.
    */
   if( aborted ) {
  
   printf("rnAbort: Waiting for server to finish.");
   send_ctrl_msg(abortstr,strlen(abortstr));
   break;
   }
   }
   /*(void)signal(SIGINT,OldHandler); */
   printf("rn");
   /*
    * close data connection
    */
   close_data_connection(hDataSocket);
   close(fd);
   get_host_reply();
}
Beispiel #15
0
int main(int argc, char *argv[])
{
	if (argc > 1)
		parse_args(argc, argv, lgp, mip);

	if (mip->shouldfork) {
		pid_t pid = 0;

		pid = fork();
		if (pid < 0) {
			int er = errno;

			fprintf(stderr, "fork failed.\n");
			exit(er);
		}

		if (pid > 0)
			exit(0);
	}

	int tstatus;

	/* Catch sigint (ctrl-c) */
	signal(SIGINT, siginthandler);

	/* Catch sigterm (kill) */
	signal(SIGTERM, siginthandler);

	/* Catch SIGUSR1, for writing control data */
	signal(SIGUSR1, sigusr1handler);

	/* get executable name, used for logging */
	dname = basename(argv[0]);
	strncpy(mip->dname, dname, sizeof(mip->dname));

	/* get PID, also used for logging */
	mip->pid = (unsigned long) getpid();

	/* initialise modbus & application parameters, & set
	 * up modbus port */
	pv = mbd_init(mbp, lgp, mip);

	logger("starting", lgp, mip);

	/* kick things off with an initial reading (otherwise
	 * the first reading won't happen until the first timer
	 * expires) */
	mbd_tick();

	tstatus = start_periodic_task(mbp->msecs, mbd_tick);
	if (tstatus != 0)
		fatal("can't create timer", mbp, lgp, mip, tstatus);

	while (1) {
		if (gotsigusr1 == 1) {
			send_ctrl_msg(mbp, mip, lgp);
			gotsigusr1 = 0;
		}

		if (gotkillsig == 1) {
			mbd_exit(mbp, lgp, mip);
			unlink(mip->fifo);
			free(pv);
			exit(0);
		}

		usleep(50000);
	}
}