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