1 /* SPDX-License-Identifier: GPL-2.0-only */ 1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 /* 2 /* 3 * Copyright (C) ST-Ericsson AB 2010 3 * Copyright (C) ST-Ericsson AB 2010 4 * Author: Sjur Brendeland 4 * Author: Sjur Brendeland 5 */ 5 */ 6 6 7 #ifndef CFPKT_H_ 7 #ifndef CFPKT_H_ 8 #define CFPKT_H_ 8 #define CFPKT_H_ 9 #include <net/caif/caif_layer.h> 9 #include <net/caif/caif_layer.h> 10 #include <linux/types.h> 10 #include <linux/types.h> 11 struct cfpkt; 11 struct cfpkt; 12 12 13 /* Create a CAIF packet. 13 /* Create a CAIF packet. 14 * len: Length of packet to be created 14 * len: Length of packet to be created 15 * @return New packet. 15 * @return New packet. 16 */ 16 */ 17 struct cfpkt *cfpkt_create(u16 len); 17 struct cfpkt *cfpkt_create(u16 len); 18 18 19 /* 19 /* 20 * Destroy a CAIF Packet. 20 * Destroy a CAIF Packet. 21 * pkt Packet to be destroyed. !! 21 * pkt Packet to be destoyed. 22 */ 22 */ 23 void cfpkt_destroy(struct cfpkt *pkt); 23 void cfpkt_destroy(struct cfpkt *pkt); 24 24 25 /* 25 /* 26 * Extract header from packet. 26 * Extract header from packet. 27 * 27 * 28 * pkt Packet to extract header data from. 28 * pkt Packet to extract header data from. 29 * data Pointer to copy the header data into. 29 * data Pointer to copy the header data into. 30 * len Length of head data to copy. 30 * len Length of head data to copy. 31 * @return zero on success and error code upon 31 * @return zero on success and error code upon failure 32 */ 32 */ 33 int cfpkt_extr_head(struct cfpkt *pkt, void *d 33 int cfpkt_extr_head(struct cfpkt *pkt, void *data, u16 len); 34 34 35 static inline u8 cfpkt_extr_head_u8(struct cfp 35 static inline u8 cfpkt_extr_head_u8(struct cfpkt *pkt) 36 { 36 { 37 u8 tmp; 37 u8 tmp; 38 38 39 cfpkt_extr_head(pkt, &tmp, 1); 39 cfpkt_extr_head(pkt, &tmp, 1); 40 40 41 return tmp; 41 return tmp; 42 } 42 } 43 43 44 static inline u16 cfpkt_extr_head_u16(struct c 44 static inline u16 cfpkt_extr_head_u16(struct cfpkt *pkt) 45 { 45 { 46 __le16 tmp; 46 __le16 tmp; 47 47 48 cfpkt_extr_head(pkt, &tmp, 2); 48 cfpkt_extr_head(pkt, &tmp, 2); 49 49 50 return le16_to_cpu(tmp); 50 return le16_to_cpu(tmp); 51 } 51 } 52 52 53 static inline u32 cfpkt_extr_head_u32(struct c 53 static inline u32 cfpkt_extr_head_u32(struct cfpkt *pkt) 54 { 54 { 55 __le32 tmp; 55 __le32 tmp; 56 56 57 cfpkt_extr_head(pkt, &tmp, 4); 57 cfpkt_extr_head(pkt, &tmp, 4); 58 58 59 return le32_to_cpu(tmp); 59 return le32_to_cpu(tmp); 60 } 60 } 61 61 62 /* 62 /* 63 * Peek header from packet. 63 * Peek header from packet. 64 * Reads data from packet without changing pac 64 * Reads data from packet without changing packet. 65 * 65 * 66 * pkt Packet to extract header data from. 66 * pkt Packet to extract header data from. 67 * data Pointer to copy the header data into. 67 * data Pointer to copy the header data into. 68 * len Length of head data to copy. 68 * len Length of head data to copy. 69 * @return zero on success and error code upon 69 * @return zero on success and error code upon failure 70 */ 70 */ 71 int cfpkt_peek_head(struct cfpkt *pkt, void *d 71 int cfpkt_peek_head(struct cfpkt *pkt, void *data, u16 len); 72 72 73 /* 73 /* 74 * Extract header from trailer (end of packet) 74 * Extract header from trailer (end of packet). 75 * 75 * 76 * pkt Packet to extract header data from. 76 * pkt Packet to extract header data from. 77 * data Pointer to copy the trailer data into. 77 * data Pointer to copy the trailer data into. 78 * len Length of header data to copy. 78 * len Length of header data to copy. 79 * @return zero on success and error code upon 79 * @return zero on success and error code upon failure 80 */ 80 */ 81 int cfpkt_extr_trail(struct cfpkt *pkt, void * 81 int cfpkt_extr_trail(struct cfpkt *pkt, void *data, u16 len); 82 82 83 /* 83 /* 84 * Add header to packet. 84 * Add header to packet. 85 * 85 * 86 * 86 * 87 * pkt Packet to add header data to. 87 * pkt Packet to add header data to. 88 * data Pointer to data to copy into the heade 88 * data Pointer to data to copy into the header. 89 * len Length of header data to copy. 89 * len Length of header data to copy. 90 * @return zero on success and error code upon 90 * @return zero on success and error code upon failure 91 */ 91 */ 92 int cfpkt_add_head(struct cfpkt *pkt, const vo 92 int cfpkt_add_head(struct cfpkt *pkt, const void *data, u16 len); 93 93 94 /* 94 /* 95 * Add trailer to packet. 95 * Add trailer to packet. 96 * 96 * 97 * 97 * 98 * pkt Packet to add trailer data to. 98 * pkt Packet to add trailer data to. 99 * data Pointer to data to copy into the trail 99 * data Pointer to data to copy into the trailer. 100 * len Length of trailer data to copy. 100 * len Length of trailer data to copy. 101 * @return zero on success and error code upon 101 * @return zero on success and error code upon failure 102 */ 102 */ 103 int cfpkt_add_trail(struct cfpkt *pkt, const v 103 int cfpkt_add_trail(struct cfpkt *pkt, const void *data, u16 len); 104 104 105 /* 105 /* 106 * Pad trailer on packet. 106 * Pad trailer on packet. 107 * Moves data pointer in packet, no content co 107 * Moves data pointer in packet, no content copied. 108 * 108 * 109 * pkt Packet in which to pad trailer. 109 * pkt Packet in which to pad trailer. 110 * len Length of padding to add. 110 * len Length of padding to add. 111 * @return zero on success and error code upon 111 * @return zero on success and error code upon failure 112 */ 112 */ 113 int cfpkt_pad_trail(struct cfpkt *pkt, u16 len 113 int cfpkt_pad_trail(struct cfpkt *pkt, u16 len); 114 114 115 /* 115 /* 116 * Add a single byte to packet body (tail). 116 * Add a single byte to packet body (tail). 117 * 117 * 118 * pkt Packet in which to add byte. 118 * pkt Packet in which to add byte. 119 * data Byte to add. 119 * data Byte to add. 120 * @return zero on success and error code upon 120 * @return zero on success and error code upon failure 121 */ 121 */ 122 int cfpkt_addbdy(struct cfpkt *pkt, const u8 d 122 int cfpkt_addbdy(struct cfpkt *pkt, const u8 data); 123 123 124 /* 124 /* 125 * Add a data to packet body (tail). 125 * Add a data to packet body (tail). 126 * 126 * 127 * pkt Packet in which to add data. 127 * pkt Packet in which to add data. 128 * data Pointer to data to copy into the packe 128 * data Pointer to data to copy into the packet body. 129 * len Length of data to add. 129 * len Length of data to add. 130 * @return zero on success and error code upon 130 * @return zero on success and error code upon failure 131 */ 131 */ 132 int cfpkt_add_body(struct cfpkt *pkt, const vo 132 int cfpkt_add_body(struct cfpkt *pkt, const void *data, u16 len); 133 133 134 /* 134 /* 135 * Checks whether there are more data to proce 135 * Checks whether there are more data to process in packet. 136 * pkt Packet to check. 136 * pkt Packet to check. 137 * @return true if more data are available in 137 * @return true if more data are available in packet false otherwise 138 */ 138 */ 139 bool cfpkt_more(struct cfpkt *pkt); 139 bool cfpkt_more(struct cfpkt *pkt); 140 140 141 /* 141 /* 142 * Checks whether the packet is erroneous, 142 * Checks whether the packet is erroneous, 143 * i.e. if it has been attempted to extract mo 143 * i.e. if it has been attempted to extract more data than available in packet 144 * or writing more data than has been allocate 144 * or writing more data than has been allocated in cfpkt_create(). 145 * pkt Packet to check. 145 * pkt Packet to check. 146 * @return true on error false otherwise 146 * @return true on error false otherwise 147 */ 147 */ 148 bool cfpkt_erroneous(struct cfpkt *pkt); 148 bool cfpkt_erroneous(struct cfpkt *pkt); 149 149 150 /* 150 /* 151 * Get the packet length. 151 * Get the packet length. 152 * pkt Packet to get length from. 152 * pkt Packet to get length from. 153 * @return Number of bytes in packet. 153 * @return Number of bytes in packet. 154 */ 154 */ 155 u16 cfpkt_getlen(struct cfpkt *pkt); 155 u16 cfpkt_getlen(struct cfpkt *pkt); 156 156 157 /* 157 /* 158 * Set the packet length, by adjusting the tra 158 * Set the packet length, by adjusting the trailer pointer according to length. 159 * pkt Packet to set length. 159 * pkt Packet to set length. 160 * len Packet length. 160 * len Packet length. 161 * @return Number of bytes in packet. 161 * @return Number of bytes in packet. 162 */ 162 */ 163 int cfpkt_setlen(struct cfpkt *pkt, u16 len); 163 int cfpkt_setlen(struct cfpkt *pkt, u16 len); 164 164 165 /* 165 /* 166 * cfpkt_append - Appends a packet's data to a 166 * cfpkt_append - Appends a packet's data to another packet. 167 * dstpkt: Packet to append data into, WILL 167 * dstpkt: Packet to append data into, WILL BE FREED BY THIS FUNCTION 168 * addpkt: Packet to be appended and automa 168 * addpkt: Packet to be appended and automatically released, 169 * WILL BE FREED BY THIS FUNCTION. 169 * WILL BE FREED BY THIS FUNCTION. 170 * expectlen: Packet's expected total length. 170 * expectlen: Packet's expected total length. This should be considered 171 * as a hint. 171 * as a hint. 172 * NB: Input packets will be destroyed after a 172 * NB: Input packets will be destroyed after appending and cannot be used 173 * after calling this function. 173 * after calling this function. 174 * @return The new appended packet. 174 * @return The new appended packet. 175 */ 175 */ 176 struct cfpkt *cfpkt_append(struct cfpkt *dstpk 176 struct cfpkt *cfpkt_append(struct cfpkt *dstpkt, struct cfpkt *addpkt, 177 u16 expectlen); 177 u16 expectlen); 178 178 179 /* 179 /* 180 * cfpkt_split - Split a packet into two packe 180 * cfpkt_split - Split a packet into two packets at the specified split point. 181 * pkt: Packet to be split (will contain the f 181 * pkt: Packet to be split (will contain the first part of the data on exit) 182 * pos: Position to split packet in two parts. 182 * pos: Position to split packet in two parts. 183 * @return The new packet, containing the seco 183 * @return The new packet, containing the second part of the data. 184 */ 184 */ 185 struct cfpkt *cfpkt_split(struct cfpkt *pkt, u 185 struct cfpkt *cfpkt_split(struct cfpkt *pkt, u16 pos); 186 186 187 /* 187 /* 188 * Iteration function, iterates the packet buf 188 * Iteration function, iterates the packet buffers from start to end. 189 * 189 * 190 * Checksum iteration function used to iterate 190 * Checksum iteration function used to iterate buffers 191 * (we may have packets consisting of a chain 191 * (we may have packets consisting of a chain of buffers) 192 * pkt: Packet to calculate checksum for 192 * pkt: Packet to calculate checksum for 193 * iter_func: Function pointer to iteration fu 193 * iter_func: Function pointer to iteration function 194 * chks: Checksum calculated so far. 194 * chks: Checksum calculated so far. 195 * buf: Pointer to the buffer to checksu 195 * buf: Pointer to the buffer to checksum 196 * len: Length of buf. 196 * len: Length of buf. 197 * data: Initial checksum value. 197 * data: Initial checksum value. 198 * @return Checksum of buffer. 198 * @return Checksum of buffer. 199 */ 199 */ 200 200 201 int cfpkt_iterate(struct cfpkt *pkt, 201 int cfpkt_iterate(struct cfpkt *pkt, 202 u16 (*iter_func)(u16 chks, voi 202 u16 (*iter_func)(u16 chks, void *buf, u16 len), 203 u16 data); 203 u16 data); 204 204 205 /* Map from a "native" packet (e.g. Linux Sock 205 /* Map from a "native" packet (e.g. Linux Socket Buffer) to a CAIF packet. 206 * dir - Direction indicating whether this pa 206 * dir - Direction indicating whether this packet is to be sent or received. 207 * nativepkt - The native packet to be trans 207 * nativepkt - The native packet to be transformed to a CAIF packet 208 * @return The mapped CAIF Packet CFPKT. 208 * @return The mapped CAIF Packet CFPKT. 209 */ 209 */ 210 struct cfpkt *cfpkt_fromnative(enum caif_direc 210 struct cfpkt *cfpkt_fromnative(enum caif_direction dir, void *nativepkt); 211 211 212 /* Map from a CAIF packet to a "native" packet 212 /* Map from a CAIF packet to a "native" packet (e.g. Linux Socket Buffer). 213 * pkt - The CAIF packet to be transformed i 213 * pkt - The CAIF packet to be transformed into a "native" packet. 214 * @return The native packet transformed from 214 * @return The native packet transformed from a CAIF packet. 215 */ 215 */ 216 void *cfpkt_tonative(struct cfpkt *pkt); 216 void *cfpkt_tonative(struct cfpkt *pkt); 217 217 218 /* 218 /* 219 * Returns packet information for a packet. 219 * Returns packet information for a packet. 220 * pkt Packet to get info from; 220 * pkt Packet to get info from; 221 * @return Packet information 221 * @return Packet information 222 */ 222 */ 223 struct caif_payload_info *cfpkt_info(struct cf 223 struct caif_payload_info *cfpkt_info(struct cfpkt *pkt); 224 224 225 /** cfpkt_set_prio - set priority for a CAIF p 225 /** cfpkt_set_prio - set priority for a CAIF packet. 226 * 226 * 227 * @pkt: The CAIF packet to be adjusted. 227 * @pkt: The CAIF packet to be adjusted. 228 * @prio: one of TC_PRIO_ constants. 228 * @prio: one of TC_PRIO_ constants. 229 */ 229 */ 230 void cfpkt_set_prio(struct cfpkt *pkt, int pri 230 void cfpkt_set_prio(struct cfpkt *pkt, int prio); 231 231 232 #endif /* CFPKT_H_ */ 232 #endif /* CFPKT_H_ */ 233 233
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.