Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * Copyright (C) ST-Ericsson AB 2010
0004  * Author:  Sjur Brendeland
0005  */
0006 
0007 #ifndef CFPKT_H_
0008 #define CFPKT_H_
0009 #include <net/caif/caif_layer.h>
0010 #include <linux/types.h>
0011 struct cfpkt;
0012 
0013 /* Create a CAIF packet.
0014  * len: Length of packet to be created
0015  * @return New packet.
0016  */
0017 struct cfpkt *cfpkt_create(u16 len);
0018 
0019 /*
0020  * Destroy a CAIF Packet.
0021  * pkt Packet to be destoyed.
0022  */
0023 void cfpkt_destroy(struct cfpkt *pkt);
0024 
0025 /*
0026  * Extract header from packet.
0027  *
0028  * pkt Packet to extract header data from.
0029  * data Pointer to copy the header data into.
0030  * len Length of head data to copy.
0031  * @return zero on success and error code upon failure
0032  */
0033 int cfpkt_extr_head(struct cfpkt *pkt, void *data, u16 len);
0034 
0035 static inline u8 cfpkt_extr_head_u8(struct cfpkt *pkt)
0036 {
0037     u8 tmp;
0038 
0039     cfpkt_extr_head(pkt, &tmp, 1);
0040 
0041     return tmp;
0042 }
0043 
0044 static inline u16 cfpkt_extr_head_u16(struct cfpkt *pkt)
0045 {
0046     __le16 tmp;
0047 
0048     cfpkt_extr_head(pkt, &tmp, 2);
0049 
0050     return le16_to_cpu(tmp);
0051 }
0052 
0053 static inline u32 cfpkt_extr_head_u32(struct cfpkt *pkt)
0054 {
0055     __le32 tmp;
0056 
0057     cfpkt_extr_head(pkt, &tmp, 4);
0058 
0059     return le32_to_cpu(tmp);
0060 }
0061 
0062 /*
0063  * Peek header from packet.
0064  * Reads data from packet without changing packet.
0065  *
0066  * pkt Packet to extract header data from.
0067  * data Pointer to copy the header data into.
0068  * len Length of head data to copy.
0069  * @return zero on success and error code upon failure
0070  */
0071 int cfpkt_peek_head(struct cfpkt *pkt, void *data, u16 len);
0072 
0073 /*
0074  * Extract header from trailer (end of packet).
0075  *
0076  * pkt Packet to extract header data from.
0077  * data Pointer to copy the trailer data into.
0078  * len Length of header data to copy.
0079  * @return zero on success and error code upon failure
0080  */
0081 int cfpkt_extr_trail(struct cfpkt *pkt, void *data, u16 len);
0082 
0083 /*
0084  * Add header to packet.
0085  *
0086  *
0087  * pkt Packet to add header data to.
0088  * data Pointer to data to copy into the header.
0089  * len Length of header data to copy.
0090  * @return zero on success and error code upon failure
0091  */
0092 int cfpkt_add_head(struct cfpkt *pkt, const void *data, u16 len);
0093 
0094 /*
0095  * Add trailer to packet.
0096  *
0097  *
0098  * pkt Packet to add trailer data to.
0099  * data Pointer to data to copy into the trailer.
0100  * len Length of trailer data to copy.
0101  * @return zero on success and error code upon failure
0102  */
0103 int cfpkt_add_trail(struct cfpkt *pkt, const void *data, u16 len);
0104 
0105 /*
0106  * Pad trailer on packet.
0107  * Moves data pointer in packet, no content copied.
0108  *
0109  * pkt Packet in which to pad trailer.
0110  * len Length of padding to add.
0111  * @return zero on success and error code upon failure
0112  */
0113 int cfpkt_pad_trail(struct cfpkt *pkt, u16 len);
0114 
0115 /*
0116  * Add a single byte to packet body (tail).
0117  *
0118  * pkt Packet in which to add byte.
0119  * data Byte to add.
0120  * @return zero on success and error code upon failure
0121  */
0122 int cfpkt_addbdy(struct cfpkt *pkt, const u8 data);
0123 
0124 /*
0125  * Add a data to packet body (tail).
0126  *
0127  * pkt Packet in which to add data.
0128  * data Pointer to data to copy into the packet body.
0129  * len Length of data to add.
0130  * @return zero on success and error code upon failure
0131  */
0132 int cfpkt_add_body(struct cfpkt *pkt, const void *data, u16 len);
0133 
0134 /*
0135  * Checks whether there are more data to process in packet.
0136  * pkt Packet to check.
0137  * @return true if more data are available in packet false otherwise
0138  */
0139 bool cfpkt_more(struct cfpkt *pkt);
0140 
0141 /*
0142  * Checks whether the packet is erroneous,
0143  * i.e. if it has been attempted to extract more data than available in packet
0144  * or writing more data than has been allocated in cfpkt_create().
0145  * pkt Packet to check.
0146  * @return true on error false otherwise
0147  */
0148 bool cfpkt_erroneous(struct cfpkt *pkt);
0149 
0150 /*
0151  * Get the packet length.
0152  * pkt Packet to get length from.
0153  * @return Number of bytes in packet.
0154  */
0155 u16 cfpkt_getlen(struct cfpkt *pkt);
0156 
0157 /*
0158  * Set the packet length, by adjusting the trailer pointer according to length.
0159  * pkt Packet to set length.
0160  * len Packet length.
0161  * @return Number of bytes in packet.
0162  */
0163 int cfpkt_setlen(struct cfpkt *pkt, u16 len);
0164 
0165 /*
0166  * cfpkt_append - Appends a packet's data to another packet.
0167  * dstpkt:    Packet to append data into, WILL BE FREED BY THIS FUNCTION
0168  * addpkt:    Packet to be appended and automatically released,
0169  *            WILL BE FREED BY THIS FUNCTION.
0170  * expectlen: Packet's expected total length. This should be considered
0171  *            as a hint.
0172  * NB: Input packets will be destroyed after appending and cannot be used
0173  * after calling this function.
0174  * @return    The new appended packet.
0175  */
0176 struct cfpkt *cfpkt_append(struct cfpkt *dstpkt, struct cfpkt *addpkt,
0177               u16 expectlen);
0178 
0179 /*
0180  * cfpkt_split - Split a packet into two packets at the specified split point.
0181  * pkt: Packet to be split (will contain the first part of the data on exit)
0182  * pos: Position to split packet in two parts.
0183  * @return The new packet, containing the second part of the data.
0184  */
0185 struct cfpkt *cfpkt_split(struct cfpkt *pkt, u16 pos);
0186 
0187 /*
0188  * Iteration function, iterates the packet buffers from start to end.
0189  *
0190  * Checksum iteration function used to iterate buffers
0191  * (we may have packets consisting of a chain of buffers)
0192  * pkt:       Packet to calculate checksum for
0193  * iter_func: Function pointer to iteration function
0194  * chks:      Checksum calculated so far.
0195  * buf:       Pointer to the buffer to checksum
0196  * len:       Length of buf.
0197  * data:      Initial checksum value.
0198  * @return    Checksum of buffer.
0199  */
0200 
0201 int cfpkt_iterate(struct cfpkt *pkt,
0202         u16 (*iter_func)(u16 chks, void *buf, u16 len),
0203         u16 data);
0204 
0205 /* Map from a "native" packet (e.g. Linux Socket Buffer) to a CAIF packet.
0206  *  dir - Direction indicating whether this packet is to be sent or received.
0207  *  nativepkt  - The native packet to be transformed to a CAIF packet
0208  *  @return The mapped CAIF Packet CFPKT.
0209  */
0210 struct cfpkt *cfpkt_fromnative(enum caif_direction dir, void *nativepkt);
0211 
0212 /* Map from a CAIF packet to a "native" packet (e.g. Linux Socket Buffer).
0213  *  pkt  - The CAIF packet to be transformed into a "native" packet.
0214  *  @return The native packet transformed from a CAIF packet.
0215  */
0216 void *cfpkt_tonative(struct cfpkt *pkt);
0217 
0218 /*
0219  * Returns packet information for a packet.
0220  * pkt Packet to get info from;
0221  * @return Packet information
0222  */
0223 struct caif_payload_info *cfpkt_info(struct cfpkt *pkt);
0224 
0225 /** cfpkt_set_prio - set priority for a CAIF packet.
0226  *
0227  * @pkt: The CAIF packet to be adjusted.
0228  * @prio: one of TC_PRIO_ constants.
0229  */
0230 void cfpkt_set_prio(struct cfpkt *pkt, int prio);
0231 
0232 #endif              /* CFPKT_H_ */