Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0cc9f2c2 authored by Arun Kumar Neelakantam's avatar Arun Kumar Neelakantam Committed by Chris Lew
Browse files

net: qrtr: Add support to read qrtr packet size



Some transports need to know qrtr packet to read complete packet
from underlying transport.

Add API support to get the incoming packet size form qrtr header.

Change-Id: I4e4e4ab2e4c1fe0e1e1261af85a8b8618ce65bb3
Signed-off-by: default avatarArun Kumar Neelakantam <aneela@codeaurora.org>
parent 7c4b317c
Loading
Loading
Loading
Loading
+42 −0
Original line number Diff line number Diff line
@@ -536,6 +536,48 @@ static void qrtr_node_assign(struct qrtr_node *node, unsigned int nid)
	spin_unlock_irqrestore(&qrtr_nodes_lock, flags);
}

/**
 * qrtr_peek_pkt_size() - Peek into the packet header to get potential pkt size
 *
 * @data: Starting address of the packet which points to router header.
 *
 * @returns: potential packet size on success, < 0 on error.
 *
 * This function is used by the underlying transport abstraction layer to
 * peek into the potential packet size of an incoming packet. This information
 * is used to perform link layer fragmentation and re-assembly
 */
int qrtr_peek_pkt_size(const void *data)
{
	const struct qrtr_hdr_v1 *v1;
	const struct qrtr_hdr_v2 *v2;
	unsigned int hdrlen;
	unsigned int size;
	unsigned int ver;

	/* Version field in v1 is little endian, so this works for both cases */
	ver = *(u8 *)data;

	switch (ver) {
	case QRTR_PROTO_VER_1:
		v1 = data;
		hdrlen = sizeof(*v1);
		size = le32_to_cpu(v1->size);
		break;
	case QRTR_PROTO_VER_2:
		v2 = data;
		hdrlen = sizeof(*v2) + v2->optlen;
		size = le32_to_cpu(v2->size);
		break;
	default:
		pr_err("qrtr: Invalid version %d\n", ver);
		return -EINVAL;
	}

	return ALIGN(size, 4) + hdrlen;
}
EXPORT_SYMBOL(qrtr_peek_pkt_size);

/**
 * qrtr_endpoint_post() - post incoming data
 * @ep: endpoint handle
+1 −0
Original line number Diff line number Diff line
@@ -32,4 +32,5 @@ void qrtr_endpoint_unregister(struct qrtr_endpoint *ep);

int qrtr_endpoint_post(struct qrtr_endpoint *ep, const void *data, size_t len);

int qrtr_peek_pkt_size(const void *data);
#endif