Example #1
0
/*
 * Write the command, read the result.
 * XXX: VCLI_ReadResult will allocate ret->answer. Caller MUST free it.
 */
void ipc_send(int handle, void *data, int len, struct ipc_ret_t *ret)
{
	assert(data);
	char buffer[12];
	assert(len < 1000000000);
	assert(len >= 0);
	assert(threads_started > 0);
	snprintf(buffer,11,"%09d ",len);
	ipc_write(handle, buffer, 10);
	ipc_write(handle, data, len);

	VCLI_ReadResult(handle, &ret->status, &ret->answer, 5.0);
}
Example #2
0
/* For writing data to a specific port - use it in the external process. */
int ipc_connect_buf_write(u16 port, void *data, int data_len)
{
    int fd, rc;

    if ((fd = ipc_connect(port)) < 0)
	return -1;
    rc = ipc_write(fd, data, data_len);
    ipc_client_close(fd, rc);
    return rc;
}
Example #3
0
int ipc_string_write(int fd, char *str)
{
    int len;

    len = strlen(str) + 1;
    if (ipc_u32_write(fd, len))
	return -1;
    if (ipc_write(fd, str, len))
	return -1;
    return 0;
}
Example #4
0
static void ipc_send_request(void)
{
	sync_after_write(&ipc, 0x40);

	ipc_write(0, virt_to_phys(&ipc));
	ipc_bell(1);

	ipc_wait_ack();

	ipc_bell(2);
	ipc_irq_ack();
}
Example #5
0
void ipc_read(IPC* ipc)
{
    for (;;)
    {
        error(ERROR_OK);
        if (rb_is_empty(&__GLOBAL->process->ipcs))
            svc_call(SVC_IPC_WAIT, ANY_HANDLE, ANY_CMD, ANY_HANDLE);
        ipc_peek(__GLOBAL->process->ipcs.tail, ipc);
        if (ipc->cmd == HAL_REQ(HAL_SYSTEM, IPC_PING))
            ipc_write(ipc);
        else
            break;
    }
}
Example #6
0
void vfss()
{
    IPC ipc;
    VFSS_TYPE vfss;

#if (VFS_DEBUG_INFO) || (VFS_DEBUG_ERRORS)
    open_stdout();
#endif //(VFS_DEBUG_INFO) || (VFS_DEBUG_ERRORS)

    vfss_init(&vfss);

    for (;;)
    {
        ipc_read(&ipc);
        vfss_request(&vfss, &ipc);
        ipc_write(&ipc);
    }
}
Example #7
0
void app()
{
    APP app;
    CC1101 cc1101;
    IPC ipc;

    app_init(&app);

    cc1101_hw_init(&cc1101);

    for (;;)
    {
        ipc_read(&ipc);
        switch (HAL_GROUP(ipc.cmd))
        {
        default:
            error(ERROR_NOT_SUPPORTED);
            break;
        }
        ipc_write(&ipc);
    }
}
Example #8
0
void loras_main()
{
    IPC ipc;
    LORA lora;
#if (LORA_DEBUG)
    open_stdout();
#endif //LORA_DEBUG
    init(&lora);

    for (;;)
    {
        ipc_read(&ipc);
        switch (HAL_GROUP(ipc.cmd))
        {
        case HAL_LORA:
            loras_request(&lora, &ipc);
            break;
        default:
            error(ERROR_NOT_SUPPORTED);
            break;
        }
        ipc_write(&ipc);
    }
}
Example #9
0
int ipc_u32_write(int fd, u32 n)
{
    n = htonl(n);
    return ipc_write(fd, &n, sizeof(n));
}
Example #10
0
static void ipc_irq_ack(void)
{
	ipc_write(12, 0x40000000);
}
Example #11
0
static void ipc_bell(u32 w)
{
	ipc_write(1, (ipc_read(1) & 0x30) | w);
}
Example #12
0
	void Connector::ThreadEntry(__unused Thread *thread)
	{
		// Register
		{
			struct
			{
				ipc_header_t header;
				char name[255];
			} message;

			message.header.flags = IPC_HEADER_FLAG_RESPONSE | IPC_HEADER_FLAG_GET_RESPONSE_BITS(IPC_MESSAGE_RIGHT_COPY_SEND);
			message.header.reply = _port;
			message.header.port = ipc_get_special_port(0);
			message.header.size = _name->GetLength();
			message.header.id = 0;

			strcpy(message.name, _name->GetCString());
			ipc_write(&message.header);
		}

		// Work loop
		uint8_t *receiveBuffer = new uint8_t[8192 + sizeof(ipc_header_t)];
		uint8_t *responseBuffer = new uint8_t[8192 + sizeof(ipc_header_t)];

		ipc_header_t *receive = reinterpret_cast<ipc_header_t *>(receiveBuffer);
		ipc_header_t *response = reinterpret_cast<ipc_header_t *>(responseBuffer);

		while(!_thread->IsCancelled())
		{
			receive->port = _port;
			receive->flags = IPC_HEADER_FLAG_BLOCK;
			receive->size = 8192;

			ipc_return_t result = ipc_read(receive);

			if(result == KERN_SUCCESS)
			{
				size_t responseSize = 8192;
				bool hasResponse = DispatchMessage(receive->id, receiveBuffer, receive->size, responseBuffer + sizeof(ipc_header_t), responseSize);

				if(hasResponse)
				{
					response->port = receive->port;
					response->flags = 0;
					response->size = responseSize;

					ipc_write(response);
				}
			}
		}

		delete[] receiveBuffer;
		delete[] responseBuffer;

		// Unregister
		{
			struct
			{
				ipc_header_t header;
				char name[255];
			} message;

			message.header.flags = 0;
			message.header.reply = _port;
			message.header.port = ipc_get_special_port(0);
			message.header.size = _name->GetLength();
			message.header.id = 1;

			strcpy(message.name, _name->GetCString());
			ipc_write(&message.header);
		}
	}
