Exemplo n.º 1
0
static int sipc4_hdlc_rx(struct sipc4_rx_data *data)
{
	int rest = data->size;
	char *buf = page_address(data->page);
	int len;
	int err = -ERANGE;

	if (rest <= 0)
		goto end;

	if (data->format == SIPC4_FMT)
		printk(KERN_DEBUG "IPC:RX size=%d\n", data->size);

next_frame:
	err = len = sipc4_check_header(data, buf, rest);
	if (err < 0)
		goto end;
	buf += len;
	rest -= len;
	if (rest <= 0)
		goto end;

	err = len = sipc4_check_data(data, buf, rest);
	if (err < 0)
		goto end;
	buf += len;
	rest -= len;
	if (rest <= 0)
		goto end;

	err = len = sipc4_check_hdlc_end(data, buf);
	if (err < 0)
		goto end;
	buf += len;
	rest -= len;
	if (rest < 0)
		goto end;

	err = sipc4_hdlc_format_rx(data);
	if (err < 0)
		goto end;
	memset(data->rx_hdr, 0x00, sizeof(struct sipc_rx_hdr));

	data->skb = NULL;

	if (rest)
		goto next_frame;

end:
	netdev_free_page(data->dev, data->page);

	if (rest < 0)
		err = -ERANGE;

	if (err < 0 && data->skb) {
		dev_kfree_skb_any(data->skb);
		data->skb = NULL;
	}

	return err;
}
Exemplo n.º 2
0
static int sipc4_hdlc_rx(struct sipc4_rx_data *data)
{
	int rest = data->size;
	char *buf = page_address(data->page);
	int len;
	int err;

	static __be16 protocol;
	int ch;

	char *ptr = buf;
	int size = rest;
	int pos = 0;
	int retrycnt = 0;

	if (rest <= 0)
		goto end;

next_frame:
	err = len = sipc4_check_header(data, buf, rest);
	if (err < 0) {
		_debug_sipc4_print(data, ptr, pos);
		goto end;
	}

	buf += len;
	rest -= len;
	pos += len;

	if (rest == 0)
		goto end;

	if (rest < 0) {
		pr_err("err - r:%d, l:%d, t: %d (%d)\n",
				rest, len, retrycnt, __LINE__);
		_debug_sipc4_print(data, ptr, pos);
		goto end;
	}

	if (data->format == SIPC4_RAW && len != 0) {
		ch = sipc4_get_hdlc_ch(data->skb->data, data->format);
		if (ch >= (CHID_PSD_DATA1) && ch <= CHID_PSD_DATA15) {
			if ((*buf & 0xF0) == 0x60)
				protocol = htons(ETH_P_IPV6);
			else if ((*buf & 0xF0) == 0x40)
				protocol = htons(ETH_P_IP);
			else {
				err = -EINVAL;
				pr_err("err - ip ver\n");
				_debug_sipc4_print(data, ptr, pos);
				goto end;
			}
		}
	}

	err = len = sipc4_check_data(data, buf, rest, protocol);
	if (err < 0) {
		pr_err("err - sipc4 data\n");
		_debug_sipc4_print(data, ptr, pos);
		goto end;
	}
	buf += len;
	rest -= len;
	pos += len;
	if (rest == 0)	/* this packet is splitted */
		goto end;

	if (rest < 0) {
		pr_err("err - r:%d, l:%d, t: %d (%d)\n",
				rest, len, retrycnt, __LINE__);
		_debug_sipc4_print(data, ptr, pos);
		goto end;
	}

	err = len = sipc4_check_hdlc_end(data, buf, size);
	if (err < 0) {
		pr_err("err - r:%d, l:%d, t: %d (%d)\n",
				rest, len, retrycnt, __LINE__);
		_debug_sipc4_print(data, ptr, pos);
		goto end;
	}
	buf += len;
	rest -= len;
	pos += len;
	if (rest < 0) {
		pr_err("err - r:%d, l:%d, t: %d (%d)\n",
				rest, len, retrycnt, __LINE__);
		_debug_sipc4_print(data, ptr, pos);
		goto end;
	}

	err = sipc4_hdlc_format_rx(data, protocol);
	if (err < 0) {
		pr_err("err - hdlc rx\n");
		_debug_sipc4_print(data, ptr, pos);
		goto end;
	}

	data->skb = NULL;

	if (rest) {
		retrycnt++;
		goto next_frame;
	}

end:
	netdev_free_page(data->dev, data->page);

	if (rest < 0)
		err = -ERANGE;

	if (err < 0 && data->skb) {
		dev_kfree_skb_any(data->skb);
		data->skb = NULL;
	}

	return err;
}