/* gather IR data from incoming urb, process it when we have enough */
static int redrat3_get_ir_data(struct redrat3_dev *rr3, unsigned len)
{
    struct device *dev = rr3->dev;
    unsigned pkttype;
    int ret = 0;

    rr3_ftr(dev, "Entering %s\n", __func__);

    if (rr3->bytes_read == 0 && len >= sizeof(struct redrat3_header)) {
        redrat3_read_packet_start(rr3, len);
    } else if (rr3->bytes_read != 0) {
        redrat3_read_packet_continue(rr3, len);
    } else if (rr3->bytes_read == 0) {
        dev_err(dev, "error: no packet data read\n");
        ret = -ENODATA;
        goto out;
    }

    if (rr3->bytes_read < be16_to_cpu(rr3->irdata.header.length) +
            sizeof(struct redrat3_header))
        /* we're still accumulating data */
        return 0;

    /* if we get here, we've got IR data to decode */
    pkttype = be16_to_cpu(rr3->irdata.header.transfer_type);
    if (pkttype == RR3_MOD_SIGNAL_IN)
        redrat3_process_ir_data(rr3);
    else
        rr3_dbg(dev, "discarding non-signal data packet (type 0x%02x)\n",
                pkttype);

out:
    rr3->bytes_read = 0;
    return ret;
}
Пример #2
0
static int redrat3_get_ir_data(struct redrat3_dev *rr3, int len)
{
	struct device *dev = rr3->dev;
	int ret = 0;

	rr3_ftr(dev, "Entering %s\n", __func__);

	if (rr3->pktlen > RR3_MAX_BUF_SIZE) {
		dev_err(rr3->dev, "error: packet larger than buffer\n");
		ret = -EINVAL;
		goto out;
	}

	if ((rr3->bytes_read == 0) &&
	    (len >= (sizeof(rr3->pkttype) + sizeof(rr3->pktlen)))) {
		redrat3_read_packet_start(rr3, len);
	} else if (rr3->bytes_read != 0) {
		redrat3_read_packet_continue(rr3, len);
	} else if (rr3->bytes_read == 0) {
		dev_err(dev, "error: no packet data read\n");
		ret = -ENODATA;
		goto out;
	}

	if (rr3->bytes_read > rr3->pktlen) {
		dev_err(dev, "bytes_read (%d) greater than pktlen (%d)\n",
			rr3->bytes_read, rr3->pktlen);
		ret = -EINVAL;
		goto out;
	} else if (rr3->bytes_read < rr3->pktlen)
		/*                               */
		return 0;

	/*                                             */
	if (rr3->pkttype == RR3_MOD_SIGNAL_IN)
		redrat3_process_ir_data(rr3);
	else
		rr3_dbg(dev, "discarding non-signal data packet "
			"(type 0x%02x)\n", rr3->pkttype);

out:
	rr3->bytes_read = 0;
	rr3->pktlen = 0;
	rr3->pkttype = 0;
	return ret;
}