예제 #1
0
파일: test-ecc.c 프로젝트: rymanluk/bluez
static int test_sample(uint8_t priv_a[32], uint8_t priv_b[32],
				uint8_t pub_a[64], uint8_t pub_b[64],
				uint8_t dhkey[32])
{
	uint8_t dhkey_a[32], dhkey_b[32];
	int fails = 0;

	ecdh_shared_secret(pub_b, priv_a, dhkey_a);
	ecdh_shared_secret(pub_a, priv_b, dhkey_b);

	printf("\n");

	print_buf("DHKey  ", dhkey, 32);
	print_buf("DHKey A", dhkey_a, 32);
	print_buf("DHKey B", dhkey_b, 32);

	if (memcmp(dhkey_a, dhkey, 32)) {
		printf("DHKey A doesn't match!\n");
		fails++;
	} else {
		printf("DHKey A matches :)\n");
	}

	if (memcmp(dhkey_b, dhkey, 32)) {
		printf("DHKey B doesn't match!\n");
		fails++;
	} else {
		printf("DHKey B matches :)\n");
	}

	return fails;
}
예제 #2
0
int push(struct buf *buf, int val)
{
	unsigned int t_head = buf->head, t_tail = buf->tail;
#ifdef DEBUG
	if (buf->full_fl == true || buf->empt_fl == true) {
		if (t_head != t_tail) {
			del(buf);
			fprintf(stderr, "buffer %p is corrupt\n", buf);
			return FAIL;
		}
	}
	print_buf(buf, "befor push");
#endif
	if (buf->full_fl == true) {
		return FULL;
	}
	if (t_tail == t_head && buf->empt_fl != true) {
		buf->full_fl = true;
		return FULL;
	}
	buf->data[t_head] = val;
	t_head++;
	buf->head = t_head & buf->mask;
	buf->empt_fl = false;
#ifdef DEBUG
	print_buf(buf, "after push");
#endif
	return SUCC;
}
예제 #3
0
/* Buf is assumed to be NIOS_PKT_LEN bytes */
static int nios_access(struct bladerf *dev, uint8_t *buf)
{
    int status;
    void *driver;
    struct bladerf_usb *usb = usb_backend(dev, &driver);

    print_buf("NIOS II request:\n", buf, NIOS_PKT_LEN);

    /* Send the command */
    status = usb->fn->bulk_transfer(driver, PERIPHERAL_EP_OUT,
                                     buf, NIOS_PKT_LEN,
                                     PERIPHERAL_TIMEOUT_MS);
    if (status != 0) {
        log_debug("Failed to send NIOS II request: %s\n",
                  bladerf_strerror(status));
        return status;
    }

    /* Retrieve the request */
    status = usb->fn->bulk_transfer(driver, PERIPHERAL_EP_IN,
                                    buf, NIOS_PKT_LEN,
                                    PERIPHERAL_TIMEOUT_MS);

    if (status != 0) {
        log_debug("Failed to receive NIOS II response: %s\n",
                  bladerf_strerror(status));
    }

    print_buf("NIOS II response:\n", buf, NIOS_PKT_LEN);

    return status;
}
예제 #4
0
int pop(struct buf *buf, int *val)
{
	unsigned int t_head = buf->head, t_tail = buf->tail;
#ifdef DEBUG
	if (buf->full_fl == true || buf->empt_fl == true) {
		if (t_head != t_tail) {
			del(buf);
			fprintf(stderr, "buffer %p is corrupt\n", buf);
			return FAIL;
		}
	}
	print_buf(buf, "befor pop");
#endif
	if (buf->empt_fl == true) {
		return EMPT;
	}
	if (t_tail == t_head && buf->full_fl != true) { /*last value in the buf*/
		buf->empt_fl = true;
		return EMPT;
	}
	*val = buf->data[t_tail];
	buf->data[t_tail] = 0;
	t_tail++;
	buf->tail = t_tail & buf->mask;
	buf->full_fl = false;
#ifdef DEBUG
	print_buf(buf, "after pop");
#endif
	return SUCC;
}
예제 #5
0
void loop() {
    delay(250);
    toggleLED();

    if (isButtonPressed()) {
        if (servo1.attached()) detach();
        else                   attach();
    }

    if (!servo1.attached()) return;

    int32 average = averageAnalogReads(250);
    int16 angle1 = (int16)map(average, 0, 4095, MIN_ANGLE1, MAX_ANGLE1);
    int16 angle2 = (int16)map(average, 0, 4095, MIN_ANGLE2, MAX_ANGLE2);

    print_buf("pot reading = %d, angle 1 = %d, angle 2 = %d.",
              average, angle1, angle2);

    servo1.write(angle1);
    servo2.write(angle2);

    int16 read1 = servo1.read();
    int16 read2 = servo2.read();

    print_buf("write/read angle 1: %d/%d, angle 2: %d/%d",
              angle1, read1, angle2, read2);

    ASSERT(abs(angle1 - read1) <= 1);
    ASSERT(abs(angle2 - read2) <= 1);

    print_buf("pulse width 1: %d, pulse width 2: %d",
              servo1.readMicroseconds(), servo2.readMicroseconds());

     Serial2.println("\n--------------------------\n");
}
예제 #6
0
/* Access device/module via the legacy NIOS II packet format. */
static int nios_access(struct bladerf *dev, uint8_t peripheral,
                       usb_direction dir, struct uart_cmd *cmd,
                       size_t len)
{
    void *driver;
    struct bladerf_usb *usb = usb_backend(dev, &driver);

    int status;
    size_t i;
    uint8_t buf[16] = { 0 };
    const uint8_t pkt_mode_dir = (dir == USB_DIR_HOST_TO_DEVICE) ?
                                 NIOS_PKT_LEGACY_MODE_DIR_WRITE :
                                 NIOS_PKT_LEGACY_MODE_DIR_READ;

    assert(len <= ((sizeof(buf) - 2) / 2));

    /* Populate the buffer for transfer, given address data pairs */
    buf[0] = NIOS_PKT_LEGACY_MAGIC;
    buf[1] = pkt_mode_dir | peripheral | (uint8_t)len;

    for (i = 0; i < len; i++) {
        buf[i * 2 + 2] = cmd[i].addr;
        buf[i * 2 + 3] = cmd[i].data;
    }

    print_buf("NIOS II access request:\n", buf, 16);

    /* Send the command */
    status = usb->fn->bulk_transfer(driver, PERIPHERAL_EP_OUT,
                                     buf, sizeof(buf),
                                     PERIPHERAL_TIMEOUT_MS);
    if (status != 0) {
        log_debug("Failed to submit NIOS II request: %s\n",
                  bladerf_strerror(status));
        return status;
    }

    /* Read back the ACK. The command data is only used for a read operation,
     * and is thrown away otherwise */
    status = usb->fn->bulk_transfer(driver, PERIPHERAL_EP_IN,
                                    buf, sizeof(buf),
                                    PERIPHERAL_TIMEOUT_MS);

    if (dir == NIOS_PKT_LEGACY_MODE_DIR_READ && status == 0) {
        for (i = 0; i < len; i++) {
            cmd[i].data = buf[i * 2 + 3];
        }
    }

    if (status == 0) {
        print_buf("NIOS II access response:\n", buf, 16);
    } else {
        log_debug("Failed to receive NIOS II response: %s\n",
                  bladerf_strerror(status));
    }


    return status;
}
예제 #7
0
void flow(struct lfc *lfc, void *mydata,
	struct lfc_flow *flow, void *flowdata)
{
	struct flowdata *fd = flowdata;

