/*1* Copyright (C) ST-Ericsson AB 20102* Author: Sjur Brendeland/[email protected]3* License terms: GNU General Public License (GPL) version 24*/56#ifndef CFPKT_H_7#define CFPKT_H_8#include <net/caif/caif_layer.h>9#include <linux/types.h>10struct cfpkt;1112/* Create a CAIF packet.13* len: Length of packet to be created14* @return New packet.15*/16struct cfpkt *cfpkt_create(u16 len);1718/*19* Destroy a CAIF Packet.20* pkt Packet to be destoyed.21*/22void cfpkt_destroy(struct cfpkt *pkt);2324/*25* Extract header from packet.26*27* pkt Packet to extract header data from.28* data Pointer to copy the header data into.29* len Length of head data to copy.30* @return zero on success and error code upon failure31*/32int cfpkt_extr_head(struct cfpkt *pkt, void *data, u16 len);3334/*35* Peek header from packet.36* Reads data from packet without changing packet.37*38* pkt Packet to extract header data from.39* data Pointer to copy the header data into.40* len Length of head data to copy.41* @return zero on success and error code upon failure42*/43int cfpkt_peek_head(struct cfpkt *pkt, void *data, u16 len);4445/*46* Extract header from trailer (end of packet).47*48* pkt Packet to extract header data from.49* data Pointer to copy the trailer data into.50* len Length of header data to copy.51* @return zero on success and error code upon failure52*/53int cfpkt_extr_trail(struct cfpkt *pkt, void *data, u16 len);5455/*56* Add header to packet.57*58*59* pkt Packet to add header data to.60* data Pointer to data to copy into the header.61* len Length of header data to copy.62* @return zero on success and error code upon failure63*/64int cfpkt_add_head(struct cfpkt *pkt, const void *data, u16 len);6566/*67* Add trailer to packet.68*69*70* pkt Packet to add trailer data to.71* data Pointer to data to copy into the trailer.72* len Length of trailer data to copy.73* @return zero on success and error code upon failure74*/75int cfpkt_add_trail(struct cfpkt *pkt, const void *data, u16 len);7677/*78* Pad trailer on packet.79* Moves data pointer in packet, no content copied.80*81* pkt Packet in which to pad trailer.82* len Length of padding to add.83* @return zero on success and error code upon failure84*/85int cfpkt_pad_trail(struct cfpkt *pkt, u16 len);8687/*88* Add a single byte to packet body (tail).89*90* pkt Packet in which to add byte.91* data Byte to add.92* @return zero on success and error code upon failure93*/94int cfpkt_addbdy(struct cfpkt *pkt, const u8 data);9596/*97* Add a data to packet body (tail).98*99* pkt Packet in which to add data.100* data Pointer to data to copy into the packet body.101* len Length of data to add.102* @return zero on success and error code upon failure103*/104int cfpkt_add_body(struct cfpkt *pkt, const void *data, u16 len);105106/*107* Checks whether there are more data to process in packet.108* pkt Packet to check.109* @return true if more data are available in packet false otherwise110*/111bool cfpkt_more(struct cfpkt *pkt);112113/*114* Checks whether the packet is erroneous,115* i.e. if it has been attempted to extract more data than available in packet116* or writing more data than has been allocated in cfpkt_create().117* pkt Packet to check.118* @return true on error false otherwise119*/120bool cfpkt_erroneous(struct cfpkt *pkt);121122/*123* Get the packet length.124* pkt Packet to get length from.125* @return Number of bytes in packet.126*/127u16 cfpkt_getlen(struct cfpkt *pkt);128129/*130* Set the packet length, by adjusting the trailer pointer according to length.131* pkt Packet to set length.132* len Packet length.133* @return Number of bytes in packet.134*/135int cfpkt_setlen(struct cfpkt *pkt, u16 len);136137/*138* cfpkt_append - Appends a packet's data to another packet.139* dstpkt: Packet to append data into, WILL BE FREED BY THIS FUNCTION140* addpkt: Packet to be appended and automatically released,141* WILL BE FREED BY THIS FUNCTION.142* expectlen: Packet's expected total length. This should be considered143* as a hint.144* NB: Input packets will be destroyed after appending and cannot be used145* after calling this function.146* @return The new appended packet.147*/148struct cfpkt *cfpkt_append(struct cfpkt *dstpkt, struct cfpkt *addpkt,149u16 expectlen);150151/*152* cfpkt_split - Split a packet into two packets at the specified split point.153* pkt: Packet to be split (will contain the first part of the data on exit)154* pos: Position to split packet in two parts.155* @return The new packet, containing the second part of the data.156*/157struct cfpkt *cfpkt_split(struct cfpkt *pkt, u16 pos);158159/*160* Iteration function, iterates the packet buffers from start to end.161*162* Checksum iteration function used to iterate buffers163* (we may have packets consisting of a chain of buffers)164* pkt: Packet to calculate checksum for165* iter_func: Function pointer to iteration function166* chks: Checksum calculated so far.167* buf: Pointer to the buffer to checksum168* len: Length of buf.169* data: Initial checksum value.170* @return Checksum of buffer.171*/172173u16 cfpkt_iterate(struct cfpkt *pkt,174u16 (*iter_func)(u16 chks, void *buf, u16 len),175u16 data);176177/* Map from a "native" packet (e.g. Linux Socket Buffer) to a CAIF packet.178* dir - Direction indicating whether this packet is to be sent or received.179* nativepkt - The native packet to be transformed to a CAIF packet180* @return The mapped CAIF Packet CFPKT.181*/182struct cfpkt *cfpkt_fromnative(enum caif_direction dir, void *nativepkt);183184/* Map from a CAIF packet to a "native" packet (e.g. Linux Socket Buffer).185* pkt - The CAIF packet to be transformed into a "native" packet.186* @return The native packet transformed from a CAIF packet.187*/188void *cfpkt_tonative(struct cfpkt *pkt);189190191/*192* Returns packet information for a packet.193* pkt Packet to get info from;194* @return Packet information195*/196struct caif_payload_info *cfpkt_info(struct cfpkt *pkt);197#endif /* CFPKT_H_ */198199200