Beispiel #1
0
void uartbuf_putframe(UINT channel, unsigned char *f) {

   UINT i;
   UINT fsize = strlen((char *)f);

   for (i = 0; i < fsize; i++)
      cbuffer_write(&Uart[channel], f[i]);

#ifdef DEBUG

   printf("\r\n\nPutFrame(");
   if (channel == SLAVE_TX)
      printf("Slave TX");
   else if (channel == SLAVE_RX)
      printf("Slave RX");
   else if (channel == SLAVE_HPTX)
      printf("Slave #HP# TX");

   printf(") for PSC: \n\r");
   printf("\tKW = 0x%X \t", frame_getkw(f));
   printf("IDB = 0x%03X \t", frame_getidb(f));
   printf("IDS = 0x%02X \t", frame_getids(f));
   printf("CMD = 0x%X \t", frame_getcmd(f));
   printf("DATA = %s \t", frame_getdata(f));
   printf("CRC = 0x%X \t", frame_getcrc(f));
   printf("fsize = %d\n\r", f->size);

#endif
}
static int
charpipehalf_write( CharDriverState*  cs, const uint8_t*  buf, int  len )
{
    CharPipeHalf*  ph   = cs->opaque;
    CharPipeHalf*  peer = ph->peer;
    BipBuffer*     bip  = ph->bip_last;
    int            ret  = 0;

    D("%s: writing %d bytes to %p: '%s'", __FUNCTION__,
      len, ph, quote_bytes( buf, len ));

    if (bip == NULL && peer != NULL && peer->cs->chr_read != NULL) {
        /* no buffered data, try to write directly to the peer */
        while (len > 0) {
            int  size;

            if (peer->cs->chr_can_read) {
                size = qemu_chr_can_read( peer->cs );
                if (size == 0)
                    break;

                if (size > len)
                    size = len;
            } else
                size = len;

            qemu_chr_read( peer->cs, (uint8_t*)buf, size );
            buf += size;
            len -= size;
            ret += size;
        }
    }

    if (len == 0)
        return ret;

    /* buffer the remaining data */
    if (bip == NULL) {
        bip = bip_buffer_alloc();
        ph->bip_first = ph->bip_last = bip;
    }

    while (len > 0) {
        int  len2 = cbuffer_write( bip->cb, buf, len );

        buf += len2;
        ret += len2;
        len -= len2;
        if (len == 0)
            break;

        /* ok, we need another buffer */
        ph->bip_last = bip_buffer_alloc();
        bip->next = ph->bip_last;
        bip       = ph->bip_last;
    }
    return  ret;
}
static int
charbuffer_write( CharDriverState*  cs, const uint8_t*  buf, int  len )
{
    CharBuffer*       cbuf = cs->opaque;
    CharDriverState*  peer = cbuf->endpoint;
    BipBuffer*        bip  = cbuf->bip_last;
    int               ret  = 0;

    D("%s: writing %d bytes to %p: '%s'", __FUNCTION__,
      len, cbuf, quote_bytes( buf, len ));

    if (bip == NULL && peer != NULL) {
        /* no buffered data, try to write directly to the peer */
        int  size = qemu_chr_write(peer, buf, len);

        if (size < 0)  /* just to be safe */
            size = 0;
        else if (size > len)
            size = len;

        buf += size;
        ret += size;
        len -= size;
    }

    if (len == 0)
        return ret;

    /* buffer the remaining data */
    if (bip == NULL) {
        bip = bip_buffer_alloc();
        cbuf->bip_first = cbuf->bip_last = bip;
    }

    while (len > 0) {
        int  len2 = cbuffer_write( bip->cb, buf, len );

        buf += len2;
        ret += len2;
        len -= len2;
        if (len == 0)
            break;

        /* ok, we need another buffer */
        cbuf->bip_last = bip_buffer_alloc();
        bip->next = cbuf->bip_last;
        bip       = cbuf->bip_last;
    }
    return  ret;
}
Beispiel #4
0
/*
 * Files are queued in a list
 * Add one file to the list
 */
static int file_agent_queue_file(void* ssnptr, void *file_mem)
{
    FileInfo *finfo;
    char *sha256;

    if (cbuffer_is_full(file_list))
    {
        return -1;
    }

    finfo = calloc(1, sizeof (*finfo));

    if (!finfo)
    {
        return -1;
    }

    sha256 = (char *) _dpd.fileAPI->get_sig_sha256(ssnptr);

    if (!sha256)
    {
        free(finfo);
        return -1;
    }

    memcpy(finfo->sha256, sha256, SHA256_HASH_SIZE);
    finfo->file_mem = file_mem;
    finfo->file_size = _dpd.fileAPI->get_file_capture_size(file_mem);

    pthread_mutex_lock(&file_list_mutex);

    if(cbuffer_write(file_list, finfo))
    {
        pthread_mutex_unlock(&file_list_mutex);
        free(finfo);
        return -1;
    }

    pthread_cond_signal(&file_available_cond);
    pthread_mutex_unlock(&file_list_mutex);

    return 0;
}