	print_buf(fd->up, fd->ups);
	print_buf(fd->down, fd->downs);
}
예제 #8
0
static void shader_write_scale_dim(config_file_t *conf, const char *dim,
      enum gfx_scale_type type, float scale, unsigned abs, unsigned i)
{
   char key[64];
   print_buf(key, "scale_type_%s%u", dim, i);
   config_set_string(conf, key, scale_type_to_str(type));

   print_buf(key, "scale_%s%u", dim, i);
   if (type == RARCH_SCALE_ABSOLUTE)
      config_set_int(conf, key, abs);
   else
      config_set_float(conf, key, scale);
}
예제 #9
0
파일: spi_test.c 프로젝트: zwzmzd/kl02z
int cmd_spi(int argc, char * const argv[])
{
    struct w25qxx_init_t init;
    uint32_t i, buf_size;
    static uint8_t buf[256];
    struct w25qxx_attr_t w25qxx;
    
    init.delayms = DelayMs;
    init.get_reamin = _get_reamin;
    init.xfer = xfer;
    
    SPI_QuickInit(SPI0_MOSI_PA7_MISO_PA6, kSPI_CPOL1_CPHA1, 100*1000);//配置PTA7为MOSI PTA6为MISO, 波特率为100K,但是实际波特率要根据匹配出来的寄存器值算,有些误差
    GPIO_QuickInit(HW_GPIOA, 5, kGPIO_Mode_OPP); //PTA5 SS
    GPIO_WriteBit(HW_GPIOA, 5, 1);  
    PORT_PinMuxConfig(HW_GPIOB,0,kPinAlt3); //PTB0 SCK
       
    w25qxx_init(&init);   //外部flash初始化
    w25qxx_get_attr(&w25qxx);
    buf_size = sizeof(buf); 
    
    /*读取外部flash256个字节*/
    printf("reading page...\n");
    w25qxx_read(0, buf, buf_size);
    print_buf(buf,PAGE_SIZE);
    /*擦除整个外部flash芯片*/  
    printf("erase all chips...\r\n");
    w25qxx_erase_chip();
    printf("erase complete\r\n");
    /*读取外部flash256个字节*/
    printf("reading page...\n");
    w25qxx_read(0, buf, buf_size);
    print_buf(buf,PAGE_SIZE);
    /*编程外部flash256个字节*/
    printf("programing a page...\n");
    for(i=0;i<256;i++)
        buf[i] = i;
    w25qxx_write(0, buf, buf_size);
     
    printf("clearing buffer..\n");
    for(i=0;i<256;i++)
        buf[i] = 0;
    /*读取外部flash256个字节*/
    printf("reading page...\n");
    w25qxx_read(0, buf, buf_size);
    print_buf(buf,PAGE_SIZE);
    
    printf("demo end.\n");
 

    return 0;
}
예제 #10
0
static bool shader_parse_textures(config_file_t *conf,
      struct gfx_shader *shader)
{
   const char *id;
   char *save;
   char textures[1024];

