libcoap 4.3.5-develop-379c7f4
Loading...
Searching...
No Matches
coap_debug.c File Reference

Debug utilities. More...

#include "coap3/coap_libcoap_build.h"
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
Include dependency graph for coap_debug.c:

Go to the source code of this file.

Data Structures

struct  packet_num_interval

Macros

#define min(a, b)
#define INET6_ADDRSTRLEN   46
#define COAP_DO_SHOW_OUTPUT_LINE
#define USE_BUF_SIZE   COAP_DEBUG_BUF_SIZE
#define COAP_DEBUG_INTERVAL_COUNT   10

Functions

const char * coap_package_name (void)
 Get the library package name.
const char * coap_package_version (void)
 Get the library package version.
const char * coap_package_build (void)
 Get the library package build.
void coap_set_show_pdu_output (int use_fprintf)
 Defines the output mode for the coap_show_pdu() function.
void coap_enable_pdu_data_output (int enable_data)
 Defines whether the data is to be output or not for the coap_show_pdu() function.
coap_log_t coap_get_log_level (void)
 Get the current logging level.
void coap_set_log_level (coap_log_t level)
 Sets the log level to the specified value.
const char * coap_log_level_desc (coap_log_t level)
 Get the current logging description.
COAP_STATIC_INLINE size_t print_timestamp (char *s, size_t len, coap_tick_t t)
static size_t strnlen (const char *s, size_t maxlen)
 A length-safe strlen() fake.
static size_t print_readable (const uint8_t *data, size_t len, unsigned char *result, size_t buflen, int encode_always)
int coap_snprintf (char *buffer, size_t buf_size, size_t *offset, const char *format,...)
 The equivalent to snprintf() functionality, but returning the actual characters added and defining the buffer offset in a separate parameter.
size_t coap_print_addr (const coap_address_t *addr, unsigned char *buf, size_t len)
 Print the address into the defined buffer.
const char * coap_print_ip_addr (const coap_address_t *addr, char *buf, size_t len)
 Print the IP address into the defined buffer.
static const char * msg_type_string (uint16_t t)
 Returns a textual description of the message type t.
static const char * msg_code_string (uint16_t c)
 Returns a textual description of the method or response code.
const char * coap_option_string (coap_pdu_code_t code, coap_option_num_t number)
 Returns a textual description of the option name.
static unsigned int print_content_format (unsigned int format_type, unsigned char *result, unsigned int buflen)
COAP_STATIC_INLINE int is_binary (int content_format)
 Returns 1 if the given content_format is either unknown or known to carry binary data.
void coap_show_pdu (coap_log_t level, const coap_pdu_t *pdu)
 Display the contents of the specified pdu.
void coap_show_tls_version (coap_log_t level)
 Display the current (D)TLS library linked with and built for version.
char * coap_string_tls_version (char *buffer, size_t bufsize)
 Build a string containing the current (D)TLS library linked with and built for version.
char * coap_string_tls_support (char *buffer, size_t bufsize)
 Build a string containing the current (D)TLS library support.
void coap_set_log_handler (coap_log_handler_t handler)
 Add a custom log callback handler.
void coap_log_impl (coap_log_t level, const char *format,...)
 Writes the given text to COAP_ERR_FD (for level <= COAP_LOG_CRIT) or COAP_DEBUG_FD (for level >= COAP_LOG_ERR).
static int coap_debug_set_packet_common (const char *loss_level, struct packet_num_interval *intervals, int *num_intervals, uint16_t *level, size_t *count)
int coap_debug_set_packet_loss (const char *loss_level)
 Set the packet loss level for testing.
int coap_debug_send_packet (void)
 Check to see whether a packet should be sent or not.
int coap_debug_set_packet_fail (const char *fail_level)
 Set the packet transmit fail level for testing.
int coap_debug_set_packet_drop (const char *drop_level)
 Set the packet receive fail level for testing.
int coap_debug_recv_packet (void)
 Check to see whether an incoming packet should be dropped or not.
void coap_debug_reset (void)
 Reset all the defined logging parameters.

Variables

static coap_log_t maxlog = COAP_LOG_WARN
static int use_fprintf_for_show_pdu = 1
static int enable_data_for_show_pdu = 1
static const char * loglevels []
static coap_log_handler_t log_handler = NULL
static struct packet_num_interval packet_loss_intervals [COAP_DEBUG_INTERVAL_COUNT]
static int num_packet_loss_intervals = 0
static uint16_t packet_loss_level = 0
static size_t send_packet_count = 0
struct packet_num_interval packet_fail_intervals [COAP_DEBUG_INTERVAL_COUNT]
static int num_packet_fail_intervals = 0
static uint16_t packet_fail_level = 0
static size_t recv_packet_count = 0
struct packet_num_interval packet_drop_intervals [COAP_DEBUG_INTERVAL_COUNT]
static int num_packet_drop_intervals = 0
static uint16_t packet_drop_level = 0

