util.c 987 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*
  2. * Copyright (C) 2014 Felix Fietkau <nbd@openwrt.org>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2
  6. * as published by the Free Software Foundation
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. */
  13. #include "mt7601u.h"
  14. void mt76_remove_hdr_pad(struct sk_buff *skb)
  15. {
  16. int len = ieee80211_get_hdrlen_from_skb(skb);
  17. memmove(skb->data + 2, skb->data, len);
  18. skb_pull(skb, 2);
  19. }
  20. int mt76_insert_hdr_pad(struct sk_buff *skb)
  21. {
  22. int len = ieee80211_get_hdrlen_from_skb(skb);
  23. int ret;
  24. if (len % 4 == 0)
  25. return 0;
  26. ret = skb_cow(skb, 2);
  27. if (ret)
  28. return ret;
  29. skb_push(skb, 2);
  30. memmove(skb->data, skb->data + 2, len);
  31. skb->data[len] = 0;
  32. skb->data[len + 1] = 0;
  33. return 0;
  34. }