xref: /linux/drivers/net/wireless/mediatek/mt7601u/util.c (revision 75bf465f0bc33e9b776a46d6a1b9b990f5fb7c37)
1*1802d0beSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
2c869f77dSJakub Kicinski /*
3c869f77dSJakub Kicinski  * Copyright (C) 2014 Felix Fietkau <nbd@openwrt.org>
4c869f77dSJakub Kicinski  */
5c869f77dSJakub Kicinski 
6c869f77dSJakub Kicinski #include "mt7601u.h"
7c869f77dSJakub Kicinski 
mt76_remove_hdr_pad(struct sk_buff * skb)8c869f77dSJakub Kicinski void mt76_remove_hdr_pad(struct sk_buff *skb)
9c869f77dSJakub Kicinski {
10c869f77dSJakub Kicinski 	int len = ieee80211_get_hdrlen_from_skb(skb);
11c869f77dSJakub Kicinski 
12c869f77dSJakub Kicinski 	memmove(skb->data + 2, skb->data, len);
13c869f77dSJakub Kicinski 	skb_pull(skb, 2);
14c869f77dSJakub Kicinski }
15c869f77dSJakub Kicinski 
mt76_insert_hdr_pad(struct sk_buff * skb)16c869f77dSJakub Kicinski int mt76_insert_hdr_pad(struct sk_buff *skb)
17c869f77dSJakub Kicinski {
18c869f77dSJakub Kicinski 	int len = ieee80211_get_hdrlen_from_skb(skb);
19c869f77dSJakub Kicinski 	int ret;
20c869f77dSJakub Kicinski 
21c869f77dSJakub Kicinski 	if (len % 4 == 0)
22c869f77dSJakub Kicinski 		return 0;
23c869f77dSJakub Kicinski 
24c869f77dSJakub Kicinski 	ret = skb_cow(skb, 2);
25c869f77dSJakub Kicinski 	if (ret)
26c869f77dSJakub Kicinski 		return ret;
27c869f77dSJakub Kicinski 
28c869f77dSJakub Kicinski 	skb_push(skb, 2);
29c869f77dSJakub Kicinski 	memmove(skb->data, skb->data + 2, len);
30c869f77dSJakub Kicinski 
31c869f77dSJakub Kicinski 	skb->data[len] = 0;
32c869f77dSJakub Kicinski 	skb->data[len + 1] = 0;
33c869f77dSJakub Kicinski 	return 0;
34c869f77dSJakub Kicinski }
35