hex.h 871 B

12345678910111213141516171819202122232425262728293031323334
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _LINUX_HEX_H
  3. #define _LINUX_HEX_H
  4. #include "../types.h"
  5. extern const char hex_asc[];
  6. #define hex_asc_lo(x) hex_asc[((x)&0x0f)]
  7. #define hex_asc_hi(x) hex_asc[((x)&0xf0) >> 4]
  8. static inline char *hex_byte_pack(char *buf, u8 byte)
  9. {
  10. *buf++ = hex_asc_hi(byte);
  11. *buf++ = hex_asc_lo(byte);
  12. return buf;
  13. }
  14. extern const char hex_asc_upper[];
  15. #define hex_asc_upper_lo(x) hex_asc_upper[((x)&0x0f)]
  16. #define hex_asc_upper_hi(x) hex_asc_upper[((x)&0xf0) >> 4]
  17. static inline char *hex_byte_pack_upper(char *buf, u8 byte)
  18. {
  19. *buf++ = hex_asc_upper_hi(byte);
  20. *buf++ = hex_asc_upper_lo(byte);
  21. return buf;
  22. }
  23. extern int hex_to_bin(unsigned char ch);
  24. extern int __must_check hex2bin(u8 *dst, const char *src, size_t count);
  25. extern char *bin2hex(char *dst, const void *src, size_t count);
  26. bool mac_pton(const char *s, u8 *mac);
  27. #endif