1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef _LINUX_HEX_H
3#define _LINUX_HEX_H
4
5#include <linux/types.h>
6
7extern 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
11static 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
18extern 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
22static 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
29extern int hex_to_bin(unsigned char ch);
30extern int __must_check hex2bin(u8 *dst, const char *src, size_t count);
31extern char *bin2hex(char *dst, const void *src, size_t count);
32
33bool mac_pton(const char *s, u8 *mac);
34
35#endif
36

source code of linux/include/linux/hex.h