   if (!config_get_array(conf, "textures", textures, sizeof(textures)))
      return true;

   for (id = strtok_r(textures, ";", &save);
         id && shader->luts < GFX_MAX_TEXTURES;
         shader->luts++, id = strtok_r(NULL, ";", &save))
   {
      if (!config_get_array(conf, id, shader->lut[shader->luts].path,
               sizeof(shader->lut[shader->luts].path)))
      {
         RARCH_ERR("Cannot find path to texture \"%s\" ...\n", id);
         return false;
      }

      strlcpy(shader->lut[shader->luts].id, id,
            sizeof(shader->lut[shader->luts].id));

      char id_filter[64];
      print_buf(id_filter, "%s_linear", id);
      bool smooth = false;
      if (config_get_bool(conf, id_filter, &smooth))
         shader->lut[shader->luts].filter = smooth ? 
            RARCH_FILTER_LINEAR : RARCH_FILTER_NEAREST;
      else
         shader->lut[shader->luts].filter = RARCH_FILTER_UNSPEC;

      char id_wrap[64];
      print_buf(id_wrap, "%s_wrap_mode", id);
      char wrap_mode[64];
      if (config_get_array(conf, id_wrap, wrap_mode, sizeof(wrap_mode)))
         shader->lut[shader->luts].wrap = wrap_str_to_mode(wrap_mode);

      char id_mipmap[64];
      print_buf(id_mipmap, "%s_mipmap", id);
      bool mipmap = false;
      if (config_get_bool(conf, id_mipmap, &mipmap))
         shader->lut[shader->luts].mipmap = mipmap;
      else
         shader->lut[shader->luts].mipmap = false;
   }

