9b34add4229f0f09c41a99451055eab581cfae02
[project/usteer.git] / utils.h
1 /*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License.
5 *
6 * This program is distributed in the hope that it will be useful,
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 * GNU General Public License for more details.
10 *
11 * You should have received a copy of the GNU General Public License
12 * along with this program; if not, write to the Free Software
13 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
14 *
15 * Copyright (C) 2020 embedd.ch
16 * Copyright (C) 2020 Felix Fietkau <nbd@nbd.name>
17 * Copyright (C) 2020 John Crispin <john@phrozen.org>
18 */
19
20 #ifndef __APMGR_UTILS_H
21 #define __APMGR_UTILS_H
22
23 #define MSG(_nr, _format, ...) debug_msg(MSG_##_nr, __func__, __LINE__, _format, ##__VA_ARGS__)
24 #define MSG_CONT(_nr, _format, ...) debug_msg_cont(MSG_##_nr, _format, ##__VA_ARGS__)
25
26 #define MAC_ADDR_FMT "%02x:%02x:%02x:%02x:%02x:%02x"
27 #define MAC_ADDR_DATA(_a) \
28 ((const uint8_t *)(_a))[0], \
29 ((const uint8_t *)(_a))[1], \
30 ((const uint8_t *)(_a))[2], \
31 ((const uint8_t *)(_a))[3], \
32 ((const uint8_t *)(_a))[4], \
33 ((const uint8_t *)(_a))[5]
34
35 #define MSG_T_STA(_option, _sta_addr, _format, ...) \
36 MSG(DEBUG_ALL, "TESTCASE=" _option ",STA=" MAC_ADDR_FMT ": " _format, \
37 MAC_ADDR_DATA(_sta_addr), ##__VA_ARGS__)
38
39 #define MSG_T(_option, _format, ...) \
40 MSG(DEBUG_ALL, "TESTCASE=" _option ": " _format, ##__VA_ARGS__)
41
42 enum usteer_debug {
43 MSG_FATAL,
44 MSG_INFO,
45 MSG_VERBOSE,
46 MSG_DEBUG,
47 MSG_NETWORK,
48 MSG_DEBUG_ALL,
49 };
50
51 extern void debug_msg(int level, const char *func, int line, const char *format, ...);
52 extern void debug_msg_cont(int level, const char *format, ...);
53
54 #define __usteer_init __attribute__((constructor))
55
56 #endif