qmi_encdec_priv.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /* Copyright (c) 2012, The Linux Foundation. All rights reserved.
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License version 2 and
  5. * only version 2 as published by the Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. */
  12. #ifndef _QMI_ENCDEC_PRIV_H_
  13. #define _QMI_ENCDEC_PRIV_H_
  14. #include <linux/types.h>
  15. #include <linux/errno.h>
  16. #include <linux/mm.h>
  17. #include <linux/list.h>
  18. #include <linux/socket.h>
  19. #include <linux/gfp.h>
  20. #include <linux/qmi_encdec.h>
  21. #define QMI_ENCDEC_ENCODE_TLV(type, length, p_dst) do { \
  22. *p_dst++ = type; \
  23. *p_dst++ = ((uint8_t)((length) & 0xFF)); \
  24. *p_dst++ = ((uint8_t)(((length) >> 8) & 0xFF)); \
  25. } while (0)
  26. #define QMI_ENCDEC_DECODE_TLV(p_type, p_length, p_src) do { \
  27. *p_type = (uint8_t)*p_src++; \
  28. *p_length = (uint8_t)*p_src++; \
  29. *p_length |= ((uint8_t)*p_src) << 8; \
  30. } while (0)
  31. #define QMI_ENCDEC_ENCODE_N_BYTES(p_dst, p_src, size) \
  32. do { \
  33. memcpy(p_dst, p_src, size); \
  34. p_dst = (uint8_t *)p_dst + size; \
  35. p_src = (uint8_t *)p_src + size; \
  36. } while (0)
  37. #define QMI_ENCDEC_DECODE_N_BYTES(p_dst, p_src, size) \
  38. do { \
  39. memcpy(p_dst, p_src, size); \
  40. p_dst = (uint8_t *)p_dst + size; \
  41. p_src = (uint8_t *)p_src + size; \
  42. } while (0)
  43. #define UPDATE_ENCODE_VARIABLES(temp_si, buf_dst, \
  44. encoded_bytes, tlv_len, encode_tlv, rc) \
  45. do { \
  46. buf_dst = (uint8_t *)buf_dst + rc; \
  47. encoded_bytes += rc; \
  48. tlv_len += rc; \
  49. temp_si = temp_si + 1; \
  50. encode_tlv = 1; \
  51. } while (0)
  52. #define UPDATE_DECODE_VARIABLES(buf_src, decoded_bytes, rc) \
  53. do { \
  54. buf_src = (uint8_t *)buf_src + rc; \
  55. decoded_bytes += rc; \
  56. } while (0)
  57. #endif