Detailed Description

Debug utilities.

Definition in file coap_debug.c.

Macro Definition Documentation

◆ COAP_DEBUG_INTERVAL_COUNT

#define COAP_DEBUG_INTERVAL_COUNT   10

Definition at line 1450 of file coap_debug.c.

◆ COAP_DO_SHOW_OUTPUT_LINE

#define COAP_DO_SHOW_OUTPUT_LINE
Value:
do { \
fprintf(COAP_DEBUG_FD, "%s", outbuf); \
} \
else { \
coap_log(level, "%s", outbuf); \
} \
} while (0)
static int use_fprintf_for_show_pdu
Definition coap_debug.c:70
#define COAP_DEBUG_FD
Used for output for COAP_LOG_OSCORE to COAP_LOG_ERR.
Definition coap_debug.h:37

Definition at line 811 of file coap_debug.c.

◆ INET6_ADDRSTRLEN

#define INET6_ADDRSTRLEN   46

Definition at line 259 of file coap_debug.c.

◆ min

#define min ( a,
b )
Value:
((a) < (b) ? (a) : (b))

Definition at line 255 of file coap_debug.c.

◆ USE_BUF_SIZE

#define USE_BUF_SIZE   COAP_DEBUG_BUF_SIZE

Definition at line 839 of file coap_debug.c.

Function Documentation

◆ coap_debug_recv_packet()

int coap_debug_recv_packet ( void )

Check to see whether an incoming packet should be dropped or not.

Internal function

Returns
1 if packet is to be let through, 0 if packet is to be dropped.

Definition at line 1577 of file coap_debug.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ coap_debug_reset()

void coap_debug_reset ( void )

Reset all the defined logging parameters.

Internal function

Definition at line 1602 of file coap_debug.c.

Here is the caller graph for this function:

◆ coap_debug_send_packet()

int coap_debug_send_packet ( void )

Check to see whether a packet should be sent or not.

Internal function

Returns
1 if packet is to be sent, 0 if packet is to be dropped.

Definition at line 1521 of file coap_debug.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ coap_debug_set_packet_common()

int coap_debug_set_packet_common ( const char * loss_level,
struct packet_num_interval * intervals,
int * num_intervals,
uint16_t * level,
size_t * count )
static

Definition at line 1469 of file coap_debug.c.

Here is the caller graph for this function:

◆ coap_debug_set_packet_drop()

int coap_debug_set_packet_drop ( const char * drop_level)

Set the packet receive fail level for testing.

This can be in one of two forms.

Percentage : 0% to 100%. Use the specified probability. 0% is receive all packets, 100% is drop all packets.

List: A comma separated list of numbers or number ranges that are the packets to fail.

Parameters
drop_levelThe defined drop level (percentage or list).
Returns
1 If drop level set, 0 if there is an error.

Definition at line 1571 of file coap_debug.c.

Here is the call graph for this function:

◆ coap_debug_set_packet_fail()

int coap_debug_set_packet_fail ( const char * fail_level)

Set the packet transmit fail level for testing.

This can be in one of two forms.

Percentage : 0% to 100%. Use the specified probability. 0% is send all packets, 100% is fail all packets.

List: A comma separated list of numbers or number ranges that are the packets to fail.

Parameters
fail_levelThe defined fail level (percentage or list).
Returns
1 If fail level set, 0 if there is an error.

Definition at line 1565 of file coap_debug.c.

Here is the call graph for this function:

◆ coap_debug_set_packet_loss()

int coap_debug_set_packet_loss ( const char * loss_level)

Set the packet loss level for testing.

This can be in one of two forms.

Percentage : 0% to 100%. Use the specified probability. 0% is send all packets, 100% is drop all packets.

List: A comma separated list of numbers or number ranges that are the packets to drop.

Parameters
loss_levelThe defined loss level (percentage or list).
Returns
1 If loss level set, 0 if there is an error.

Definition at line 1515 of file coap_debug.c.

Here is the call graph for this function:

◆ coap_option_string()

const char * coap_option_string ( coap_pdu_code_t code,
coap_option_num_t number )

Returns a textual description of the option name.

Output ascii representation of option number, if known.

Definition at line 640 of file coap_debug.c.

Here is the caller graph for this function:

◆ coap_snprintf()

