Example #1
0
void print_help()
{
  int i;
  printf("Use ./csi_tool mode output input format ap_name client_name debug\n");
  printf("Mode:");
  for ( i = 0; i < NO_MODES; i++) {
    printf("\t%s:\t%s -> %s\n",modes[i],input_types[io_type(modes[i][0],INPUT)], output_types[io_type(modes[i][2],TARGET)]);
  }

  printf("\nOutputformat:\n");
  for ( i = 0; i < NO_TYPES; i++) {
    printf("\t%s\n", format_types[i]);
  }
}
Example #2
0
STXXL_BEGIN_NAMESPACE


void wincall_file::serve(const request* req) throw (io_error)
{
    scoped_mutex_lock fd_lock(fd_mutex);
    assert(req->get_file() == this);
    offset_type offset = req->get_offset();
    void* buffer = req->get_buffer();
    size_type bytes = req->get_size();
    request::request_type type = req->get_type();

    if (bytes > 32 * 1024 * 1024) {
        STXXL_ERRMSG("Using a block size larger than 32 MiB may not work with the " << io_type() << " filetype");
    }

    HANDLE handle = file_des;
    LARGE_INTEGER desired_pos;
    desired_pos.QuadPart = offset;
    if (!SetFilePointerEx(handle, desired_pos, NULL, FILE_BEGIN))
    {
        STXXL_THROW_WIN_LASTERROR(io_error,
                                  "SetFilePointerEx in wincall_request::serve()" <<
                                  " offset=" << offset <<
                                  " this=" << this <<
                                  " buffer=" << buffer <<
                                  " bytes=" << bytes <<
                                  " type=" << ((type == request::READ) ? "READ" : "WRITE"));
    }
    else
    {
        stats::scoped_read_write_timer read_write_timer(bytes, type == request::WRITE);

        if (type == request::READ)
        {
            DWORD NumberOfBytesRead = 0;
            assert(bytes <= std::numeric_limits<DWORD>::max());
            if (!ReadFile(handle, buffer, (DWORD)bytes, &NumberOfBytesRead, NULL))
            {
                STXXL_THROW_WIN_LASTERROR(io_error,
                                          "ReadFile" <<
                                          " this=" << this <<
                                          " offset=" << offset <<
                                          " buffer=" << buffer <<
                                          " bytes=" << bytes <<
                                          " type=" << ((type == request::READ) ? "READ" : "WRITE") <<
                                          " NumberOfBytesRead= " << NumberOfBytesRead);
            }
            else if (NumberOfBytesRead != bytes) {
                STXXL_THROW_WIN_LASTERROR(io_error, " partial read: missing " << (bytes - NumberOfBytesRead) << " out of " << bytes << " bytes");
            }
        }
        else
        {
            DWORD NumberOfBytesWritten = 0;
            assert(bytes <= std::numeric_limits<DWORD>::max());
            if (!WriteFile(handle, buffer, (DWORD)bytes, &NumberOfBytesWritten, NULL))
            {
                STXXL_THROW_WIN_LASTERROR(io_error,
                                          "WriteFile" <<
                                          " this=" << this <<
                                          " offset=" << offset <<
                                          " buffer=" << buffer <<
                                          " bytes=" << bytes <<
                                          " type=" << ((type == request::READ) ? "READ" : "WRITE") <<
                                          " NumberOfBytesWritten= " << NumberOfBytesWritten);
            }
            else if (NumberOfBytesWritten != bytes) {
                STXXL_THROW_WIN_LASTERROR(io_error, " partial write: missing " << (bytes - NumberOfBytesWritten) << " out of " << bytes << " bytes");
            }
        }
    }
}
Example #3
0
bool io_open_try(io_log_name *naml, io_log_name *tl, mval *pp, int4 timeout, mval *mspace)
{
	char		buf1[MAX_TRANS_NAME_LEN];	/* buffer to hold translated name */
	char		dev_type[MAX_DEV_TYPE_LEN];
        int             n;
	mstr		tn;				/* translated name */
	uint4		stat;				/* status */
	int		p_offset;
	unsigned char	ch;
	ABS_TIME	cur_time, end_time;
	bool		out_of_time = FALSE;

	if (0 == naml->iod)
	{
		if (0 == tl->iod)
		{
			tl->iod = (io_desc *)malloc(SIZEOF(io_desc));
			memset((char*)tl->iod, 0, SIZEOF(io_desc));
			tl->iod->pair.in  = tl->iod;
			tl->iod->pair.out = tl->iod;
			tl->iod->trans_name = tl;
			p_offset = 0;
			while (iop_eol != *(pp->str.addr + p_offset))
			{
				if ((iop_tmpmbx == (ch = *(pp->str.addr + p_offset++))) || (iop_prmmbx == ch))
					tl->iod->type = mb;
				else  if (iop_nl == ch)
					tl->iod->type = nl;
				p_offset += ((IOP_VAR_SIZE == io_params_size[ch]) ?
					(unsigned char)*(pp->str.addr + p_offset) + 1 : io_params_size[ch]);
			}
			if (!tl->iod->type && mspace && mspace->str.len)
			{
				lower_to_upper(dev_type, mspace->str.addr, mspace->str.len);
				if (((SIZEOF("SOCKET") - 1) == mspace->str.len)
					&& (0 == memcmp(dev_type, LIT_AND_LEN("SOCKET"))))
					tl->iod->type = gtmsocket;
				else
					tl->iod->type = us;
			}
			if (!tl->iod->type)
			{
				tn.len = tl->len;
				tn.addr = &tl->dollar_io;
				tl->iod->type = io_type(&tn);
			}
		}
		naml->iod = tl->iod;
	}
	tl->iod->disp_ptr = &io_dev_dispatch[tl->iod->type];
	assert(0 != naml->iod);
	active_device = naml->iod;
	if (dev_never_opened == naml->iod->state)
	{
		naml->iod->wrap = DEFAULT_IOD_WRAP;
		naml->iod->width = DEFAULT_IOD_WIDTH;
		naml->iod->length = DEFAULT_IOD_LENGTH;
		naml->iod->write_filter = write_filter;
	}
	if (dev_open != naml->iod->state)
	{
		naml->iod->dollar.x = 0;
		naml->iod->dollar.y = 0;
		naml->iod->dollar.za = 0;
		naml->iod->dollar.zb[0] = 0;
		naml->iod->dollar.zeof = FALSE;
	}
	if (0 == timeout)
		stat = (naml->iod->disp_ptr->open)(naml, pp, -1, mspace, timeout);	/* ZY: add a parameter timeout */
	else  if (NO_M_TIMEOUT == timeout)
	{
		while (FALSE == (stat = (naml->iod->disp_ptr->open)(naml, pp, -1, mspace, timeout)))	/* ZY: add timeout */
		{
			hiber_start(1000);	/* 1 second */
			if (outofband)
				outofband_action(FALSE);
		}
	} else
	{
		sys_get_curr_time(&cur_time);
		add_int_to_abs_time(&cur_time, timeout * 1000, &end_time);
		while (FALSE == (stat = (naml->iod->disp_ptr->open)(naml, pp, -1, mspace, timeout))	/* ZY: add timeout */
			&& (!out_of_time))
		{
			hiber_start(1000);	/* 1 second */
			if (outofband)
				outofband_action(FALSE);
			sys_get_curr_time(&cur_time);
			if (abs_time_comp(&end_time, &cur_time) <= 0)
				out_of_time = TRUE;
		}
	}
	if (TRUE == stat)
	{
		naml->iod->state = dev_open;
		if (27 == naml->iod->trans_name->dollar_io[0])
		{
			tn.addr = &naml->iod->trans_name->dollar_io[4];
			n = naml->iod->trans_name->len - 4;
			if (n < 0)
				n = 0;
			tn.len = n;
			naml->iod->trans_name = get_log_name(&tn, INSERT);
			naml->iod->trans_name->iod = naml->iod;
		}
	}
	else
	{
		if (dev_open == naml->iod->state && (gtmsocket != naml->iod->type))
			naml->iod->state = dev_closed;
		else if ((gtmsocket == naml->iod->type) && naml->iod->newly_created)
		{
			assert(naml->iod->state != dev_open);
			iosocket_destroy(naml->iod);
		}
	}
	active_device = 0;
	if ((NO_M_TIMEOUT != timeout) && IS_MCODE_RUNNING)
		return (stat);
	return FALSE;
}
Example #4
0
int main(int argc, char** argv)
{
  int target = TARGET_UDP_SOCKET;
  int input = INPUT_FILE;
  int output_mode = OUTPUT_MODE_CLICK;

  filter_code = 0xFF;
  filter_rate = 0xFFFF;
  filter_Nrx = 0xFF;

  char *csi_node = "0.0.0.0";
  char *tx_node = "0.0.0.1";

  int debug_level = 0;

  if ( (argc < 5) || ((argc > 1) && (strcmp(argv[1], "help") == 0)) ) {
    print_help();
    exit(0);
  }

  target = io_type(argv[1][2],TARGET);
  input = io_type(argv[1][0],INPUT);
  output_mode = format_type(argv[4][0]);

  printf("Config: %s (%s -> %s) %s %s %s\n", argv[1], input_types[input], output_types[target],
                                             argv[2], argv[3], format_types[output_mode]);

  if ( argc > 5 ) {
    csi_node = argv[5];
    tx_node = argv[6];
  }

  if ( argc > 7 ) {
    debug_level = atoi(argv[7]);
  }

  struct cn_msg *cmsg;
  unsigned char cmsg_input_buf[BUF_SIZE];

  char sendline[3000];
  unsigned char buf[BUF_SIZE];

  int ret;
  int count = 0;

  char hostname[1024];
  gethostname(hostname, 1024);

  uint32_t csi_node_addr = (uint32_t)inet_addr(csi_node);
  uint32_t tx_node_addr = (uint32_t)inet_addr(tx_node);

  unsigned short l, l2;

  /* Make sure usage is correct */
  check_usage(argc, argv);

  /* Set up the "caught_signal" function as this program's sig handler */
  signal(SIGINT, caught_signal);

  /* Prepare Input */
  switch ( input ) {
    case INPUT_SOCKET:
      netlink_sock_fd = open_iwl_netlink_socket();
      break;
    case INPUT_FILE:
      netlink_sock_fd = open_file(argv[3], "r");
      break;
  }

  /* Prepare Output */
  switch ( target ) {
    case TARGET_TCP_SOCKET:
      out_fd = open_tcp_socket(argv[2], 32000);
      break;
    case TARGET_UDP_SOCKET:
      out_fd = open_udp_socket(argv[2], 32000);
      break;
    case TARGET_FILE:
      out_fd = open_file(argv[2], "w");
      break;
    case TARGET_STDOUT:
      out_fd = 1;
      break;
  }

  /* Poll socket forever waiting for a message */
  u_char *buf_p;
  int len_p, len_sendline;

  while (1) {
    /* Receive from socket with infinite timeout */
    //ret = recv(sock_fd, buf, sizeof(buf), 0);

    /* Read the next entry size */

    if (DEBUG_LEVEL_DEV) {
      printf("\n----- Next Data -----\n\n");
    }

    switch (input) {
      case INPUT_FILE:
        /* Read the next entry size */
        ret = read(netlink_sock_fd, &l2, 1 * sizeof(unsigned short));

        if ( ret != 0 ) {
          l = ntohs(l2);
          /* Sanity-check the entry size */

          if (l == 0) {
            fprintf(stderr, "Error: got entry size=0\n");
            exit_program(-1);
          } else if (l > BUF_SIZE) {
            fprintf(stderr, "Error: got entry size %u > BUF_SIZE=%u\n", l, BUF_SIZE);
            exit_program(-2);
          }

          /* Read in the entry */
          read(netlink_sock_fd, buf, l * sizeof(*buf));

          cmsg = (struct cn_msg*)&cmsg_input_buf[0];
          cmsg->id.idx = 0;
          cmsg->id.val = 0;
          cmsg->seq = 0;
          cmsg->ack = 0;
          cmsg->len = l;
          cmsg->flags = 0;
          memcpy(cmsg->data,buf,l);

        }
        if ( ret == 0 ) ret = -1;
        break;
      case INPUT_SOCKET:
        ret = iwl_netlink_recv(netlink_sock_fd, &buf_p, &len_p, &cmsg);
        break;
    }

    if (ret == -1) exit_program_err(-1, "recv");

    if (cmsg == NULL) {
      printf("cmsg == NULL\n");
      continue;
    }
    struct iwl5000_bfee_notif *bfee = NULL;
    bfee = (struct iwl5000_bfee_notif *)&(cmsg->data[1]);

    /* Filter */
    if ( (filter_code != 0xFF) && (cmsg->data[0] != filter_code) ) continue;
    if ( (filter_rate != 0xFFFF) && (bfee->fake_rate_n_flags != filter_rate) ) continue;
    if ( (filter_Nrx != 0xFF) && (bfee->Nrx != filter_Nrx) ) continue;

     if (DEBUG_LEVEL_DEV) printf("Entry size=%d, code=0x%X\n", cmsg->len, cmsg->data[0]);

    /* Evaluation */
    double eff_snrs[MAX_NUM_RATES][4];

    if ( cmsg->data[0] == IWL_CONN_BFEE_NOTIF /*0xBB*/) { /* Beamforming packet */

      calc_eff_snrs(bfee, eff_snrs);

      struct timeval timeVal;
      gettimeofday (&timeVal, NULL);

      if (DEBUG_LEVEL_INFO) printf("Rcvd pkt at <%ld.%06ld>\n", (long int)(timeVal.tv_sec), (long int)(timeVal.tv_usec));

      if (DEBUG_LEVEL_DEV) {
        /* Beamforming packet */
        printf("\nBeamforming: rate=0x%x\n", bfee->fake_rate_n_flags);
        /* Pull out the message portion and print some stats */
        if (count % SLOW_MSG_CNT == 0)
          printf("Received %d bytes: id: %d val: %d seq: %d clen: %d\n", cmsg->len, cmsg->id.idx, cmsg->id.val, cmsg->seq, cmsg->len);

        printf("\n--- Effektive SNR ---\n\n");
        int i;
        for ( i = 0; i < MAX_NUM_RATES; i++) {
          printf("%d: %f %f %f %f\n", i, db(eff_snrs[i][0]), db(eff_snrs[i][1]), db(eff_snrs[i][2]), db(eff_snrs[i][3]));
        }
        printf("\n---------------------\n\n");
      }
    }

    /* Log the data remote */
    /* Puffer mit Text füllen */
    switch (output_mode) {
      case OUTPUT_MODE_FORMAT:
        sprintf(sendline, "%s, Received %d bytes: id: %d val: %d seq: %d clen: %d\n", hostname, cmsg->len, cmsg->id.idx,
                                                                                      cmsg->id.val, cmsg->seq, cmsg->len);
        len_sendline = strlen(sendline);
        break;
      case OUTPUT_MODE_BFEE:
        if ( bfee != NULL) {
          calc_eff_snrs_tostr(bfee, eff_snrs, sendline, hostname);
        } else {
          sprintf(sendline, "bfee == NULL\n");
        }

        if (DEBUG_LEVEL_DEV) printf("To tx:\n%s\n", sendline);
        break;
      case OUTPUT_MODE_CLICK:
        len_sendline = click_output(sendline, bfee, cmsg, eff_snrs, csi_node_addr, tx_node_addr);
        break;
      default:
        /* Log the data to file */
        l = (unsigned short) cmsg->len;
        l2 = htons(l);
        memcpy(sendline, &l2, 1 * sizeof(unsigned short));
        len_sendline = 1 * sizeof(unsigned short);

        memcpy(&(sendline[len_sendline]), cmsg->data, 1 * l);
        len_sendline += 1 * l;

        if ((count % 100 == 0) && (DEBUG_LEVEL_DEV)) printf("wrote %d bytes [msgcnt=%u]\n", len_sendline, count);
    }

    switch ( target ) {
      case TARGET_FILE:
      case TARGET_TCP_SOCKET:
        ret = write(out_fd, sendline, len_sendline);
        break;
      case TARGET_UDP_SOCKET:
        sendto(out_fd, sendline, len_sendline, 0, (struct sockaddr *)&servaddr, sizeof(servaddr));
        break;
      case TARGET_STDOUT:
        dprintf(out_fd,"%s",sendline);
        break;
    }

    ++count;
  }

  exit_program(0);
  return 0;
}