   return true;
}
예제 #11
0
static void shader_write_fbo(config_file_t *conf, const struct gfx_fbo_scale *fbo, unsigned i)
{
   char key[64];
   print_buf(key, "float_framebuffer%u", i);
   config_set_bool(conf, key, fbo->fp_fbo);
   print_buf(key, "srgb_framebuffer%u", i);
   config_set_bool(conf, key, fbo->srgb_fbo);

   if (!fbo->valid)
      return;

   shader_write_scale_dim(conf, "x", fbo->type_x, fbo->scale_x, fbo->abs_x, i);
   shader_write_scale_dim(conf, "y", fbo->type_y, fbo->scale_y, fbo->abs_y, i);
}
예제 #12
0
static hg_return_t
snappy_pull_cb(const struct hg_bulk_cb_info *hg_bulk_cb_info)
{
    struct snappy_transfer_args *snappy_transfer_args =
            (struct snappy_transfer_args *) hg_bulk_cb_info->arg;
    hg_return_t ret = HG_SUCCESS;
    void *input;
    size_t input_length;
    size_t source_length = HG_Bulk_get_size(snappy_transfer_args->local_input_bulk_handle);

    /* Get pointer to input buffer from local handle */
    HG_Bulk_access(hg_bulk_cb_info->local_handle, 0, source_length,
            HG_BULK_READ_ONLY, 1, &input, &input_length, NULL);
    printf("Transferred input buffer of length: %zu\n", input_length);
    print_buf(20, (int *) input);

    /* Allocate compressed buffer for compressing input data */
    snappy_transfer_args->compressed_length = snappy_max_compressed_length(input_length);
    snappy_transfer_args->compressed = malloc(snappy_transfer_args->compressed_length);

    /* Compress data */
    printf("Compressing buffer...\n");
    snappy_transfer_args->ret = snappy_compress(input, input_length,
            snappy_transfer_args->compressed, &snappy_transfer_args->compressed_length);
    printf("Return value of snappy_compress is: %d\n", snappy_transfer_args->ret);
    printf("Compressed buffer length is: %zu\n", snappy_transfer_args->compressed_length);
    print_buf(5, (int *) snappy_transfer_args->compressed);

    /* Free bulk handles */
    HG_Bulk_free(snappy_transfer_args->local_input_bulk_handle);

    if (snappy_validate_compressed_buffer(snappy_transfer_args->compressed,
            snappy_transfer_args->compressed_length) == SNAPPY_OK) {
        printf("Compressed buffer validated: compressed successfully\n");
    }

    /* Now set up bulk transfer for "push to origin" callback */
    HG_Bulk_create(HG_Get_info(snappy_transfer_args->handle)->hg_bulk_class, 1,
            &snappy_transfer_args->compressed, &snappy_transfer_args->compressed_length,
            HG_BULK_WRITE_ONLY, &snappy_transfer_args->local_compressed_bulk_handle);

    HG_Bulk_transfer(HG_Get_info(snappy_transfer_args->handle)->bulk_context,
            snappy_push_cb, snappy_transfer_args,
            HG_BULK_PUSH, HG_Get_info(snappy_transfer_args->handle)->addr,
            snappy_transfer_args->snappy_compress_input.compressed_bulk_handle, 0, /* origin */
            snappy_transfer_args->local_compressed_bulk_handle, 0, /* local */
            snappy_transfer_args->compressed_length, HG_OP_ID_IGNORE);

    return ret;
}
예제 #13
0
void deal_packet( char *argc, const struct pcap_pkthdr *pcap_hdr, const char *buf)
{
	uint64_t leng;
	leng = pcap_hdr->len;
	print_buf(buf, leng);	
		
}
예제 #14
0
void task_yield() {
  disable_irq();

  struct task_t *current_task = task_current();
  struct list_node_t *next_task_it;
  struct task_t *next_task;

  if ( task_is_active(current_task) ) {
    next_task_it = current_task_it->next;
  }
  else {
    next_task_it = list_first(active_tasks);
  }

  next_task = (struct task_t *)next_task_it->data;
  task_print("task_yield:", current_task, next_task);
  if ( current_task == next_task ) {
    return;
  };
  if ( next_task == 0 ) {
    print_buf("ERROR: next_task=0\n");
  };

  current_task_it = next_task_it;
  task_switch(&current_task->sp, next_task->sp);
}
예제 #15
0
void talk_notes()
{

	short i,item_hit;
	
	store_num_i = 0;
	for (i = 0; i < 120; i++)
		if (univ.party.talk_save[i].personality != -1)
			store_num_i = i + 1;
	store_page_on = 0;
	if (store_num_i == 0) {
		ASB("Nothing in your talk journal.");
		print_buf();
		return;
		}
	
	make_cursor_sword();

	cd_create_dialog_parent_num(960,0);

	put_talk();
	if (store_num_i == 1) {
		cd_activate_item(960,10,0);
		cd_activate_item(960,11,0);
	}
	
	item_hit = cd_run_dialog();
	cd_kill_dialog(960);

}
예제 #16
0
static void
print_reply_hdr (Call *call, const char *buf, int len)
{
  Call_Private_Data *priv = CALL_PRIVATE_DATA (call);
  const char *eoh;

  if (len <= 0 || priv->done_with_reply_hdr)
    return;

  eoh = strstr (buf, "\r\n\r\n");
  if (eoh)
    {
      priv->done_with_reply_hdr = 1;
      eoh += 4;
    }
  else
    {
      /* no CRLFCRLF: non-conforming server */
      eoh = strstr (buf, "\n\n");
      if (eoh)
	{
	  priv->done_with_reply_hdr = 1;
	  eoh += 2;
	}
      else
	eoh = buf + len;
    }
  print_buf (call, "RH", buf, eoh - buf);
}
예제 #17
0
파일: hexdump.c 프로젝트: matrix207/C
int main(int argc, char **argv)
{
    if (argc < 2) {
        printf("%s %d.%d\n", version, hd_major, hd_miner);
        printf("Usage: %s [file]\n", argv[0]);
        return -1;
    }

    FILE *fp = fopen(argv[1], "r");
    if (!fp) {
        printf("Failed to open file %s.\n", argv[1]);
        return -1;
    }

    fseek(fp, 0, SEEK_END);
    int size = ftell(fp);
    char *buf = (char*)malloc(size);
    if (!buf) {
        printf("Failed to allocate memory.\n");
        return -1;
    }
    fseek(fp, 0, SEEK_SET);
    int rsize = fread(buf, sizeof(char), size, fp);
    if (rsize != size) {
        printf("Reading error.\n");
        return -1;
    }
    print_buf(buf, size);
    free(buf);
    fclose(fp);
        
    return 0;
}
예제 #18
0
static int sipc4_check_header(struct sipc4_rx_data *data, char *buf, int rest)
{
	struct sipc_rx_hdr *hdr = data->rx_hdr;
	int head_size = sipc4_get_header_size(data->format);
	int done_len = 0;
	int len;

	if (!hdr->start) {
		len = sipc4_check_hdlc_start(data, buf);
		if (len < 0)
			return len;
		memcpy(&hdr->start, hdlc_start, sizeof(hdlc_start));
		hdr->len = 0;

		switch (data->format) {
		case SIPC4_FMT:
		/*case SIPC4_RAW:*/
		/*case SIPC4_RFS:*/
			print_buf(buf, 0, NULL);
			break;
		}
		buf += len;
		rest -= len;
		done_len += len;
	}

	if (hdr->len < head_size) {
		len = sipc_min(rest, head_size - hdr->len);
		memcpy(hdr->hdr + hdr->len, buf, len);
		hdr->len += len;
		done_len += len;
	}
	return done_len;
}
예제 #19
0
static void
print_request (Call *call)
{
  size_t hdr_len, h_len, b_len;
  int i, first, end;
  char *hdr;

  first = IE_CONTENT;
  end = IE_CONTENT;

  if ((param.print_request & PRINT_HEADER) != 0)
    first = IE_METHOD;

  if ((param.print_request & PRINT_BODY) != 0)
    end = IE_LEN;

  for (i = first; i < end; ++i)
    {
      hdr = call->req.iov[i].iov_base;
      hdr_len = call->req.iov[i].iov_len;

      if (hdr_len)
	print_buf (call, (i < IE_CONTENT) ? "SH" : "SB", hdr, hdr_len);
    }

  for (h_len = 0, i = IE_METHOD; i < IE_CONTENT; ++i)
    h_len += call->req.iov[i].iov_len;

  for (b_len = 0, i = IE_CONTENT; i < IE_LEN; ++i)
    b_len += call->req.iov[i].iov_len;

  printf ("SS%ld: header %ld content %ld\n",
	  call->id, (long) h_len, (long) b_len);
}
예제 #20
0
  std::list<shared_buffer> length_packer::split(net_buffer &oRecvBuffer) {
    std::list<shared_buffer> resPkgs;
    if (oRecvBuffer.length() <= 4)
      return resPkgs;

    uint32_t len;
    const char *pBuf = asio::buffer_cast<const char *>(oRecvBuffer.readable());
    uint32_t buf_len = oRecvBuffer.length();
    size_t bi = 0;
    deseralize(pBuf + bi, len);

    while (buf_len - bi >= sizeof(len) &&
        buf_len - bi - sizeof(len) >= len) {
      LOG(INFO) << "length_packer::split() buffer is "
        << print_buf(asio::buffer_cast<const char *>(oRecvBuffer.readable()),
            oRecvBuffer.filled());
      LOG(INFO) << "length_packer::split() " << "split pkg with len:" << len;

      bi += sizeof(len);
      shared_buffer sb(pBuf + bi, len);
      resPkgs.push_back(sb);
      bi += len;

      deseralize(pBuf + bi, len);
    }
    oRecvBuffer.read() = bi;
    if(oRecvBuffer.read() == oRecvBuffer.filled())
    {
      oRecvBuffer.read() = 0;
      oRecvBuffer.filled() = 0;
    }
    return resPkgs;
  }
