RT-AC56 3.0.0.4.374.37 core
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / include / net / caif / cfpkt.h
blobfbc681beff528216d70ff03f367a895077a249eb
1 /*
2 * Copyright (C) ST-Ericsson AB 2010
3 * Author: Sjur Brendeland/sjur.brandeland@stericsson.com
4 * License terms: GNU General Public License (GPL) version 2
5 */
7 #ifndef CFPKT_H_
8 #define CFPKT_H_
9 #include <net/caif/caif_layer.h>
10 #include <linux/types.h>
11 struct cfpkt;
13 /* Create a CAIF packet.
14 * len: Length of packet to be created
15 * @return New packet.
17 struct cfpkt *cfpkt_create(u16 len);
19 /* Create a CAIF packet.
20 * data Data to copy.
21 * len Length of packet to be created
22 * @return New packet.
24 struct cfpkt *cfpkt_create_uplink(const unsigned char *data, unsigned int len);
26 * Destroy a CAIF Packet.
27 * pkt Packet to be destoyed.
29 void cfpkt_destroy(struct cfpkt *pkt);
32 * Extract header from packet.
34 * pkt Packet to extract header data from.
35 * data Pointer to copy the header data into.
36 * len Length of head data to copy.
37 * @return zero on success and error code upon failure
39 int cfpkt_extr_head(struct cfpkt *pkt, void *data, u16 len);
42 * Peek header from packet.
43 * Reads data from packet without changing packet.
45 * pkt Packet to extract header data from.
46 * data Pointer to copy the header data into.
47 * len Length of head data to copy.
48 * @return zero on success and error code upon failure
50 int cfpkt_peek_head(struct cfpkt *pkt, void *data, u16 len);
53 * Extract header from trailer (end of packet).
55 * pkt Packet to extract header data from.
56 * data Pointer to copy the trailer data into.
57 * len Length of header data to copy.
58 * @return zero on success and error code upon failure
60 int cfpkt_extr_trail(struct cfpkt *pkt, void *data, u16 len);
63 * Add header to packet.
66 * pkt Packet to add header data to.
67 * data Pointer to data to copy into the header.
68 * len Length of header data to copy.
69 * @return zero on success and error code upon failure
71 int cfpkt_add_head(struct cfpkt *pkt, const void *data, u16 len);
74 * Add trailer to packet.
77 * pkt Packet to add trailer data to.
78 * data Pointer to data to copy into the trailer.
79 * len Length of trailer data to copy.
80 * @return zero on success and error code upon failure
82 int cfpkt_add_trail(struct cfpkt *pkt, const void *data, u16 len);
85 * Pad trailer on packet.
86 * Moves data pointer in packet, no content copied.
88 * pkt Packet in which to pad trailer.
89 * len Length of padding to add.
90 * @return zero on success and error code upon failure
92 int cfpkt_pad_trail(struct cfpkt *pkt, u16 len);
95 * Add a single byte to packet body (tail).
97 * pkt Packet in which to add byte.
98 * data Byte to add.
99 * @return zero on success and error code upon failure
101 int cfpkt_addbdy(struct cfpkt *pkt, const u8 data);
104 * Add a data to packet body (tail).
106 * pkt Packet in which to add data.
107 * data Pointer to data to copy into the packet body.
108 * len Length of data to add.
109 * @return zero on success and error code upon failure
111 int cfpkt_add_body(struct cfpkt *pkt, const void *data, u16 len);
114 * Checks whether there are more data to process in packet.
115 * pkt Packet to check.
116 * @return true if more data are available in packet false otherwise
118 bool cfpkt_more(struct cfpkt *pkt);
121 * Checks whether the packet is erroneous,
122 * i.e. if it has been attempted to extract more data than available in packet
123 * or writing more data than has been allocated in cfpkt_create().
124 * pkt Packet to check.
125 * @return true on error false otherwise
127 bool cfpkt_erroneous(struct cfpkt *pkt);
130 * Get the packet length.
131 * pkt Packet to get length from.
132 * @return Number of bytes in packet.
134 u16 cfpkt_getlen(struct cfpkt *pkt);
137 * Set the packet length, by adjusting the trailer pointer according to length.
138 * pkt Packet to set length.
139 * len Packet length.
140 * @return Number of bytes in packet.
142 int cfpkt_setlen(struct cfpkt *pkt, u16 len);
145 * cfpkt_append - Appends a packet's data to another packet.
146 * dstpkt: Packet to append data into, WILL BE FREED BY THIS FUNCTION
147 * addpkt: Packet to be appended and automatically released,
148 * WILL BE FREED BY THIS FUNCTION.
149 * expectlen: Packet's expected total length. This should be considered
150 * as a hint.
151 * NB: Input packets will be destroyed after appending and cannot be used
152 * after calling this function.
153 * @return The new appended packet.
155 struct cfpkt *cfpkt_append(struct cfpkt *dstpkt, struct cfpkt *addpkt,
156 u16 expectlen);
159 * cfpkt_split - Split a packet into two packets at the specified split point.
160 * pkt: Packet to be split (will contain the first part of the data on exit)
161 * pos: Position to split packet in two parts.
162 * @return The new packet, containing the second part of the data.
164 struct cfpkt *cfpkt_split(struct cfpkt *pkt, u16 pos);
167 * Iteration function, iterates the packet buffers from start to end.
169 * Checksum iteration function used to iterate buffers
170 * (we may have packets consisting of a chain of buffers)
171 * pkt: Packet to calculate checksum for
172 * iter_func: Function pointer to iteration function
173 * chks: Checksum calculated so far.
174 * buf: Pointer to the buffer to checksum
175 * len: Length of buf.
176 * data: Initial checksum value.
177 * @return Checksum of buffer.
180 u16 cfpkt_iterate(struct cfpkt *pkt,
181 u16 (*iter_func)(u16 chks, void *buf, u16 len),
182 u16 data);
184 /* Append by giving user access to packet buffer
185 * cfpkt Packet to append to
186 * buf Buffer inside pkt that user shall copy data into
187 * buflen Length of buffer and number of bytes added to packet
188 * @return 0 on error, 1 on success
190 int cfpkt_raw_append(struct cfpkt *cfpkt, void **buf, unsigned int buflen);
192 /* Extract by giving user access to packet buffer
193 * cfpkt Packet to extract from
194 * buf Buffer inside pkt that user shall copy data from
195 * buflen Length of buffer and number of bytes removed from packet
196 * @return 0 on error, 1 on success
198 int cfpkt_raw_extract(struct cfpkt *cfpkt, void **buf, unsigned int buflen);
200 /* Map from a "native" packet (e.g. Linux Socket Buffer) to a CAIF packet.
201 * dir - Direction indicating whether this packet is to be sent or received.
202 * nativepkt - The native packet to be transformed to a CAIF packet
203 * @return The mapped CAIF Packet CFPKT.
205 struct cfpkt *cfpkt_fromnative(enum caif_direction dir, void *nativepkt);
207 /* Map from a CAIF packet to a "native" packet (e.g. Linux Socket Buffer).
208 * pkt - The CAIF packet to be transformed into a "native" packet.
209 * @return The native packet transformed from a CAIF packet.
211 void *cfpkt_tonative(struct cfpkt *pkt);
214 * Insert a packet in the packet queue.
215 * pktq Packet queue to insert into
216 * pkt Packet to be inserted in queue
217 * prio Priority of packet
219 void cfpkt_queue(struct cfpktq *pktq, struct cfpkt *pkt,
220 unsigned short prio);
223 * Remove a packet from the packet queue.
224 * pktq Packet queue to fetch packets from.
225 * @return Dequeued packet.
227 struct cfpkt *cfpkt_dequeue(struct cfpktq *pktq);
230 * Peek into a packet from the packet queue.
231 * pktq Packet queue to fetch packets from.
232 * @return Peeked packet.
234 struct cfpkt *cfpkt_qpeek(struct cfpktq *pktq);
237 * Initiates the packet queue.
238 * @return Pointer to new packet queue.
240 struct cfpktq *cfpktq_create(void);
243 * Get the number of packets in the queue.
244 * pktq Packet queue to fetch count from.
245 * @return Number of packets in queue.
247 int cfpkt_qcount(struct cfpktq *pktq);
250 * Put content of packet into buffer for debuging purposes.
251 * pkt Packet to copy data from
252 * buf Buffer to copy data into
253 * buflen Length of data to copy
254 * @return Pointer to copied data
256 char *cfpkt_log_pkt(struct cfpkt *pkt, char *buf, int buflen);
259 * Clones a packet and releases the original packet.
260 * This is used for taking ownership of a packet e.g queueing.
261 * pkt Packet to clone and release.
262 * @return Cloned packet.
264 struct cfpkt *cfpkt_clone_release(struct cfpkt *pkt);
268 * Returns packet information for a packet.
269 * pkt Packet to get info from;
270 * @return Packet information
272 struct caif_payload_info *cfpkt_info(struct cfpkt *pkt);
273 /*! @} */
274 #endif /* CFPKT_H_ */