예제 #1
0
파일: gathdlc.c 프로젝트: yongsu/oFono
static void new_bytes(struct ring_buffer *rbuf, gpointer user_data)
{
	GAtHDLC *hdlc = user_data;
	unsigned int len = ring_buffer_len(rbuf);
	unsigned int wrap = ring_buffer_len_no_wrap(rbuf);
	unsigned char *buf = ring_buffer_read_ptr(rbuf, 0);
	unsigned int pos = 0;

	hdlc_record(hdlc->record_fd, TRUE, buf, wrap);

	hdlc->in_read_handler = TRUE;

	while (pos < len) {
		if (hdlc->decode_escape == TRUE) {
			unsigned char val = *buf ^ HDLC_TRANS;

			hdlc->decode_buffer[hdlc->decode_offset++] = val;
			hdlc->decode_fcs = HDLC_FCS(hdlc->decode_fcs, val);

			hdlc->decode_escape = FALSE;
		} else if (*buf == HDLC_ESCAPE) {
			hdlc->decode_escape = TRUE;
		} else if (*buf == HDLC_FLAG) {
			if (hdlc->receive_func && hdlc->decode_offset > 2 &&
					hdlc->decode_fcs == HDLC_GOODFCS) {
				hdlc->receive_func(hdlc->decode_buffer,
							hdlc->decode_offset - 2,
							hdlc->receive_data);

				if (hdlc->destroyed)
					goto out;
			}

			hdlc->decode_fcs = HDLC_INITFCS;
			hdlc->decode_offset = 0;
		} else if (*buf >= 0x20 ||
					(hdlc->recv_accm & (1 << *buf)) == 0) {
			hdlc->decode_buffer[hdlc->decode_offset++] = *buf;
			hdlc->decode_fcs = HDLC_FCS(hdlc->decode_fcs, *buf);
		}

		buf++;
		pos++;

		if (pos == wrap) {
			buf = ring_buffer_read_ptr(rbuf, pos);
			hdlc_record(hdlc->record_fd, TRUE, buf, len - wrap);
		}
	}

	ring_buffer_drain(rbuf, pos);

out:
	hdlc->in_read_handler = FALSE;

	if (hdlc->destroyed)
		g_free(hdlc);
}
예제 #2
0
파일: grilio.c 프로젝트: saukko/ofono
gboolean g_ril_io_set_read_handler(GRilIO *io, GRilIOReadFunc read_handler,
					gpointer user_data)
{
	if (io == NULL)
		return FALSE;

	io->read_handler = read_handler;
	io->read_data = user_data;

	if (read_handler && ring_buffer_len(io->buf) > 0)
		read_handler(io->buf, user_data);

	return TRUE;
}
예제 #3
0
파일: gathdlc.c 프로젝트: yongsu/oFono
static gboolean can_write_data(gpointer data)
{
	GAtHDLC *hdlc = data;
	unsigned int len;
	unsigned char *buf;
	gsize bytes_written;

	len = ring_buffer_len_no_wrap(hdlc->write_buffer);
	buf = ring_buffer_read_ptr(hdlc->write_buffer, 0);

	bytes_written = g_at_io_write(hdlc->io, (gchar *) buf, len);
	hdlc_record(hdlc->record_fd, FALSE, buf, bytes_written);
	ring_buffer_drain(hdlc->write_buffer, bytes_written);

	if (ring_buffer_len(hdlc->write_buffer) > 0)
		return TRUE;

	return FALSE;
}
예제 #4
0
파일: gatrawip.c 프로젝트: AndriusA/ofono
static gboolean tun_write_data(gpointer data)
{
	GAtRawIP *rawip = data;
	unsigned int len;
	unsigned char *buf;
	gsize bytes_written;

	if (rawip->tun_write_buffer == NULL)
		return FALSE;

	len = ring_buffer_len_no_wrap(rawip->tun_write_buffer);
	buf = ring_buffer_read_ptr(rawip->tun_write_buffer, 0);

	bytes_written = g_at_io_write(rawip->tun_io, (gchar *) buf, len);
	ring_buffer_drain(rawip->tun_write_buffer, bytes_written);

	if (ring_buffer_len(rawip->tun_write_buffer) > 0)
		return TRUE;

	rawip->tun_write_buffer = NULL;

	return FALSE;
}
예제 #5
0
파일: OSAL_RingBuf.c 프로젝트: saiyn/OSAL
size_t ring_buffer_peek_read(ringbuf_device_t index, uint8 *buf, size_t len)
{
	ring_buffer_t *p;
	uint8 read;
	uint8 size;
	uint8 j;
	uint8 l;
	
	OSAL_ASSERT(buf != NULL);
	OSAL_ASSERT(index < DEVICE_NUM);
	
	p = ring_list[index];
	read = p->read;
	size =  ring_buffer_len(index);
	
	l = ((len >= size) ? size : len);
	
	for(j = 0; j < l; j++){
		*buf++ = p->buffer[read];
		read = (read + 1) % RING_BUF_SIZE;
	}
	
	return l;
}