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