48 #define __FILENAME__ \
49 (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)
51 #define __FILENAME__ \
52 (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
56 #include "android/oc_log_android.h"
66 #define PRINT(...) __android_log_print(ANDROID_LOG_INFO, TAG, __VA_ARGS__)
70 #define PRINT(...) oc_file_print(__VA_ARGS__)
72 #define PRINT(...) printf(__VA_ARGS__)
80 #define PRINT_APP(...) printf(__VA_ARGS__)
82 #define PRINT_APP(...)
85 #define SPRINTF(...) sprintf(__VA_ARGS__)
86 #define SNPRINTF(...) snprintf(__VA_ARGS__)
88 #define PRINTipaddr(endpoint) \
90 const char *scheme = "coap"; \
91 if ((endpoint).flags & SECURED) \
93 if ((endpoint).flags & TCP) \
94 scheme = "coap+tcp"; \
95 if ((endpoint).flags & TCP && (endpoint).flags & SECURED) \
96 scheme = "coaps+tcp"; \
97 if ((endpoint).flags & IPV4) { \
98 PRINT("%s://%d.%d.%d.%d:%d", scheme, ((endpoint).addr.ipv4.address)[0], \
99 ((endpoint).addr.ipv4.address)[1], \
100 ((endpoint).addr.ipv4.address)[2], \
101 ((endpoint).addr.ipv4.address)[3], (endpoint).addr.ipv4.port); \
104 "%s://[%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%" \
108 scheme, ((endpoint).addr.ipv6.address)[0], \
109 ((endpoint).addr.ipv6.address)[1], ((endpoint).addr.ipv6.address)[2], \
110 ((endpoint).addr.ipv6.address)[3], ((endpoint).addr.ipv6.address)[4], \
111 ((endpoint).addr.ipv6.address)[5], ((endpoint).addr.ipv6.address)[6], \
112 ((endpoint).addr.ipv6.address)[7], ((endpoint).addr.ipv6.address)[8], \
113 ((endpoint).addr.ipv6.address)[9], ((endpoint).addr.ipv6.address)[10], \
114 ((endpoint).addr.ipv6.address)[11], \
115 ((endpoint).addr.ipv6.address)[12], \
116 ((endpoint).addr.ipv6.address)[13], \
117 ((endpoint).addr.ipv6.address)[14], \
118 ((endpoint).addr.ipv6.address)[15], (endpoint).addr.ipv6.port); \
122 #define PRINTipaddr_flags(endpoint) \
124 if ((endpoint).flags & SECURED) { \
125 PRINT(" Secured "); \
127 if ((endpoint).flags & MULTICAST) { \
128 PRINT(" MULTICAST "); \
130 if ((endpoint).flags & TCP) { \
133 if ((endpoint).flags & IPV4) { \
136 if ((endpoint).flags & IPV6) { \
139 if ((endpoint).flags & OSCORE) { \
142 if ((endpoint).flags & ACCEPTED) { \
143 PRINT(" ACCEPTED "); \
145 if ((endpoint).flags & OSCORE_DECRYPTED) { \
146 PRINT(" OSCORE_DECRYPTED "); \
151 #define PRINTipaddr_local(endpoint) \
153 const char *scheme = "coap"; \
154 if ((endpoint).flags & SECURED) \
156 if ((endpoint).flags & TCP) \
157 scheme = "coap+tcp"; \
158 if ((endpoint).flags & TCP && (endpoint).flags & SECURED) \
159 scheme = "coaps+tcp"; \
160 if ((endpoint).flags & IPV4) { \
161 PRINT("%s://%d.%d.%d.%d:%d", scheme, \
162 ((endpoint).addr_local.ipv4.address)[0], \
163 ((endpoint).addr_local.ipv4.address)[1], \
164 ((endpoint).addr_local.ipv4.address)[2], \
165 ((endpoint).addr_local.ipv4.address)[3], \
166 (endpoint).addr_local.ipv4.port); \
169 "%s://[%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%" \
173 scheme, ((endpoint).addr_local.ipv6.address)[0], \
174 ((endpoint).addr_local.ipv6.address)[1], \
175 ((endpoint).addr_local.ipv6.address)[2], \
176 ((endpoint).addr_local.ipv6.address)[3], \
177 ((endpoint).addr_local.ipv6.address)[4], \
178 ((endpoint).addr_local.ipv6.address)[5], \
179 ((endpoint).addr_local.ipv6.address)[6], \
180 ((endpoint).addr_local.ipv6.address)[7], \
181 ((endpoint).addr_local.ipv6.address)[8], \
182 ((endpoint).addr_local.ipv6.address)[9], \
183 ((endpoint).addr_local.ipv6.address)[10], \
184 ((endpoint).addr_local.ipv6.address)[11], \
185 ((endpoint).addr_local.ipv6.address)[12], \
186 ((endpoint).addr_local.ipv6.address)[13], \
187 ((endpoint).addr_local.ipv6.address)[14], \
188 ((endpoint).addr_local.ipv6.address)[15], \
189 (endpoint).addr_local.ipv6.port); \
193 #define IPADDR_BUFF_SIZE 64
195 #define SNPRINTFipaddr(str, size, endpoint) \
197 const char *scheme = "coap"; \
198 if ((endpoint).flags & SECURED) \
200 if ((endpoint).flags & TCP) \
201 scheme = "coap+tcp"; \
202 if ((endpoint).flags & TCP && (endpoint).flags & SECURED) \
203 scheme = "coaps+tcp"; \
204 memset(str, 0, size); \
205 if ((endpoint).flags & IPV4) { \
206 SNPRINTF(str, size, "%s://%d.%d.%d.%d:%d", scheme, \
207 ((endpoint).addr.ipv4.address)[0], \
208 ((endpoint).addr.ipv4.address)[1], \
209 ((endpoint).addr.ipv4.address)[2], \
210 ((endpoint).addr.ipv4.address)[3], (endpoint).addr.ipv4.port); \
215 "[%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:" \
217 scheme, ((endpoint).addr.ipv6.address)[0], \
218 ((endpoint).addr.ipv6.address)[1], ((endpoint).addr.ipv6.address)[2], \
219 ((endpoint).addr.ipv6.address)[3], ((endpoint).addr.ipv6.address)[4], \
220 ((endpoint).addr.ipv6.address)[5], ((endpoint).addr.ipv6.address)[6], \
221 ((endpoint).addr.ipv6.address)[7], ((endpoint).addr.ipv6.address)[8], \
222 ((endpoint).addr.ipv6.address)[9], ((endpoint).addr.ipv6.address)[10], \
223 ((endpoint).addr.ipv6.address)[11], \
224 ((endpoint).addr.ipv6.address)[12], \
225 ((endpoint).addr.ipv6.address)[13], \
226 ((endpoint).addr.ipv6.address)[14], \
227 ((endpoint).addr.ipv6.address)[15], (endpoint).addr.ipv6.port); \
231 #define SNPRINTFbytes(buff, size, data, len) \
233 char *beg = (buff); \
234 char *end = (buff) + (size); \
235 for (size_t i = 0; beg <= (end - 3) && i < (len); i++) { \
236 beg += (i == 0) ? SPRINTF(beg, "%02x", (data)[i]) \
237 : SPRINTF(beg, ":%02x", (data)[i]); \
241 #define OC_LOG(level, ...) \
243 PRINT("%s: %s <%s:%d>: ", level, __FILENAME__, __func__, __LINE__); \
244 PRINT(__VA_ARGS__); \
248 #define OC_LOGbytes_internalxx(prefix, bytes, length) \
250 PRINT("%s: %s <%s:%d>:\n", prefix, __FILENAME__, __func__, __LINE__); \
252 for (i = 0; i < (length); i++) \
253 PRINT(" %02X", (bytes)[i]); \
257 #define OC_LOGbytes_internal(prefix, bytes, length) \
260 for (i = 0; i < (length); i++) \
261 PRINT(" %02X", (bytes)[i]); \
267 #define OC_LOG(level, ...) \
268 android_log(level, __FILE__, __func__, __LINE__, __VA_ARGS__)
269 #define OC_LOGipaddr(endpoint) \
270 android_log_ipaddr("DEBUG", __FILE__, __func__, __LINE__, endpoint)
271 #define OC_LOGbytes(bytes, length) \
272 android_log_bytes("DEBUG", __FILE__, __func__, __LINE__, bytes, length)
283 #define OC_LOGipaddr(endpoint) \
285 PRINT("DEBUG: %s <%s:%d>: ", __FILENAME__, __func__, __LINE__); \
286 PRINTipaddr(endpoint); \
290 #ifndef OC_NO_LOG_BYTES
291 #define OC_LOGbytes(bytes, length) \
293 PRINT("D: %s <%s:%d>: ", __FILENAME__, __func__, __LINE__); \
295 for (i = 0; i < (length); i++) \
296 PRINT(" %02X", (bytes)[i]); \
303 #define OC_DBG(...) OC_LOG("D", __VA_ARGS__)
304 #define OC_WRN(...) OC_LOG("W", __VA_ARGS__)
305 #define OC_ERR(...) OC_LOG("E", __VA_ARGS__)
312 #define OC_LOGipaddr(endpoint)
313 #define OC_LOGbytes(bytes, length)
317 #define OC_ERR(...) OC_LOG("E", __VA_ARGS__)
318 #define OC_WRN(...) OC_LOG("W", __VA_ARGS__)
320 #ifdef OC_DEBUG_OSCORE
321 #define OC_DBG_OSCORE(...) OC_LOG("OSCORE", __VA_ARGS__)
322 #define OC_DBG_SPAKE(...) OC_LOG("SPAKE", __VA_ARGS__)
323 #define OC_LOGbytes_OSCORE(bytes, length) \
324 OC_LOGbytes_internal("OSCORE", bytes, length)
325 #define OC_LOGbytes_SPAKE(bytes, length) \
326 OC_LOGbytes_internal("SPAKE", bytes, length)
328 #define OC_DBG_OSCORE(...)
329 #define OC_DBG_SPAKE(...)
330 #define OC_LOGbytes_OSCORE(bytes, length)
331 #define OC_LOGbytes_SPAKE(bytes, length)