int coap_snprintf ( char * buffer,
size_t buf_size,
size_t * offset,
const char * format,
... )

The equivalent to snprintf() functionality, but returning the actual characters added and defining the buffer offset in a separate parameter.

Internal function

Parameters
bufferThe start of the buffer to write into.
buf_sizeThe size of the buffer to write into.
offsetThe start offset into buffer, updated after buffer is updated with the currently used length of buffer, not including the NUL terminator.
formatThe formatting string to use as per printf().
Returns
The number of characters written to the string. If 0, an error or no more data can be put in buffer.

Definition at line 230 of file coap_debug.c.

Here is the caller graph for this function:

◆ is_binary()

COAP_STATIC_INLINE int is_binary ( int content_format)

Returns 1 if the given content_format is either unknown or known to carry binary data.

The return value 0 hence indicates printable data which is also assumed if content_format is 01.

Definition at line 803 of file coap_debug.c.

Here is the caller graph for this function:

◆ msg_code_string()

const char * msg_code_string ( uint16_t c)
static

Returns a textual description of the method or response code.

Definition at line 618 of file coap_debug.c.

Here is the caller graph for this function:

◆ msg_type_string()

const char * msg_type_string ( uint16_t t)
static

Returns a textual description of the message type t.

Definition at line 610 of file coap_debug.c.

Here is the caller graph for this function:

◆ print_content_format()

unsigned int print_content_format ( unsigned int format_type,
unsigned char * result,
unsigned int buflen )
static

Definition at line 736 of file coap_debug.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ print_readable()

size_t print_readable ( const uint8_t * data,
size_t len,
unsigned char * result,
size_t buflen,
int encode_always )
static

Definition at line 192 of file coap_debug.c.

Here is the caller graph for this function:

◆ print_timestamp()

COAP_STATIC_INLINE size_t print_timestamp ( char * s,
size_t len,
coap_tick_t t )

Definition at line 160 of file coap_debug.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ strnlen()

size_t strnlen ( const char * s,
size_t maxlen )
inlinestatic

A length-safe strlen() fake.

Parameters
sThe string to count characters != 0.
maxlenThe maximum length of s.
Returns
The length of s.

Definition at line 183 of file coap_debug.c.

Variable Documentation

◆ enable_data_for_show_pdu

int enable_data_for_show_pdu = 1
static

Definition at line 71 of file coap_debug.c.

◆ log_handler

coap_log_handler_t log_handler = NULL
static

Definition at line 1363 of file coap_debug.c.

◆ loglevels

const char* loglevels[]
static
Initial value:
= {
"EMRG", "ALRT", "CRIT", "ERR ", "WARN", "NOTE", "INFO", "DEBG", "OSC ",
"Emrg", "Alrt", "Crit", "Err ", "Warn", "Note", "Info", "Debg"
}

Definition at line 116 of file coap_debug.c.

◆ maxlog

coap_log_t maxlog = COAP_LOG_WARN
static

Definition at line 63 of file coap_debug.c.

◆ num_packet_drop_intervals

int num_packet_drop_intervals = 0
static

Definition at line 1465 of file coap_debug.c.

◆ num_packet_fail_intervals

int num_packet_fail_intervals = 0
static

Definition at line 1461 of file coap_debug.c.

◆ num_packet_loss_intervals

int num_packet_loss_intervals = 0
static

Definition at line 1457 of file coap_debug.c.

◆ packet_drop_intervals

struct packet_num_interval packet_drop_intervals[COAP_DEBUG_INTERVAL_COUNT]

Definition at line 1464 of file coap_debug.c.

◆ packet_drop_level

uint16_t packet_drop_level = 0
static

Definition at line 1466 of file coap_debug.c.

◆ packet_fail_intervals

struct packet_num_interval packet_fail_intervals[COAP_DEBUG_INTERVAL_COUNT]

Definition at line 1460 of file coap_debug.c.

◆ packet_fail_level

uint16_t packet_fail_level = 0
static

Definition at line 1462 of file coap_debug.c.

◆ packet_loss_intervals

struct packet_num_interval packet_loss_intervals[COAP_DEBUG_INTERVAL_COUNT]
static

◆ packet_loss_level

uint16_t packet_loss_level = 0
static

Definition at line 1458 of file coap_debug.c.

◆ recv_packet_count

size_t recv_packet_count = 0
static

Definition at line 1463 of file coap_debug.c.

◆ send_packet_count

size_t send_packet_count = 0
static

Definition at line 1459 of file coap_debug.c.

◆ use_fprintf_for_show_pdu

int use_fprintf_for_show_pdu = 1
static

Definition at line 70 of file coap_debug.c.