Loading...
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * Copyright (C) ST-Ericsson AB 2010
4 * Author: Sjur Brendeland
5 */
6
7#define pr_fmt(fmt) KBUILD_MODNAME ":%s(): " fmt, __func__
8
9#include <linux/string.h>
10#include <linux/skbuff.h>
11#include <linux/export.h>
12#include <net/caif/cfpkt.h>
13
14#define PKT_PREFIX 48
15#define PKT_POSTFIX 2
16#define PKT_LEN_WHEN_EXTENDING 128
17#define PKT_ERROR(pkt, errmsg) \
18do { \
19 cfpkt_priv(pkt)->erronous = true; \
20 skb_reset_tail_pointer(&pkt->skb); \
21 pr_warn(errmsg); \
22} while (0)
23
24struct cfpktq {
25 struct sk_buff_head head;
26 atomic_t count;
27 /* Lock protects count updates */
28 spinlock_t lock;
29};
30
31/*
32 * net/caif/ is generic and does not
33 * understand SKB, so we do this typecast
34 */
35struct cfpkt {
36 struct sk_buff skb;
37};
38
39/* Private data inside SKB */
40struct cfpkt_priv_data {
41 struct dev_info dev_info;
42 bool erronous;
43};
44
45static inline struct cfpkt_priv_data *cfpkt_priv(struct cfpkt *pkt)
46{
47 return (struct cfpkt_priv_data *) pkt->skb.cb;
48}
49
50static inline bool is_erronous(struct cfpkt *pkt)
51{
52 return cfpkt_priv(pkt)->erronous;
53}
54
55static inline struct sk_buff *pkt_to_skb(struct cfpkt *pkt)
56{
57 return &pkt->skb;
58}
59
60static inline struct cfpkt *skb_to_pkt(struct sk_buff *skb)
61{
62 return (struct cfpkt *) skb;
63}
64
65struct cfpkt *cfpkt_fromnative(enum caif_direction dir, void *nativepkt)
66{
67 struct cfpkt *pkt = skb_to_pkt(nativepkt);
68 cfpkt_priv(pkt)->erronous = false;
69 return pkt;
70}
71EXPORT_SYMBOL(cfpkt_fromnative);
72
73void *cfpkt_tonative(struct cfpkt *pkt)
74{
75 return (void *) pkt;
76}
77EXPORT_SYMBOL(cfpkt_tonative);
78
79static struct cfpkt *cfpkt_create_pfx(u16 len, u16 pfx)
80{
81 struct sk_buff *skb;
82
83 skb = alloc_skb(len + pfx, GFP_ATOMIC);
84 if (unlikely(skb == NULL))
85 return NULL;
86
87 skb_reserve(skb, pfx);
88 return skb_to_pkt(skb);
89}
90
91inline struct cfpkt *cfpkt_create(u16 len)
92{
93 return cfpkt_create_pfx(len + PKT_POSTFIX, PKT_PREFIX);
94}
95
96void cfpkt_destroy(struct cfpkt *pkt)
97{
98 struct sk_buff *skb = pkt_to_skb(pkt);
99 kfree_skb(skb);
100}
101
102inline bool cfpkt_more(struct cfpkt *pkt)
103{
104 struct sk_buff *skb = pkt_to_skb(pkt);
105 return skb->len > 0;
106}
107
108int cfpkt_peek_head(struct cfpkt *pkt, void *data, u16 len)
109{
110 struct sk_buff *skb = pkt_to_skb(pkt);
111 if (skb_headlen(skb) >= len) {
112 memcpy(data, skb->data, len);
113 return 0;
114 }
115 return !cfpkt_extr_head(pkt, data, len) &&
116 !cfpkt_add_head(pkt, data, len);
117}
118
119int cfpkt_extr_head(struct cfpkt *pkt, void *data, u16 len)
120{
121 struct sk_buff *skb = pkt_to_skb(pkt);
122 u8 *from;
123 if (unlikely(is_erronous(pkt)))
124 return -EPROTO;
125
126 if (unlikely(len > skb->len)) {
127 PKT_ERROR(pkt, "read beyond end of packet\n");
128 return -EPROTO;
129 }
130
131 if (unlikely(len > skb_headlen(skb))) {
132 if (unlikely(skb_linearize(skb) != 0)) {
133 PKT_ERROR(pkt, "linearize failed\n");
134 return -EPROTO;
135 }
136 }
137 from = skb_pull(skb, len);
138 from -= len;
139 if (data)
140 memcpy(data, from, len);
141 return 0;
142}
143EXPORT_SYMBOL(cfpkt_extr_head);
144
145int cfpkt_extr_trail(struct cfpkt *pkt, void *dta, u16 len)
146{
147 struct sk_buff *skb = pkt_to_skb(pkt);
148 u8 *data = dta;
149 u8 *from;
150 if (unlikely(is_erronous(pkt)))
151 return -EPROTO;
152
153 if (unlikely(skb_linearize(skb) != 0)) {
154 PKT_ERROR(pkt, "linearize failed\n");
155 return -EPROTO;
156 }
157 if (unlikely(skb->data + len > skb_tail_pointer(skb))) {
158 PKT_ERROR(pkt, "read beyond end of packet\n");
159 return -EPROTO;
160 }
161 from = skb_tail_pointer(skb) - len;
162 skb_trim(skb, skb->len - len);
163 memcpy(data, from, len);
164 return 0;
165}
166
167int cfpkt_pad_trail(struct cfpkt *pkt, u16 len)
168{
169 return cfpkt_add_body(pkt, NULL, len);
170}
171
172int cfpkt_add_body(struct cfpkt *pkt, const void *data, u16 len)
173{
174 struct sk_buff *skb = pkt_to_skb(pkt);
175 struct sk_buff *lastskb;
176 u8 *to;
177 u16 addlen = 0;
178
179
180 if (unlikely(is_erronous(pkt)))
181 return -EPROTO;
182
183 lastskb = skb;
184
185 /* Check whether we need to add space at the tail */
186 if (unlikely(skb_tailroom(skb) < len)) {
187 if (likely(len < PKT_LEN_WHEN_EXTENDING))
188 addlen = PKT_LEN_WHEN_EXTENDING;
189 else
190 addlen = len;
191 }
192
193 /* Check whether we need to change the SKB before writing to the tail */
194 if (unlikely((addlen > 0) || skb_cloned(skb) || skb_shared(skb))) {
195
196 /* Make sure data is writable */
197 if (unlikely(skb_cow_data(skb, addlen, &lastskb) < 0)) {
198 PKT_ERROR(pkt, "cow failed\n");
199 return -EPROTO;
200 }
201 }
202
203 /* All set to put the last SKB and optionally write data there. */
204 to = pskb_put(skb, lastskb, len);
205 if (likely(data))
206 memcpy(to, data, len);
207 return 0;
208}
209
210inline int cfpkt_addbdy(struct cfpkt *pkt, u8 data)
211{
212 return cfpkt_add_body(pkt, &data, 1);
213}
214
215int cfpkt_add_head(struct cfpkt *pkt, const void *data2, u16 len)
216{
217 struct sk_buff *skb = pkt_to_skb(pkt);
218 struct sk_buff *lastskb;
219 u8 *to;
220 const u8 *data = data2;
221 int ret;
222 if (unlikely(is_erronous(pkt)))
223 return -EPROTO;
224 if (unlikely(skb_headroom(skb) < len)) {
225 PKT_ERROR(pkt, "no headroom\n");
226 return -EPROTO;
227 }
228
229 /* Make sure data is writable */
230 ret = skb_cow_data(skb, 0, &lastskb);
231 if (unlikely(ret < 0)) {
232 PKT_ERROR(pkt, "cow failed\n");
233 return ret;
234 }
235
236 to = skb_push(skb, len);
237 memcpy(to, data, len);
238 return 0;
239}
240EXPORT_SYMBOL(cfpkt_add_head);
241
242inline int cfpkt_add_trail(struct cfpkt *pkt, const void *data, u16 len)
243{
244 return cfpkt_add_body(pkt, data, len);
245}
246
247inline u16 cfpkt_getlen(struct cfpkt *pkt)
248{
249 struct sk_buff *skb = pkt_to_skb(pkt);
250 return skb->len;
251}
252
253int cfpkt_iterate(struct cfpkt *pkt,
254 u16 (*iter_func)(u16, void *, u16),
255 u16 data)
256{
257 /*
258 * Don't care about the performance hit of linearizing,
259 * Checksum should not be used on high-speed interfaces anyway.
260 */
261 if (unlikely(is_erronous(pkt)))
262 return -EPROTO;
263 if (unlikely(skb_linearize(&pkt->skb) != 0)) {
264 PKT_ERROR(pkt, "linearize failed\n");
265 return -EPROTO;
266 }
267 return iter_func(data, pkt->skb.data, cfpkt_getlen(pkt));
268}
269
270int cfpkt_setlen(struct cfpkt *pkt, u16 len)
271{
272 struct sk_buff *skb = pkt_to_skb(pkt);
273
274
275 if (unlikely(is_erronous(pkt)))
276 return -EPROTO;
277
278 if (likely(len <= skb->len)) {
279 if (unlikely(skb->data_len))
280 ___pskb_trim(skb, len);
281 else
282 skb_trim(skb, len);
283
284 return cfpkt_getlen(pkt);
285 }
286
287 /* Need to expand SKB */
288 if (unlikely(!cfpkt_pad_trail(pkt, len - skb->len)))
289 PKT_ERROR(pkt, "skb_pad_trail failed\n");
290
291 return cfpkt_getlen(pkt);
292}
293
294struct cfpkt *cfpkt_append(struct cfpkt *dstpkt,
295 struct cfpkt *addpkt,
296 u16 expectlen)
297{
298 struct sk_buff *dst = pkt_to_skb(dstpkt);
299 struct sk_buff *add = pkt_to_skb(addpkt);
300 u16 addlen = skb_headlen(add);
301 u16 neededtailspace;
302 struct sk_buff *tmp;
303 u16 dstlen;
304 u16 createlen;
305 if (unlikely(is_erronous(dstpkt) || is_erronous(addpkt))) {
306 return dstpkt;
307 }
308 if (expectlen > addlen)
309 neededtailspace = expectlen;
310 else
311 neededtailspace = addlen;
312
313 if (dst->tail + neededtailspace > dst->end) {
314 /* Create a dumplicate of 'dst' with more tail space */
315 struct cfpkt *tmppkt;
316 dstlen = skb_headlen(dst);
317 createlen = dstlen + neededtailspace;
318 tmppkt = cfpkt_create(createlen + PKT_PREFIX + PKT_POSTFIX);
319 if (tmppkt == NULL)
320 return NULL;
321 tmp = pkt_to_skb(tmppkt);
322 skb_put_data(tmp, dst->data, dstlen);
323 cfpkt_destroy(dstpkt);
324 dst = tmp;
325 }
326 skb_put_data(dst, add->data, skb_headlen(add));
327 cfpkt_destroy(addpkt);
328 return skb_to_pkt(dst);
329}
330
331struct cfpkt *cfpkt_split(struct cfpkt *pkt, u16 pos)
332{
333 struct sk_buff *skb2;
334 struct sk_buff *skb = pkt_to_skb(pkt);
335 struct cfpkt *tmppkt;
336 u8 *split = skb->data + pos;
337 u16 len2nd = skb_tail_pointer(skb) - split;
338
339 if (unlikely(is_erronous(pkt)))
340 return NULL;
341
342 if (skb->data + pos > skb_tail_pointer(skb)) {
343 PKT_ERROR(pkt, "trying to split beyond end of packet\n");
344 return NULL;
345 }
346
347 /* Create a new packet for the second part of the data */
348 tmppkt = cfpkt_create_pfx(len2nd + PKT_PREFIX + PKT_POSTFIX,
349 PKT_PREFIX);
350 if (tmppkt == NULL)
351 return NULL;
352 skb2 = pkt_to_skb(tmppkt);
353
354
355 if (skb2 == NULL)
356 return NULL;
357
358 skb_put_data(skb2, split, len2nd);
359
360 /* Reduce the length of the original packet */
361 skb_trim(skb, pos);
362
363 skb2->priority = skb->priority;
364 return skb_to_pkt(skb2);
365}
366
367bool cfpkt_erroneous(struct cfpkt *pkt)
368{
369 return cfpkt_priv(pkt)->erronous;
370}
371
372struct caif_payload_info *cfpkt_info(struct cfpkt *pkt)
373{
374 return (struct caif_payload_info *)&pkt_to_skb(pkt)->cb;
375}
376EXPORT_SYMBOL(cfpkt_info);
377
378void cfpkt_set_prio(struct cfpkt *pkt, int prio)
379{
380 pkt_to_skb(pkt)->priority = prio;
381}
382EXPORT_SYMBOL(cfpkt_set_prio);
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 */
6
7#define pr_fmt(fmt) KBUILD_MODNAME ":%s(): " fmt, __func__
8
9#include <linux/string.h>
10#include <linux/skbuff.h>
11#include <linux/hardirq.h>
12#include <linux/export.h>
13#include <net/caif/cfpkt.h>
14
15#define PKT_PREFIX 48
16#define PKT_POSTFIX 2
17#define PKT_LEN_WHEN_EXTENDING 128
18#define PKT_ERROR(pkt, errmsg) \
19do { \
20 cfpkt_priv(pkt)->erronous = true; \
21 skb_reset_tail_pointer(&pkt->skb); \
22 pr_warn(errmsg); \
23} while (0)
24
25struct cfpktq {
26 struct sk_buff_head head;
27 atomic_t count;
28 /* Lock protects count updates */
29 spinlock_t lock;
30};
31
32/*
33 * net/caif/ is generic and does not
34 * understand SKB, so we do this typecast
35 */
36struct cfpkt {
37 struct sk_buff skb;
38};
39
40/* Private data inside SKB */
41struct cfpkt_priv_data {
42 struct dev_info dev_info;
43 bool erronous;
44};
45
46static inline struct cfpkt_priv_data *cfpkt_priv(struct cfpkt *pkt)
47{
48 return (struct cfpkt_priv_data *) pkt->skb.cb;
49}
50
51static inline bool is_erronous(struct cfpkt *pkt)
52{
53 return cfpkt_priv(pkt)->erronous;
54}
55
56static inline struct sk_buff *pkt_to_skb(struct cfpkt *pkt)
57{
58 return &pkt->skb;
59}
60
61static inline struct cfpkt *skb_to_pkt(struct sk_buff *skb)
62{
63 return (struct cfpkt *) skb;
64}
65
66struct cfpkt *cfpkt_fromnative(enum caif_direction dir, void *nativepkt)
67{
68 struct cfpkt *pkt = skb_to_pkt(nativepkt);
69 cfpkt_priv(pkt)->erronous = false;
70 return pkt;
71}
72EXPORT_SYMBOL(cfpkt_fromnative);
73
74void *cfpkt_tonative(struct cfpkt *pkt)
75{
76 return (void *) pkt;
77}
78EXPORT_SYMBOL(cfpkt_tonative);
79
80static struct cfpkt *cfpkt_create_pfx(u16 len, u16 pfx)
81{
82 struct sk_buff *skb;
83
84 if (likely(in_interrupt()))
85 skb = alloc_skb(len + pfx, GFP_ATOMIC);
86 else
87 skb = alloc_skb(len + pfx, GFP_KERNEL);
88
89 if (unlikely(skb == NULL))
90 return NULL;
91
92 skb_reserve(skb, pfx);
93 return skb_to_pkt(skb);
94}
95
96inline struct cfpkt *cfpkt_create(u16 len)
97{
98 return cfpkt_create_pfx(len + PKT_POSTFIX, PKT_PREFIX);
99}
100
101void cfpkt_destroy(struct cfpkt *pkt)
102{
103 struct sk_buff *skb = pkt_to_skb(pkt);
104 kfree_skb(skb);
105}
106
107inline bool cfpkt_more(struct cfpkt *pkt)
108{
109 struct sk_buff *skb = pkt_to_skb(pkt);
110 return skb->len > 0;
111}
112
113int cfpkt_peek_head(struct cfpkt *pkt, void *data, u16 len)
114{
115 struct sk_buff *skb = pkt_to_skb(pkt);
116 if (skb_headlen(skb) >= len) {
117 memcpy(data, skb->data, len);
118 return 0;
119 }
120 return !cfpkt_extr_head(pkt, data, len) &&
121 !cfpkt_add_head(pkt, data, len);
122}
123
124int cfpkt_extr_head(struct cfpkt *pkt, void *data, u16 len)
125{
126 struct sk_buff *skb = pkt_to_skb(pkt);
127 u8 *from;
128 if (unlikely(is_erronous(pkt)))
129 return -EPROTO;
130
131 if (unlikely(len > skb->len)) {
132 PKT_ERROR(pkt, "read beyond end of packet\n");
133 return -EPROTO;
134 }
135
136 if (unlikely(len > skb_headlen(skb))) {
137 if (unlikely(skb_linearize(skb) != 0)) {
138 PKT_ERROR(pkt, "linearize failed\n");
139 return -EPROTO;
140 }
141 }
142 from = skb_pull(skb, len);
143 from -= len;
144 if (data)
145 memcpy(data, from, len);
146 return 0;
147}
148EXPORT_SYMBOL(cfpkt_extr_head);
149
150int cfpkt_extr_trail(struct cfpkt *pkt, void *dta, u16 len)
151{
152 struct sk_buff *skb = pkt_to_skb(pkt);
153 u8 *data = dta;
154 u8 *from;
155 if (unlikely(is_erronous(pkt)))
156 return -EPROTO;
157
158 if (unlikely(skb_linearize(skb) != 0)) {
159 PKT_ERROR(pkt, "linearize failed\n");
160 return -EPROTO;
161 }
162 if (unlikely(skb->data + len > skb_tail_pointer(skb))) {
163 PKT_ERROR(pkt, "read beyond end of packet\n");
164 return -EPROTO;
165 }
166 from = skb_tail_pointer(skb) - len;
167 skb_trim(skb, skb->len - len);
168 memcpy(data, from, len);
169 return 0;
170}
171
172int cfpkt_pad_trail(struct cfpkt *pkt, u16 len)
173{
174 return cfpkt_add_body(pkt, NULL, len);
175}
176
177int cfpkt_add_body(struct cfpkt *pkt, const void *data, u16 len)
178{
179 struct sk_buff *skb = pkt_to_skb(pkt);
180 struct sk_buff *lastskb;
181 u8 *to;
182 u16 addlen = 0;
183
184
185 if (unlikely(is_erronous(pkt)))
186 return -EPROTO;
187
188 lastskb = skb;
189
190 /* Check whether we need to add space at the tail */
191 if (unlikely(skb_tailroom(skb) < len)) {
192 if (likely(len < PKT_LEN_WHEN_EXTENDING))
193 addlen = PKT_LEN_WHEN_EXTENDING;
194 else
195 addlen = len;
196 }
197
198 /* Check whether we need to change the SKB before writing to the tail */
199 if (unlikely((addlen > 0) || skb_cloned(skb) || skb_shared(skb))) {
200
201 /* Make sure data is writable */
202 if (unlikely(skb_cow_data(skb, addlen, &lastskb) < 0)) {
203 PKT_ERROR(pkt, "cow failed\n");
204 return -EPROTO;
205 }
206 /*
207 * Is the SKB non-linear after skb_cow_data()? If so, we are
208 * going to add data to the last SKB, so we need to adjust
209 * lengths of the top SKB.
210 */
211 if (lastskb != skb) {
212 pr_warn("Packet is non-linear\n");
213 skb->len += len;
214 skb->data_len += len;
215 }
216 }
217
218 /* All set to put the last SKB and optionally write data there. */
219 to = skb_put(lastskb, len);
220 if (likely(data))
221 memcpy(to, data, len);
222 return 0;
223}
224
225inline int cfpkt_addbdy(struct cfpkt *pkt, u8 data)
226{
227 return cfpkt_add_body(pkt, &data, 1);
228}
229
230int cfpkt_add_head(struct cfpkt *pkt, const void *data2, u16 len)
231{
232 struct sk_buff *skb = pkt_to_skb(pkt);
233 struct sk_buff *lastskb;
234 u8 *to;
235 const u8 *data = data2;
236 int ret;
237 if (unlikely(is_erronous(pkt)))
238 return -EPROTO;
239 if (unlikely(skb_headroom(skb) < len)) {
240 PKT_ERROR(pkt, "no headroom\n");
241 return -EPROTO;
242 }
243
244 /* Make sure data is writable */
245 ret = skb_cow_data(skb, 0, &lastskb);
246 if (unlikely(ret < 0)) {
247 PKT_ERROR(pkt, "cow failed\n");
248 return ret;
249 }
250
251 to = skb_push(skb, len);
252 memcpy(to, data, len);
253 return 0;
254}
255EXPORT_SYMBOL(cfpkt_add_head);
256
257inline int cfpkt_add_trail(struct cfpkt *pkt, const void *data, u16 len)
258{
259 return cfpkt_add_body(pkt, data, len);
260}
261
262inline u16 cfpkt_getlen(struct cfpkt *pkt)
263{
264 struct sk_buff *skb = pkt_to_skb(pkt);
265 return skb->len;
266}
267
268inline u16 cfpkt_iterate(struct cfpkt *pkt,
269 u16 (*iter_func)(u16, void *, u16),
270 u16 data)
271{
272 /*
273 * Don't care about the performance hit of linearizing,
274 * Checksum should not be used on high-speed interfaces anyway.
275 */
276 if (unlikely(is_erronous(pkt)))
277 return -EPROTO;
278 if (unlikely(skb_linearize(&pkt->skb) != 0)) {
279 PKT_ERROR(pkt, "linearize failed\n");
280 return -EPROTO;
281 }
282 return iter_func(data, pkt->skb.data, cfpkt_getlen(pkt));
283}
284
285int cfpkt_setlen(struct cfpkt *pkt, u16 len)
286{
287 struct sk_buff *skb = pkt_to_skb(pkt);
288
289
290 if (unlikely(is_erronous(pkt)))
291 return -EPROTO;
292
293 if (likely(len <= skb->len)) {
294 if (unlikely(skb->data_len))
295 ___pskb_trim(skb, len);
296 else
297 skb_trim(skb, len);
298
299 return cfpkt_getlen(pkt);
300 }
301
302 /* Need to expand SKB */
303 if (unlikely(!cfpkt_pad_trail(pkt, len - skb->len)))
304 PKT_ERROR(pkt, "skb_pad_trail failed\n");
305
306 return cfpkt_getlen(pkt);
307}
308
309struct cfpkt *cfpkt_append(struct cfpkt *dstpkt,
310 struct cfpkt *addpkt,
311 u16 expectlen)
312{
313 struct sk_buff *dst = pkt_to_skb(dstpkt);
314 struct sk_buff *add = pkt_to_skb(addpkt);
315 u16 addlen = skb_headlen(add);
316 u16 neededtailspace;
317 struct sk_buff *tmp;
318 u16 dstlen;
319 u16 createlen;
320 if (unlikely(is_erronous(dstpkt) || is_erronous(addpkt))) {
321 return dstpkt;
322 }
323 if (expectlen > addlen)
324 neededtailspace = expectlen;
325 else
326 neededtailspace = addlen;
327
328 if (dst->tail + neededtailspace > dst->end) {
329 /* Create a dumplicate of 'dst' with more tail space */
330 struct cfpkt *tmppkt;
331 dstlen = skb_headlen(dst);
332 createlen = dstlen + neededtailspace;
333 tmppkt = cfpkt_create(createlen + PKT_PREFIX + PKT_POSTFIX);
334 if (tmppkt == NULL)
335 return NULL;
336 tmp = pkt_to_skb(tmppkt);
337 skb_set_tail_pointer(tmp, dstlen);
338 tmp->len = dstlen;
339 memcpy(tmp->data, dst->data, dstlen);
340 cfpkt_destroy(dstpkt);
341 dst = tmp;
342 }
343 memcpy(skb_tail_pointer(dst), add->data, skb_headlen(add));
344 cfpkt_destroy(addpkt);
345 dst->tail += addlen;
346 dst->len += addlen;
347 return skb_to_pkt(dst);
348}
349
350struct cfpkt *cfpkt_split(struct cfpkt *pkt, u16 pos)
351{
352 struct sk_buff *skb2;
353 struct sk_buff *skb = pkt_to_skb(pkt);
354 struct cfpkt *tmppkt;
355 u8 *split = skb->data + pos;
356 u16 len2nd = skb_tail_pointer(skb) - split;
357
358 if (unlikely(is_erronous(pkt)))
359 return NULL;
360
361 if (skb->data + pos > skb_tail_pointer(skb)) {
362 PKT_ERROR(pkt, "trying to split beyond end of packet\n");
363 return NULL;
364 }
365
366 /* Create a new packet for the second part of the data */
367 tmppkt = cfpkt_create_pfx(len2nd + PKT_PREFIX + PKT_POSTFIX,
368 PKT_PREFIX);
369 if (tmppkt == NULL)
370 return NULL;
371 skb2 = pkt_to_skb(tmppkt);
372
373
374 if (skb2 == NULL)
375 return NULL;
376
377 /* Reduce the length of the original packet */
378 skb_set_tail_pointer(skb, pos);
379 skb->len = pos;
380
381 memcpy(skb2->data, split, len2nd);
382 skb2->tail += len2nd;
383 skb2->len += len2nd;
384 skb2->priority = skb->priority;
385 return skb_to_pkt(skb2);
386}
387
388bool cfpkt_erroneous(struct cfpkt *pkt)
389{
390 return cfpkt_priv(pkt)->erronous;
391}
392
393struct caif_payload_info *cfpkt_info(struct cfpkt *pkt)
394{
395 return (struct caif_payload_info *)&pkt_to_skb(pkt)->cb;
396}
397EXPORT_SYMBOL(cfpkt_info);
398
399void cfpkt_set_prio(struct cfpkt *pkt, int prio)
400{
401 pkt_to_skb(pkt)->priority = prio;
402}
403EXPORT_SYMBOL(cfpkt_set_prio);