1 /******************************************************************************
4 Lantiq Deutschland GmbH
6 For licensing information, see the file 'LICENSE' in the root folder of
9 ******************************************************************************/
17 * Originally written by Andrey Fidrya
24 #define LOG_LOCAL_GID GID_UTILS
25 #define LOG_LOCAL_FID 1
28 * Function outputs buffer in hex format
32 mtlk_aux_print_hex (const void *buf
, unsigned int l
)
40 #define LOG_BUFFER pr_cont
44 mtlk_aux_print_hex (const void *buf
, unsigned int l
)
47 unsigned char *cp
= (unsigned char*)buf
;
49 //TODO should be probably locked
51 LOG_BUFFER("cp= 0x%p l=%d\n", cp
, l
);
52 for (i
= 0; i
< l
/16; i
++) {
53 LOG_BUFFER("%04x: ", 16*i
);
54 for (j
= 0; j
< 16; j
++)
55 LOG_BUFFER("%02x %s", *cp
++, j
== 7 ? " " : "");
59 LOG_BUFFER("%04x: ", 16*i
);
60 for (j
= 0; j
< (l
&0x0f); j
++)
61 LOG_BUFFER("%02x %s", *cp
++, j
== 7 ? " " : "");
67 void __mtlk_dump(const void *buf
, uint32 len
, char *str
)
70 mtlk_aux_print_hex(buf
, len
);
74 mtlk_shexdump (char *buffer
, uint8
*data
, size_t size
)
79 for (line
= 0; size
; line
++) {
80 counter
+= sprintf(buffer
+counter
, "%04x: ", line
* 0x10);
81 for (i
= 0x10; i
&& size
; size
--,i
--,data
++) {
82 counter
+=sprintf(buffer
+counter
, " %02x", *data
);
84 counter
+= sprintf(buffer
+counter
, "\n");
90 mtlk_get_token (char *str
, char *buf
, size_t len
, char delim
)
98 dlm
= strchr(str
, delim
);
99 if (dlm
&& ((size_t)(dlm
- str
) < len
)) {
100 memcpy(buf
, str
, dlm
- str
);
103 memcpy(buf
, str
, len
- 1);
106 ILOG4_S("Get token: '%s'", buf
);
113 Extract MAC address from string
115 \param str - string with MAC address [I]
116 \param addr - pointer to MAC storage [O]
119 MTLK_ERR_PARAMS - wrong format of MAC address in the string
120 MTLK_ERR_OK - success
123 accepted the following string formats
127 mtlk_str_to_mac (char const *str
, uint8
*addr
)
131 MTLK_ASSERT(NULL
!= str
);
132 MTLK_ASSERT(NULL
!= addr
);
134 str
= mtlk_str_ltrim(str
);
136 if (strlen(str
) < 17)
137 return MTLK_ERR_PARAMS
;
139 if ((':' != str
[2]) ||
144 return MTLK_ERR_PARAMS
;
146 memset (addr
, 0, sizeof(*addr
));
148 for (i
= 0; i
< 6; i
++)
150 addr
[i
] = mtlk_str_x2tol(str
+ (i
* 3));