예제 #21
0
파일: window.c 프로젝트: DimondTheCat/xray
static void handle_print( void )
{
   static char outname[ 256 ] = { "out.txt" };
   static char comment[ 256 ] = { "BinView Output" };
   static int range = 0, mode = 0, flags = 7;
   FILE *ofp;
   int rlen, ok;
   long p, plen;


   ok = print_ui( outname, &range, &mode, &flags, comment );
   if ( !ok ) return;
   ofp = fopen( outname, mode ? "a" : "w" );
   if ( !ofp ) return;

   fprintf( ofp, "%s\n", comment );

   p = range ? 0 : pos;
   plen = range ? filesize : pagesize;
   fseek( fp, p, SEEK_SET );
   while ( plen ) {
      rlen = fread( buf, 1, pagesize, fp );
      if ( rlen <= 0 ) break;
      print_buf( buf, rlen, datatype, unsign, byteorder != natorder,
         linesize, p, flags, ofp );
      p += rlen;
      plen -= rlen;
   }
   fclose( ofp );
   fseek( fp, pos, SEEK_SET );
}
예제 #22
0
파일: reset.c 프로젝트: abferm/modemmanager
static qcdmbool
qcdm_send (int fd, char *buf, size_t len)
{
    int status;
    int eagain_count = 1000;
    size_t i = 0;

    if (debug)
        print_buf ("DM:ENC>>>", buf, len);

    while (i < len) {
        errno = 0;
        status = write (fd, &buf[i], 1);
        if (status < 0) {
            if (errno == EAGAIN) {
                eagain_count--;
                if (eagain_count <= 0)
                    return FALSE;
            } else
                assert (errno == 0);
        } else
            i++;

        usleep (1000);
    }

    return TRUE;
}
예제 #23
0
__interrupt void PORT1(void)
{
	if (P1IFG & TASTE_LINKS) {
		BIT_CLR(P1IFG, TASTE_LINKS);
		print_buf("Hallo World\r\n");		
	}
}
예제 #24
0
파일: reset.c 프로젝트: abferm/modemmanager
static size_t
qcdm_wait_reply (int fd, char *buf, size_t len)
{
    fd_set in;
    int result;
    struct timeval timeout = { 1, 0 };
    char readbuf[1024];
    ssize_t bytes_read;
    int total = 0, retries = 0;
    size_t decap_len = 0;

    FD_ZERO (&in);
    FD_SET (fd, &in);
    result = select (fd + 1, &in, NULL, NULL, &timeout);
    if (result != 1 || !FD_ISSET (fd, &in))
        return 0;

    do {
        errno = 0;
        bytes_read = read (fd, &readbuf[total], 1);
        if ((bytes_read == 0) || (errno == EAGAIN)) {
            /* Haven't gotten the async control char yet */
            if (retries > 20)
                return 0; /* 2 seconds, give up */

            /* Otherwise wait a bit and try again */
            usleep (100000);
            retries++;
            continue;
        } else if (bytes_read == 1) {
            qcdmbool more = FALSE;
            qcdmbool success;
            size_t used = 0;

            total++;
            decap_len = 0;
            success = dm_decapsulate_buffer (readbuf, total, buf, len, &decap_len, &used, &more);

            /* Discard used data */
            if (used > 0) {
                total -= used;
                memmove (readbuf, &readbuf[used], total);
            }

            if (success && !more) {
                /* Success; we have a packet */
                break;
            }
        } else {
            /* Some error occurred */
            return 0;
        }
    } while (total < sizeof (readbuf));

    if (debug)
        print_buf ("QCDM:DEC<<", buf, decap_len);

    return decap_len;
}
예제 #25
0
static void et_read_poll_cb(struct libusb_transfer* transfer)
{
 int len;
 char* br;
 int r;
 
 struct poll_data* adata=transfer->user_data;
 struct fpi_img_dev* dev=adata->dev;
 if(transfer->status!=LIBUSB_TRANSFER_COMPLETED)
 {
  /*WORKAROUND NEEDED, SOMETIME ALL FREEZES, RESET DEVICE AND REACTIVATE???*/
  libusb_free_transfer(transfer);
  fp_dbg("ERROR");
  fpi_imgdev_session_error(dev,-EIO);
  //return;
  goto _st;
 }
 len=transfer->actual_length-13;
 if(len!=512)
 {
  fp_dbg("Invalid return buffer, length: %d",transfer->actual_length);
  libusb_free_transfer(transfer);
  fpi_imgdev_session_error(dev,-EPROTO);
  return;
 }
 libusb_free_transfer(transfer);
 //Check poll cmd result
 br=(char*)&ret_buf[len];
 r=et_verify_result(br);
 if(r)
 {
  fp_dbg("Invalid result: %s",print_buf(br));
  fpi_imgdev_session_error(dev,-EPROTO);
  return;
 }
 //fp_dbg("0x%02hhX,0x%02hhX",ret_buf[0],ret_buf[1]);
 if((unsigned char)ret_buf[0]==0x82)
 {
  if(adata->init->rstage<20) 
  {
  /*VERY UGLY workaround below, but I don't know how to deal with it.
  Sometime ret_buf[0] equals 0x82 at the first poll rounds, but
  really no finger on the scanner
  */ 
   fp_dbg("POLL WORKAROUND");
   goto _st;
  }
  //Finger detected
  //fp_dbg("FINGER DETECTED!");
  //fp_dbg("BUF: %s",print_buf(ret_buf));
  fpi_imgdev_report_finger_status(dev,TRUE);
  start_capture(dev);
  return;
 }
 //No finger detected
_st:
 adata->init->rstage++; 
 start_finger_detection(dev,adata);
}
예제 #26
0
static int multipart_body_on_data(multipart_parser* p, const char *at, size_t length)
{

    fprintf(stderr, "multipart_body_on_data:");
    print_buf(at, length);
    return 0;

}
예제 #27
0
static void dump_hex(char *buf, size_t *remain_size, uint8_t *input_buf,
		size_t input_size)
{
	size_t i;

	for (i = 0; i < input_size; i++)
		buf = print_buf(buf, remain_size, "%02X ", input_buf[i]);
}
예제 #28
0
void dummy()
{
	char * buf=(char *) malloc(sizeof(char)*256);
	memset(buf,0,256);
	buf[0]=1;
	buf[1]=0xC0;
	buf[2]='1923';
	print_buf(buf);	
}
예제 #29
0
struct task_t *task_start(task_func_t *task_func) {
  struct task_t *task = (struct task_t *)malloc_alloc(sizeof(struct task_t));
  char *p = malloc_alloc(0x800);
  p += 0x800;
  task->sp = (uint32 *)(p); // 2k stack
  task->msg = 0;
  task->state = TASK_STATE_ACTIVE;
  list_init(&task->input_channels);
  list_init(&task->output_channels);
  task_create(&task->sp, task_func);
  list_add_last(active_tasks, task);
  print_buf("task start:");
  print_buf(" t=");
  print_ptr(task);
  print_buf(" t->sp=");
  print_ptr(task->sp);
  print_buf("\n");
  return task;
}
예제 #30
0
파일: mem.c 프로젝트: andrecurvello/net430
uint16_t mem_write(uint16_t id, uint16_t offset, const void *buf, uint16_t count) {
#if 0
	debug_puts("Writing to ");
	debug_puthex(id+offset);
	debug_nl();
	print_buf(buf, count);
	debug_nl();
#endif
	spi_mem_write(id+offset, buf, count);
	return count;
}