Example #13
0
int main(int argc, char *argv[])
{
 if(!init_cfg())
 {
  fprintf(stderr, "Unable to open config file or invalid content in config file.\n");
  exit(1);
 }
 
 parseopts(argc, argv, conf);

 if(conf->msg)
 {
  if(!open_producer())
  {
   printf("Unable to contact Bluemote server!\n");
   exit(1);
  }
  if(ipc_write(conf->device, strlen(conf->device))<=0)
  {
   printf("Unable to send message to Bluemote server!\n");
   close_producer();
   exit(1);
  }
  close_producer();
  exit(0);
 }
 else
 {
  if(!get_lock())
  {
   printf("Another instance of Bluemote already running!\n");
   exit(1);
  }

  if(!open_consumer())
  {
   printf("Unable to listen for messages!\n");
   exit(1);
  }
 }

 strcpy(logfile, getenv("HOME"));
 strcat(logfile, BLUEMOTEDIR);
 strcat(logfile, LOGFILE);

 printf("Setting up signal handlers.\n");
 logger("INIT", "Setting up signal handlers");
 if(!init_signals())
 {
  perror("init_signals()");
  exit(1);
 }

 if(conf->daemon)
 {
  printf("Entering daemon mode.\n");
  logger("INIT", "Entering daemon mode.\n");
  if(daemon(TRUE, FALSE)==-1)
  {
   printf("Unable to enter daemon mode. Exiting.\n");
   logger("ERROR", "Unable to enter daemon mode. Exiting.\n");
   exit(1);
  }
 }

 while(TRUE)
 {
  closeport();

  printf("Connecting to phone...\n");
  logger("INIT", "Connecting to phone...");
  while(openport(conf->device) == -1)
  {
   sprintf(buf,"Unable to connect to phone. Will retry after %d secs.",conf->retrysecs);
   logger("INIT", buf);
   sleep(conf->retrysecs);
   logger("INIT", "Retrying...");
  }
  printf("Connected to phone.\n");
  logger("INIT", "Connected to phone.");
  
  printf("Initialising the connection.\n");
  logger("INIT", "Initialising the connection.\n");
  if(!initport()) exit(1);

  printf("Waiting for commands from phone\n");
  logger("INIT", "Waiting for commands from phone\n");

  /* Not looping to take care of timeout because timeout is very unlikely and
   * this function is called again inside remote(). In the worst case, the I/O
   * commands for Connect event won't have any effect. */
  if(init_mainmenu()==-1) continue;

  exec_event("Connect");
  if(!manual)
  {
   exec_event("MoveIn");
  }
  manual = FALSE;
  remote();
  if(!manual)
  {
   exec_event("MoveOut");
  }
  exec_event("Disconnect");
 }
 return(0);
}
Example #14
0
File: ipc.c Project: const86/rfs
bool ipc_write_uint32_t(struct ipc *ipc, const uint32_t *p)
{
	uint32_t x = htonl(*p);
	return ipc_write(ipc, &x, sizeof(x));
}
Example #15
0
static void ipc_send_response_packet(struct host_packet *pkt)
{
	ipc_write(IPC_PEER_HOST_ID, pkt->response, pkt->response_size);
}
Example #16
0
/**
* Main entry point
*
* @param argc argument counter
* @param argv argument array
*
* @return EXIT_SUCCESS on success, EXIT_FAILURE otherwise
*/
int main(int argc, char  **argv)
{

	struct sigaction s;
	/* We only catch INT and QUIT (allthough we could catch TERM as well) */
	const int signals[] = { SIGINT, SIGQUIT };

	parse_args(argc, argv);

	s.sa_handler = signal_handler;
	s.sa_flags = SA_RESTART;

	/* Block all signals here ... */
	if(sigfillset(&s.sa_mask) < 0) {
		bail_out(EXIT_FAILURE, "Error creating Signal Block Mask");
	}

	/* ... unblock signals and set handler  */
	for(int i = 0; i < 2; ++i) {

		if(sigaction(signals[i], &s, NULL) < 0) {
			bail_out(EXIT_FAILURE, "Failed to sigaction for signale %d", signals[i]);
		}

	}
	
	/* Init ipc variables */
	ipc_init();

#ifdef _BUILD_READIN

	{
		/* readin reads stdin line wise (max MAX_BUF_SIZE - 1 chars) */
		char buf[MAX_BUF_SIZE];
		while(fgets(buf, MAX_BUF_SIZE, stdin) != NULL) {

			/* ... and writes them to shm */
			if(ipc_write(buf) == -1) { /* Write has failed, propably ipc channels have been removed by other process */
				bail_out(EXIT_FAILURE, "Error writing to shared memory");
			}

		}

		if(ipc_write(NULL) == -1) { /* This signals waiting read processed an EOF */
			bail_out(EXIT_FAILURE, "Error writing to shared memory");
		}

		shm_detach(); /* Normal shutdown for readin */

	}
	

#else
	{

		int c = 0;
		
		/* chstat keeps on listening */
		while(1) {

			/* wait for read queue to open up, generate statistic */
			c = ipc_process();

			if(c == -1) { /* Error reading from shmem, probably ipc channels have been removed by other process */
				bail_out(EXIT_FAILURE, "Error reading from shared memory");
			} else if(c == 0) { /* EOF */
				print_stat();
				break;
			} else if(opt_v == 1) { /* If called with -v */
				print_stat();
			}

		}

		ipc_shutdown();	/* Normal shutdown for chstat */
	}

#endif	

	return 0;

}