From f304b2c914796e5cf070b02b6e940e62b7d90d31 Mon Sep 17 00:00:00 2001 From: Gaetan Perrot Date: Mon, 8 Jul 2024 12:43:01 +0900 Subject: [PATCH] clang-format: run clang-format on libcsp Run clang-format on whole project to ensure code style consistency. Signed-off-by: Gaetan Perrot --- examples/csp_arch.c | 98 +++++----- examples/csp_client.c | 200 ++++++++++--------- examples/csp_server.c | 258 ++++++++++++------------- examples/csp_server_client.c | 191 +++++++++--------- examples/csp_server_client_windows.c | 2 +- examples/zmqproxy.c | 17 +- include/csp/arch/csp_queue.h | 6 +- include/csp/crypto/csp_hmac.h | 2 +- include/csp/crypto/csp_sha1.h | 12 +- include/csp/csp.h | 120 ++++++------ include/csp/csp_cmp.h | 18 +- include/csp/csp_crc32.h | 4 +- include/csp/csp_debug.h | 66 ++++--- include/csp/csp_error.h | 34 ++-- include/csp/csp_hooks.h | 4 +- include/csp/csp_iflist.h | 2 +- include/csp/csp_interface.h | 35 ++-- include/csp/csp_promisc.h | 2 +- include/csp/csp_rtable.h | 8 +- include/csp/csp_sfp.h | 7 +- include/csp/csp_types.h | 112 ++++++----- include/csp/drivers/can_zephyr.h | 8 +- include/csp/interfaces/csp_if_can.h | 82 ++++---- include/csp/interfaces/csp_if_eth.h | 15 +- include/csp/interfaces/csp_if_i2c.h | 1 - include/csp/interfaces/csp_if_kiss.h | 20 +- include/csp/interfaces/csp_if_zmqhub.h | 8 +- src/csp_bridge.c | 10 +- src/csp_buffer.c | 5 +- src/csp_conn.c | 39 ++-- src/csp_conn.h | 6 +- src/csp_crc32.c | 11 +- src/csp_debug.c | 8 +- src/csp_dedup.c | 4 +- src/csp_dedup.h | 1 - src/csp_id.c | 8 +- src/csp_iflist.c | 27 ++- src/csp_init.c | 1 - src/csp_io.c | 19 +- src/csp_io.h | 8 +- src/csp_macro.h | 2 +- src/csp_port.c | 1 - src/csp_rdp.c | 12 +- src/csp_rdp_queue.c | 80 ++++---- src/csp_route.c | 14 +- src/csp_rtable_cidr.c | 20 +- src/csp_rtable_stdio.c | 4 +- src/csp_semaphore.h | 18 +- src/csp_service_handler.c | 2 +- src/csp_sfp.c | 14 +- src/csp_yaml.c | 21 +- 51 files changed, 812 insertions(+), 855 deletions(-) diff --git a/examples/csp_arch.c b/examples/csp_arch.c index 8cd3f4ba0..ba6c286b1 100644 --- a/examples/csp_arch.c +++ b/examples/csp_arch.c @@ -8,59 +8,57 @@ #include #include - int main(int argc, char * argv[]) { + // clock + csp_timestamp_t csp_clock = {}; + csp_clock_get_time(&csp_clock); + assert(csp_clock.tv_sec != 0); + csp_print("csp_clock_get_time(..) -> sec:nsec = %" PRIu32 ":%" PRIu32 "\n", csp_clock.tv_sec, csp_clock.tv_nsec); - // clock - csp_timestamp_t csp_clock = {}; - csp_clock_get_time(&csp_clock); - assert(csp_clock.tv_sec != 0); - csp_print("csp_clock_get_time(..) -> sec:nsec = %"PRIu32":%"PRIu32"\n", csp_clock.tv_sec, csp_clock.tv_nsec); - - // relative time - const uint32_t msec1 = csp_get_ms(); - const uint32_t msec2 = csp_get_ms_isr(); - const uint32_t sec1 = csp_get_s(); - const uint32_t sec2 = csp_get_s_isr(); - sleep(2); - assert(csp_get_ms() >= (msec1 + 500)); - assert(csp_get_ms_isr() >= (msec2 + 500)); - assert(csp_get_s() >= (sec1 + 1)); - assert(csp_get_s_isr() >= (sec2 + 1)); + // relative time + const uint32_t msec1 = csp_get_ms(); + const uint32_t msec2 = csp_get_ms_isr(); + const uint32_t sec1 = csp_get_s(); + const uint32_t sec2 = csp_get_s_isr(); + sleep(2); + assert(csp_get_ms() >= (msec1 + 500)); + assert(csp_get_ms_isr() >= (msec2 + 500)); + assert(csp_get_s() >= (sec1 + 1)); + assert(csp_get_s_isr() >= (sec2 + 1)); - // queue handling - uint32_t value; - csp_static_queue_t sq; - csp_queue_handle_t q; - char buf[3 * sizeof(value)]; - q = csp_queue_create_static(3, sizeof(value), buf, &sq); - assert(csp_queue_size(q) == 0); - assert(csp_queue_size_isr(q) == 0); - assert(csp_queue_dequeue(q, &value, 0) == CSP_QUEUE_ERROR); - assert(csp_queue_dequeue(q, &value, 200) == CSP_QUEUE_ERROR); - assert(csp_queue_dequeue_isr(q, &value, NULL) == CSP_QUEUE_ERROR); - value = 1; - assert(csp_queue_enqueue(q, &value, 0) == CSP_QUEUE_OK); - value = 2; - assert(csp_queue_enqueue(q, &value, 200) == CSP_QUEUE_OK); - value = 3; - assert(csp_queue_enqueue_isr(q, &value, NULL) == CSP_QUEUE_OK); - assert(csp_queue_size(q) == 3); - assert(csp_queue_size_isr(q) == 3); - value = 10; - assert(csp_queue_enqueue(q, &value, 0) == CSP_QUEUE_ERROR); - value = 20; - assert(csp_queue_enqueue(q, &value, 200) == CSP_QUEUE_ERROR); - value = 30; - assert(csp_queue_enqueue_isr(q, &value, NULL) == CSP_QUEUE_ERROR); - value = 100; - assert(csp_queue_dequeue(q, &value, 0) == CSP_QUEUE_OK); - assert(value == 1); - assert(csp_queue_dequeue(q, &value, 200) == CSP_QUEUE_OK); - assert(value == 2); - assert(csp_queue_dequeue_isr(q, &value, NULL) == CSP_QUEUE_OK); - assert(value == 3); + // queue handling + uint32_t value; + csp_static_queue_t sq; + csp_queue_handle_t q; + char buf[3 * sizeof(value)]; + q = csp_queue_create_static(3, sizeof(value), buf, &sq); + assert(csp_queue_size(q) == 0); + assert(csp_queue_size_isr(q) == 0); + assert(csp_queue_dequeue(q, &value, 0) == CSP_QUEUE_ERROR); + assert(csp_queue_dequeue(q, &value, 200) == CSP_QUEUE_ERROR); + assert(csp_queue_dequeue_isr(q, &value, NULL) == CSP_QUEUE_ERROR); + value = 1; + assert(csp_queue_enqueue(q, &value, 0) == CSP_QUEUE_OK); + value = 2; + assert(csp_queue_enqueue(q, &value, 200) == CSP_QUEUE_OK); + value = 3; + assert(csp_queue_enqueue_isr(q, &value, NULL) == CSP_QUEUE_OK); + assert(csp_queue_size(q) == 3); + assert(csp_queue_size_isr(q) == 3); + value = 10; + assert(csp_queue_enqueue(q, &value, 0) == CSP_QUEUE_ERROR); + value = 20; + assert(csp_queue_enqueue(q, &value, 200) == CSP_QUEUE_ERROR); + value = 30; + assert(csp_queue_enqueue_isr(q, &value, NULL) == CSP_QUEUE_ERROR); + value = 100; + assert(csp_queue_dequeue(q, &value, 0) == CSP_QUEUE_OK); + assert(value == 1); + assert(csp_queue_dequeue(q, &value, 200) == CSP_QUEUE_OK); + assert(value == 2); + assert(csp_queue_dequeue_isr(q, &value, NULL) == CSP_QUEUE_OK); + assert(value == 3); - return 0; + return 0; } diff --git a/examples/csp_client.c b/examples/csp_client.c index 3d4c9353d..12c13f250 100644 --- a/examples/csp_client.c +++ b/examples/csp_client.c @@ -10,12 +10,11 @@ #include #include - /* This function must be provided in arch specific way */ int router_start(void); /* Server port, the port the server listens on for incoming connections from the client. */ -#define SERVER_PORT 10 +#define SERVER_PORT 10 /* Commandline options */ static uint8_t server_address = 0; @@ -38,30 +37,29 @@ enum DeviceType { static struct option long_options[] = { {"kiss-device", required_argument, 0, 'k'}, #if (CSP_HAVE_LIBSOCKETCAN) - #define OPTION_c "c:" - {"can-device", required_argument, 0, 'c'}, +#define OPTION_c "c:" + {"can-device", required_argument, 0, 'c'}, #else - #define OPTION_c +#define OPTION_c #endif #if (CSP_HAVE_LIBZMQ) - #define OPTION_z "z:" - {"zmq-device", required_argument, 0, 'z'}, +#define OPTION_z "z:" + {"zmq-device", required_argument, 0, 'z'}, #else - #define OPTION_z +#define OPTION_z #endif #if (CSP_USE_RTABLE) - #define OPTION_R "R:" - {"rtable", required_argument, 0, 'R'}, +#define OPTION_R "R:" + {"rtable", required_argument, 0, 'R'}, #else - #define OPTION_R +#define OPTION_R #endif - {"interface-address", required_argument, 0, 'a'}, - {"connect-to", required_argument, 0, 'C'}, - {"test-mode", no_argument, 0, 't'}, - {"test-mode-with-sec", required_argument, 0, 'T'}, - {"help", no_argument, 0, 'h'}, - {0, 0, 0, 0} -}; + {"interface-address", required_argument, 0, 'a'}, + {"connect-to", required_argument, 0, 'C'}, + {"test-mode", no_argument, 0, 't'}, + {"test-mode-with-sec", required_argument, 0, 'T'}, + {"help", no_argument, 0, 'h'}, + {0, 0, 0, 0}}; void print_help() { csp_print("Usage: csp_client [options]\n"); @@ -78,52 +76,52 @@ void print_help() { csp_print(" -R set routing table\n"); } if (1) { - csp_print(" -a
set interface address\n" - " -C
connect to server at address\n" - " -t enable test mode\n" - " -T enable test mode with running time in seconds\n" - " -h print help\n"); + csp_print( + " -a
set interface address\n" + " -C
connect to server at address\n" + " -t enable test mode\n" + " -T enable test mode with running time in seconds\n" + " -h print help\n"); } } -csp_iface_t * add_interface(enum DeviceType device_type, const char * device_name) -{ - csp_iface_t * default_iface = NULL; +csp_iface_t * add_interface(enum DeviceType device_type, const char * device_name) { + csp_iface_t * default_iface = NULL; if (device_type == DEVICE_KISS) { - csp_usart_conf_t conf = { + csp_usart_conf_t conf = { .device = device_name, - .baudrate = 115200, /* supported on all platforms */ - .databits = 8, - .stopbits = 1, - .paritysetting = 0, + .baudrate = 115200, /* supported on all platforms */ + .databits = 8, + .stopbits = 1, + .paritysetting = 0, }; - int error = csp_usart_open_and_add_kiss_interface(&conf, CSP_IF_KISS_DEFAULT_NAME, &default_iface); - if (error != CSP_ERR_NONE) { - csp_print("failed to add KISS interface [%s], error: %d\n", device_name, error); - exit(1); - } + int error = csp_usart_open_and_add_kiss_interface(&conf, CSP_IF_KISS_DEFAULT_NAME, &default_iface); + if (error != CSP_ERR_NONE) { + csp_print("failed to add KISS interface [%s], error: %d\n", device_name, error); + exit(1); + } default_iface->addr = client_address; - default_iface->is_default = 1; - } + default_iface->is_default = 1; + } if (CSP_HAVE_LIBSOCKETCAN && (device_type == DEVICE_CAN)) { int error = csp_can_socketcan_open_and_add_interface(device_name, CSP_IF_CAN_DEFAULT_NAME, client_address, 1000000, true, &default_iface); - if (error != CSP_ERR_NONE) { + if (error != CSP_ERR_NONE) { csp_print("failed to add CAN interface [%s], error: %d\n", device_name, error); - exit(1); - } - default_iface->is_default = 1; - } + exit(1); + } + default_iface->is_default = 1; + } if (CSP_HAVE_LIBZMQ && (device_type == DEVICE_ZMQ)) { - int error = csp_zmqhub_init(client_address, device_name, 0, &default_iface); - if (error != CSP_ERR_NONE) { - csp_print("failed to add ZMQ interface [%s], error: %d\n", device_name, error); - exit(1); - } - default_iface->is_default = 1; - } + int error = csp_zmqhub_init(client_address, device_name, 0, &default_iface); + if (error != CSP_ERR_NONE) { + csp_print("failed to add ZMQ interface [%s], error: %d\n", device_name, error); + exit(1); + } + default_iface->is_default = 1; + } return default_iface; } @@ -138,66 +136,66 @@ int main(int argc, char * argv[]) { struct timespec start_time; unsigned int count; int ret = EXIT_SUCCESS; - int opt; + int opt; while ((opt = getopt_long(argc, argv, OPTION_c OPTION_z OPTION_R "k:a:C:tT:h", long_options, NULL)) != -1) { - switch (opt) { - case 'c': + switch (opt) { + case 'c': device_name = optarg; device_type = DEVICE_CAN; - break; - case 'k': + break; + case 'k': device_name = optarg; device_type = DEVICE_KISS; - break; - case 'z': + break; + case 'z': device_name = optarg; device_type = DEVICE_ZMQ; - break; + break; #if (CSP_USE_RTABLE) - case 'R': - rtable = optarg; - break; + case 'R': + rtable = optarg; + break; #endif - case 'a': - client_address = atoi(optarg); - break; - case 'C': - server_address = atoi(optarg); - break; - case 't': - test_mode = true; - break; - case 'T': - test_mode = true; - run_duration_in_sec = atoi(optarg); - break; - case 'h': + case 'a': + client_address = atoi(optarg); + break; + case 'C': + server_address = atoi(optarg); + break; + case 't': + test_mode = true; + break; + case 'T': + test_mode = true; + run_duration_in_sec = atoi(optarg); + break; + case 'h': print_help(); exit(EXIT_SUCCESS); - case '?': - // Invalid option or missing argument + case '?': + // Invalid option or missing argument print_help(); - exit(EXIT_FAILURE); - } - } + exit(EXIT_FAILURE); + } + } // Unless one of the interfaces are set, print a message and exit if (device_type == DEVICE_UNKNOWN) { csp_print("One and only one of the interfaces can be set.\n"); - print_help(); - exit(EXIT_FAILURE); - } + print_help(); + exit(EXIT_FAILURE); + } - csp_print("Initialising CSP\n"); + csp_print("Initialising CSP\n"); - /* Init CSP */ - csp_init(); + /* Init CSP */ + csp_init(); - /* Start router */ - router_start(); + /* Start router */ + router_start(); - /* Add interface(s) */ + /* Add interface(s) */ default_iface = add_interface(device_type, device_name); /* Setup routing table */ @@ -213,18 +211,18 @@ int main(int argc, char * argv[]) { } } - csp_print("Connection table\r\n"); - csp_conn_print_table(); + csp_print("Connection table\r\n"); + csp_conn_print_table(); - csp_print("Interfaces\r\n"); - csp_iflist_print(); + csp_print("Interfaces\r\n"); + csp_iflist_print(); if (CSP_USE_RTABLE) { csp_print("Route table\r\n"); csp_rtable_print(); } - /* Start client work */ + /* Start client work */ csp_print("Client started\n"); clock_gettime(CLOCK_MONOTONIC, &start_time); count = 'A'; @@ -237,10 +235,10 @@ int main(int argc, char * argv[]) { /* Send ping to server, timeout 1000 mS, ping size 100 bytes */ int result = csp_ping(server_address, 1000, 100, CSP_O_NONE); csp_print("Ping address: %u, result %d [mS]\n", server_address, result); - // Increment successful_ping if ping was successful - if (result >= 0) { - ++successful_ping; - } + // Increment successful_ping if ping was successful + if (result >= 0) { + ++successful_ping; + } /* Send reboot request to server, the server has no actual implementation of csp_sys_reboot() and fails to reboot */ csp_reboot(server_address); @@ -273,7 +271,7 @@ int main(int argc, char * argv[]) { count++; /* 4. Set packet length */ - packet->length = (strlen((char *) packet->data) + 1); /* include the 0 termination */ + packet->length = (strlen((char *)packet->data) + 1); /* include the 0 termination */ /* 5. Send packet */ csp_send(conn, packet); @@ -299,7 +297,7 @@ int main(int argc, char * argv[]) { } } - /* Wait for execution to end (ctrl+c) */ + /* Wait for execution to end (ctrl+c) */ - return ret; + return ret; } diff --git a/examples/csp_server.c b/examples/csp_server.c index 18f85462d..dd37ca193 100644 --- a/examples/csp_server.c +++ b/examples/csp_server.c @@ -9,13 +9,12 @@ #include #include - /* These three functions must be provided in arch specific way */ int router_start(void); int server_start(void); /* Server port, the port the server listens on for incoming connections from the client. */ -#define SERVER_PORT 10 +#define SERVER_PORT 10 /* Commandline options */ static uint8_t server_address = 0; @@ -52,27 +51,27 @@ void server(void) { while (1) { /* Wait for a new connection, 10000 mS timeout */ - csp_conn_t *conn; + csp_conn_t * conn; if ((conn = csp_accept(&sock, 10000)) == NULL) { /* timeout */ continue; } /* Read packets on connection, timout is 100 mS */ - csp_packet_t *packet; + csp_packet_t * packet; while ((packet = csp_read(conn, 50)) != NULL) { switch (csp_conn_dport(conn)) { - case SERVER_PORT: - /* Process packet here */ - csp_print("Packet received on SERVER_PORT: %s\n", (char *) packet->data); - csp_buffer_free(packet); - ++server_received; - break; - - default: - /* Call the default CSP service handler, handle pings, buffer use, etc. */ - csp_service_handler(packet); - break; + case SERVER_PORT: + /* Process packet here */ + csp_print("Packet received on SERVER_PORT: %s\n", (char *)packet->data); + csp_buffer_free(packet); + ++server_received; + break; + + default: + /* Call the default CSP service handler, handle pings, buffer use, etc. */ + csp_service_handler(packet); + break; } } @@ -85,35 +84,34 @@ void server(void) { /* End of server task */ static struct option long_options[] = { - {"kiss-device", required_argument, 0, 'k'}, + {"kiss-device", required_argument, 0, 'k'}, #if (CSP_HAVE_LIBSOCKETCAN) - #define OPTION_c "c:" - {"can-device", required_argument, 0, 'c'}, +#define OPTION_c "c:" + {"can-device", required_argument, 0, 'c'}, #else - #define OPTION_c +#define OPTION_c #endif #if (CSP_HAVE_LIBZMQ) - #define OPTION_z "z:" - {"zmq-device", required_argument, 0, 'z'}, +#define OPTION_z "z:" + {"zmq-device", required_argument, 0, 'z'}, #else - #define OPTION_z +#define OPTION_z #endif #if (CSP_USE_RTABLE) - #define OPTION_R "R:" - {"rtable", required_argument, 0, 'R'}, +#define OPTION_R "R:" + {"rtable", required_argument, 0, 'R'}, #else - #define OPTION_R +#define OPTION_R #endif - {"interface-address", required_argument, 0, 'a'}, - {"connect-to", required_argument, 0, 'C'}, - {"test-mode", no_argument, 0, 't'}, - {"test-mode-with-sec", required_argument, 0, 'T'}, - {"help", no_argument, 0, 'h'}, - {0, 0, 0, 0} -}; + {"interface-address", required_argument, 0, 'a'}, + {"connect-to", required_argument, 0, 'C'}, + {"test-mode", no_argument, 0, 't'}, + {"test-mode-with-sec", required_argument, 0, 'T'}, + {"help", no_argument, 0, 'h'}, + {0, 0, 0, 0}}; void print_help() { - csp_print("Usage: csp_server [options]\n"); + csp_print("Usage: csp_server [options]\n"); if (CSP_HAVE_LIBSOCKETCAN) { csp_print(" -c set CAN device\n"); } @@ -127,51 +125,51 @@ void print_help() { csp_print(" -R set routing table\n"); } if (1) { - csp_print(" -a
set interface address\n" - " -t enable test mode\n" - " -T enable test mode with running time in seconds\n" - " -h print help\n"); + csp_print( + " -a
set interface address\n" + " -t enable test mode\n" + " -T enable test mode with running time in seconds\n" + " -h print help\n"); } } -csp_iface_t * add_interface(enum DeviceType device_type, const char * device_name) -{ - csp_iface_t * default_iface = NULL; +csp_iface_t * add_interface(enum DeviceType device_type, const char * device_name) { + csp_iface_t * default_iface = NULL; - if (device_type == DEVICE_KISS) { - csp_usart_conf_t conf = { + if (device_type == DEVICE_KISS) { + csp_usart_conf_t conf = { .device = device_name, - .baudrate = 115200, /* supported on all platforms */ - .databits = 8, - .stopbits = 1, - .paritysetting = 0, + .baudrate = 115200, /* supported on all platforms */ + .databits = 8, + .stopbits = 1, + .paritysetting = 0, }; - int error = csp_usart_open_and_add_kiss_interface(&conf, CSP_IF_KISS_DEFAULT_NAME, &default_iface); - if (error != CSP_ERR_NONE) { - csp_print("failed to add KISS interface [%s], error: %d\n", device_name, error); - exit(1); - } + int error = csp_usart_open_and_add_kiss_interface(&conf, CSP_IF_KISS_DEFAULT_NAME, &default_iface); + if (error != CSP_ERR_NONE) { + csp_print("failed to add KISS interface [%s], error: %d\n", device_name, error); + exit(1); + } default_iface->addr = server_address; - default_iface->is_default = 1; - } - - if (CSP_HAVE_LIBSOCKETCAN && (device_type == DEVICE_CAN)) { - int error = csp_can_socketcan_open_and_add_interface(device_name, CSP_IF_CAN_DEFAULT_NAME, server_address, 1000000, true, &default_iface); - if (error != CSP_ERR_NONE) { - csp_print("failed to add CAN interface [%s], error: %d\n", device_name, error); - exit(1); - } - default_iface->is_default = 1; - } - - if (CSP_HAVE_LIBZMQ && (device_type == DEVICE_ZMQ)) { - int error = csp_zmqhub_init(server_address, device_name, 0, &default_iface); - if (error != CSP_ERR_NONE) { - csp_print("failed to add ZMQ interface [%s], error: %d\n", device_name, error); - exit(1); - } - default_iface->is_default = 1; - } + default_iface->is_default = 1; + } + + if (CSP_HAVE_LIBSOCKETCAN && (device_type == DEVICE_CAN)) { + int error = csp_can_socketcan_open_and_add_interface(device_name, CSP_IF_CAN_DEFAULT_NAME, server_address, 1000000, true, &default_iface); + if (error != CSP_ERR_NONE) { + csp_print("failed to add CAN interface [%s], error: %d\n", device_name, error); + exit(1); + } + default_iface->is_default = 1; + } + + if (CSP_HAVE_LIBZMQ && (device_type == DEVICE_ZMQ)) { + int error = csp_zmqhub_init(server_address, device_name, 0, &default_iface); + if (error != CSP_ERR_NONE) { + csp_print("failed to add ZMQ interface [%s], error: %d\n", device_name, error); + exit(1); + } + default_iface->is_default = 1; + } return default_iface; } @@ -183,67 +181,67 @@ int main(int argc, char * argv[]) { enum DeviceType device_type = DEVICE_UNKNOWN; const char * rtable __maybe_unused = NULL; csp_iface_t * default_iface; - int opt; + int opt; while ((opt = getopt_long(argc, argv, OPTION_c OPTION_z OPTION_R "k:a:tT:h", long_options, NULL)) != -1) { - switch (opt) { - case 'c': + switch (opt) { + case 'c': device_name = optarg; device_type = DEVICE_CAN; - break; - case 'k': + break; + case 'k': device_name = optarg; device_type = DEVICE_KISS; - break; - case 'z': + break; + case 'z': device_name = optarg; device_type = DEVICE_ZMQ; - break; + break; #if (CSP_USE_RTABLE) - case 'R': - rtable = optarg; - break; + case 'R': + rtable = optarg; + break; #endif - case 'a': - server_address = atoi(optarg); - break; - case 't': - test_mode = true; - break; - case 'T': - test_mode = true; + case 'a': + server_address = atoi(optarg); + break; + case 't': + test_mode = true; + break; + case 'T': + test_mode = true; run_duration_in_sec = atoi(optarg); - break; - case 'h': + break; + case 'h': print_help(); exit(EXIT_SUCCESS); - case '?': - // Invalid option or missing argument + case '?': + // Invalid option or missing argument print_help(); - exit(EXIT_FAILURE); - } - } + exit(EXIT_FAILURE); + } + } // If more than one of the interfaces are set, print a message and exit if (device_type == DEVICE_UNKNOWN) { csp_print("Only one of the interfaces can be set.\n"); - print_help(); - exit(EXIT_FAILURE); - } + print_help(); + exit(EXIT_FAILURE); + } - csp_print("Initialising CSP\n"); + csp_print("Initialising CSP\n"); - /* Init CSP */ - csp_init(); + /* Init CSP */ + csp_init(); - /* Start router */ - router_start(); + /* Start router */ + router_start(); - /* Add interface(s) */ + /* Add interface(s) */ default_iface = add_interface(device_type, device_name); /* Setup routing table */ - if (CSP_USE_RTABLE) { + if (CSP_USE_RTABLE) { if (rtable) { int error = csp_rtable_load(rtable); if (error < 1) { @@ -255,34 +253,34 @@ int main(int argc, char * argv[]) { } } - csp_print("Connection table\r\n"); - csp_conn_print_table(); + csp_print("Connection table\r\n"); + csp_conn_print_table(); - csp_print("Interfaces\r\n"); - csp_iflist_print(); + csp_print("Interfaces\r\n"); + csp_iflist_print(); if (CSP_USE_RTABLE) { csp_print("Route table\r\n"); csp_rtable_print(); } - /* Start server thread */ - server_start(); - - /* Wait for execution to end (ctrl+c) */ - while(1) { - sleep(run_duration_in_sec); - - if (test_mode) { - /* Test mode, check that server & client can exchange packets */ - if (server_received < 5) { - csp_print("Server received %u packets\n", server_received); - exit(EXIT_FAILURE); - } - csp_print("Server received %u packets\n", server_received); - exit(EXIT_SUCCESS); - } - } - - return 0; + /* Start server thread */ + server_start(); + + /* Wait for execution to end (ctrl+c) */ + while (1) { + sleep(run_duration_in_sec); + + if (test_mode) { + /* Test mode, check that server & client can exchange packets */ + if (server_received < 5) { + csp_print("Server received %u packets\n", server_received); + exit(EXIT_FAILURE); + } + csp_print("Server received %u packets\n", server_received); + exit(EXIT_SUCCESS); + } + } + + return 0; } diff --git a/examples/csp_server_client.c b/examples/csp_server_client.c index 859a917e1..747f4a772 100644 --- a/examples/csp_server_client.c +++ b/examples/csp_server_client.c @@ -8,14 +8,13 @@ #include #include - /* These three functions must be provided in arch specific way */ int router_start(void); int server_start(void); int client_start(void); /* Server port, the port the server listens on for incoming connections from the client. */ -#define MY_SERVER_PORT 10 +#define MY_SERVER_PORT 10 /* Commandline options */ static uint8_t server_address = 255; @@ -43,37 +42,35 @@ void server(void) { while (1) { /* Wait for a new connection, 10000 mS timeout */ - csp_conn_t *conn; + csp_conn_t * conn; if ((conn = csp_accept(&sock, 10000)) == NULL) { /* timeout */ continue; } /* Read packets on connection, timout is 100 mS */ - csp_packet_t *packet; + csp_packet_t * packet; while ((packet = csp_read(conn, 50)) != NULL) { switch (csp_conn_dport(conn)) { - case MY_SERVER_PORT: - /* Process packet here */ - csp_print("Packet received on MY_SERVER_PORT: %s\n", (char *) packet->data); - csp_buffer_free(packet); - ++server_received; - break; - - default: - /* Call the default CSP service handler, handle pings, buffer use, etc. */ - csp_service_handler(packet); - break; + case MY_SERVER_PORT: + /* Process packet here */ + csp_print("Packet received on MY_SERVER_PORT: %s\n", (char *)packet->data); + csp_buffer_free(packet); + ++server_received; + break; + + default: + /* Call the default CSP service handler, handle pings, buffer use, etc. */ + csp_service_handler(packet); + break; } } /* Close current connection */ csp_close(conn); - } return; - } /* End of server task */ @@ -91,7 +88,7 @@ void client(void) { /* Send ping to server, timeout 1000 mS, ping size 100 bytes */ int result = csp_ping(server_address, 1000, 100, CSP_O_NONE); csp_print("Ping address: %u, result %d [mS]\n", server_address, result); - (void) result; + (void)result; /* Send reboot request to server, the server has no actual implementation of csp_sys_reboot() and fails to reboot */ csp_reboot(server_address); @@ -116,13 +113,13 @@ void client(void) { } /* 3. Copy data to packet */ - memcpy(packet->data, "Hello world ", 12); - memcpy(packet->data + 12, &count, 1); - memset(packet->data + 13, 0, 1); - count++; + memcpy(packet->data, "Hello world ", 12); + memcpy(packet->data + 12, &count, 1); + memset(packet->data + 13, 0, 1); + count++; /* 4. Set packet length */ - packet->length = (strlen((char *) packet->data) + 1); /* include the 0 termination */ + packet->length = (strlen((char *)packet->data) + 1); /* include the 0 termination */ /* 5. Send packet */ csp_send(conn, packet); @@ -135,86 +132,86 @@ void client(void) { } /* End of client task */ -static void print_usage(void) -{ - csp_print("Usage:\n" - " -t enable test mode\n" - " -T enable test mode with running time in seconds\n" - " -h print help\n"); +static void print_usage(void) { + csp_print( + "Usage:\n" + " -t enable test mode\n" + " -T enable test mode with running time in seconds\n" + " -h print help\n"); } /* main - initialization of CSP and start of server/client tasks */ int main(int argc, char * argv[]) { - uint8_t address = 0; - int opt; - while ((opt = getopt(argc, argv, "tT:h")) != -1) { - switch (opt) { - case 'a': - address = atoi(optarg); - break; - case 'r': - server_address = atoi(optarg); - break; - case 't': - test_mode = true; - break; - case 'T': - test_mode = true; - run_duration_in_sec = atoi(optarg); - break; - case 'h': + uint8_t address = 0; + int opt; + while ((opt = getopt(argc, argv, "tT:h")) != -1) { + switch (opt) { + case 'a': + address = atoi(optarg); + break; + case 'r': + server_address = atoi(optarg); + break; + case 't': + test_mode = true; + break; + case 'T': + test_mode = true; + run_duration_in_sec = atoi(optarg); + break; + case 'h': print_usage(); exit(0); - break; - default: + break; + default: print_usage(); - exit(1); - break; - } - } - - csp_print("Initialising CSP"); - - /* Init CSP */ - csp_init(); - - /* Start router */ - router_start(); - - /* Add interface(s) */ - csp_iface_t * default_iface = NULL; - if (!default_iface) { - /* no interfaces configured - run server and client in process, using loopback interface */ - server_address = address; - } - - csp_print("Connection table\r\n"); - csp_conn_print_table(); - - csp_print("Interfaces\r\n"); - csp_iflist_print(); - - /* Start server thread */ - server_start(); - - /* Start client thread */ - client_start(); - - /* Wait for execution to end (ctrl+c) */ - while(1) { - sleep(run_duration_in_sec); - - if (test_mode) { - /* Test mode is intended for checking that host & client can exchange packets over loopback */ - if (server_received < 5) { - csp_print("Server received %u packets\n", server_received); - exit(1); - } - csp_print("Server received %u packets\n", server_received); - exit(0); - } - } - - return 0; + exit(1); + break; + } + } + + csp_print("Initialising CSP"); + + /* Init CSP */ + csp_init(); + + /* Start router */ + router_start(); + + /* Add interface(s) */ + csp_iface_t * default_iface = NULL; + if (!default_iface) { + /* no interfaces configured - run server and client in process, using loopback interface */ + server_address = address; + } + + csp_print("Connection table\r\n"); + csp_conn_print_table(); + + csp_print("Interfaces\r\n"); + csp_iflist_print(); + + /* Start server thread */ + server_start(); + + /* Start client thread */ + client_start(); + + /* Wait for execution to end (ctrl+c) */ + while (1) { + sleep(run_duration_in_sec); + + if (test_mode) { + /* Test mode is intended for checking that host & client can exchange packets over loopback */ + if (server_received < 5) { + csp_print("Server received %u packets\n", server_received); + exit(1); + } + csp_print("Server received %u packets\n", server_received); + exit(0); + } + } + + return 0; } diff --git a/examples/csp_server_client_windows.c b/examples/csp_server_client_windows.c index 94ce03d05..1b9a5ccb4 100644 --- a/examples/csp_server_client_windows.c +++ b/examples/csp_server_client_windows.c @@ -5,7 +5,7 @@ void server(void); void client(void); -static int csp_win_thread_create(unsigned int (* routine)(void *)) { +static int csp_win_thread_create(unsigned int (*routine)(void *)) { uintptr_t ret = _beginthreadex(NULL, 0, routine, NULL, 0, NULL); if (ret == 0) { diff --git a/examples/zmqproxy.c b/examples/zmqproxy.c index 709106c49..fc7d5a875 100644 --- a/examples/zmqproxy.c +++ b/examples/zmqproxy.c @@ -18,16 +18,16 @@ FILE * logfile; static void * task_capture(void * ctx) { - int ret; + int ret; csp_print("Capture/logging task listening on %s\n", sub_str); /* Subscriber (RX) */ void * subscriber = zmq_socket(ctx, ZMQ_SUB); ret = zmq_connect(subscriber, pub_str); - assert(ret == 0); + assert(ret == 0); ret = zmq_setsockopt(subscriber, ZMQ_SUBSCRIBE, "", 0); - assert(ret == 0); + assert(ret == 0); /* Allocated 'raw' CSP packet */ csp_packet_t * packet = malloc(1024); @@ -70,9 +70,8 @@ static void * task_capture(void * ctx) { /* Print header data */ csp_print("Packet: Src %u, Dst %u, Dport %u, Sport %u, Pri %u, Flags 0x%02X, Size %" PRIu16 "\n", - packet->id.src, packet->id.dst, packet->id.dport, - packet->id.sport, packet->id.pri, packet->id.flags, packet->length); - + packet->id.src, packet->id.dst, packet->id.dport, + packet->id.sport, packet->id.pri, packet->id.flags, packet->length); if (logfile) { const char * delimiter = "--------\n"; @@ -87,7 +86,7 @@ static void * task_capture(void * ctx) { int main(int argc, char ** argv) { - int ret; + int ret; csp_conf.version = 2; int opt; @@ -126,13 +125,13 @@ int main(int argc, char ** argv) { void * frontend = zmq_socket(ctx, ZMQ_XSUB); assert(frontend); - ret = zmq_bind(frontend, sub_str); + ret = zmq_bind(frontend, sub_str); assert(ret == 0); csp_print("Subscriber task listening on %s\n", sub_str); void * backend = zmq_socket(ctx, ZMQ_XPUB); assert(backend); - ret = zmq_bind(backend, pub_str); + ret = zmq_bind(backend, pub_str); assert(ret == 0); csp_print("Publisher task listening on %s\n", pub_str); diff --git a/include/csp/arch/csp_queue.h b/include/csp/arch/csp_queue.h index 1190ebd78..fb6052a4e 100644 --- a/include/csp/arch/csp_queue.h +++ b/include/csp/arch/csp_queue.h @@ -18,7 +18,7 @@ extern "C" { #endif -#define CSP_QUEUE_OK 0 +#define CSP_QUEUE_OK 0 #define CSP_QUEUE_ERROR -1 typedef void * csp_queue_handle_t; @@ -42,7 +42,7 @@ csp_queue_handle_t csp_queue_create_static(int length, size_t item_size, char * * @param[in] timeout timeout, time to wait for free space * @return #CSP_QUEUE_OK on success, otherwise a queue error code. */ -int csp_queue_enqueue(csp_queue_handle_t handle, const void *value, uint32_t timeout); +int csp_queue_enqueue(csp_queue_handle_t handle, const void * value, uint32_t timeout); /** * Enqueue (back) value from ISR. @@ -62,7 +62,7 @@ int csp_queue_enqueue_isr(csp_queue_handle_t handle, const void * value, int * p * @param[in] timeout timeout, time to wait for element in queue. * @return #CSP_QUEUE_OK on success, otherwise a queue error code. */ -int csp_queue_dequeue(csp_queue_handle_t handle, void *buf, uint32_t timeout); +int csp_queue_dequeue(csp_queue_handle_t handle, void * buf, uint32_t timeout); /** * Dequeue value (front) from ISR. diff --git a/include/csp/crypto/csp_hmac.h b/include/csp/crypto/csp_hmac.h index 500d4bf00..73f6d8e94 100644 --- a/include/csp/crypto/csp_hmac.h +++ b/include/csp/crypto/csp_hmac.h @@ -16,7 +16,7 @@ extern "C" { /** * Number of bytes from the HMAC calculation, that is appended to the CSP message. */ -#define CSP_HMAC_LENGTH 4 +#define CSP_HMAC_LENGTH 4 /** * Append HMAC to packet diff --git a/include/csp/crypto/csp_sha1.h b/include/csp/crypto/csp_sha1.h index 4d86cb4a9..9d3f7d38f 100644 --- a/include/csp/crypto/csp_sha1.h +++ b/include/csp/crypto/csp_sha1.h @@ -14,19 +14,19 @@ extern "C" { #endif /** The SHA1 block size in bytes */ -#define CSP_SHA1_BLOCKSIZE 64 +#define CSP_SHA1_BLOCKSIZE 64 /** The SHA1 digest (hash) size in bytes */ -#define CSP_SHA1_DIGESTSIZE 20 +#define CSP_SHA1_DIGESTSIZE 20 /** * SHA1 state. */ typedef struct { - uint64_t length; /**< Internal SHA1 state. */ - uint32_t state[5]; /**< Internal SHA1 state. */ - uint32_t curlen; /**< Internal SHA1 state. */ - uint8_t buf[CSP_SHA1_BLOCKSIZE]; /**< Internal SHA1 state. */ + uint64_t length; /**< Internal SHA1 state. */ + uint32_t state[5]; /**< Internal SHA1 state. */ + uint32_t curlen; /**< Internal SHA1 state. */ + uint8_t buf[CSP_SHA1_BLOCKSIZE]; /**< Internal SHA1 state. */ } csp_sha1_state_t; /** diff --git a/include/csp/csp.h b/include/csp/csp.h index ad713faa5..d2feeefa7 100644 --- a/include/csp/csp.h +++ b/include/csp/csp.h @@ -22,29 +22,28 @@ extern "C" { /** Max delay */ #define CSP_MAX_DELAY CSP_MAX_TIMEOUT -#define CSP_INFINITY CSP_MAX_TIMEOUT - +#define CSP_INFINITY CSP_MAX_TIMEOUT /** * CSP Debug Types */ enum csp_dedup_types { - CSP_DEDUP_OFF, /**< Deduplication off */ - CSP_DEDUP_FWD, /**< Deduplication on forwarding only */ - CSP_DEDUP_INCOMING, /**< Deduplication on incomfing only */ - CSP_DEDUP_ALL, /**< Deduplication on incoming and forwarding*/ + CSP_DEDUP_OFF, /**< Deduplication off */ + CSP_DEDUP_FWD, /**< Deduplication on forwarding only */ + CSP_DEDUP_INCOMING, /**< Deduplication on incomfing only */ + CSP_DEDUP_ALL, /**< Deduplication on incoming and forwarding*/ }; /** * CSP configuration. */ typedef struct csp_conf_s { - uint8_t version; /**< Protocol version to use (either 1 or 2) */ - const char *hostname; /**< Host name, returned by the #CSP_CMP_IDENT request */ - const char *model; /**< Model, returned by the #CSP_CMP_IDENT request */ - const char *revision; /**< Revision, returned by the #CSP_CMP_IDENT request */ - uint32_t conn_dfl_so; /**< Default connection options. Options will always be or'ed onto new connections, see csp_connect() */ - uint8_t dedup; /**< Enable CSP deduplication. 0 = off, 1 = always on, 2 = only on forwarded packets, */ + uint8_t version; /**< Protocol version to use (either 1 or 2) */ + const char * hostname; /**< Host name, returned by the #CSP_CMP_IDENT request */ + const char * model; /**< Model, returned by the #CSP_CMP_IDENT request */ + const char * revision; /**< Revision, returned by the #CSP_CMP_IDENT request */ + uint32_t conn_dfl_so; /**< Default connection options. Options will always be or'ed onto new connections, see csp_connect() */ + uint8_t dedup; /**< Enable CSP deduplication. 0 = off, 1 = always on, 2 = only on forwarded packets, */ } csp_conf_t; extern csp_conf_t csp_conf; @@ -80,7 +79,7 @@ void csp_id_copy(csp_id_t * target, csp_id_t * source); * @param[in] timeout timeout in mS to wait for a connection, use CSP_MAX_TIMEOUT for infinite timeout. * @return New connection on success, NULL on failure or timeout. */ -csp_conn_t *csp_accept(csp_socket_t *socket, uint32_t timeout); +csp_conn_t * csp_accept(csp_socket_t * socket, uint32_t timeout); /** * Read packet from a connection. @@ -90,7 +89,7 @@ csp_conn_t *csp_accept(csp_socket_t *socket, uint32_t timeout); * @param[in] timeout timeout in mS to wait for a packet, use CSP_MAX_TIMEOUT for infinite timeout. * @return Packet or NULL in case of failure or timeout. */ -csp_packet_t *csp_read(csp_conn_t *conn, uint32_t timeout); +csp_packet_t * csp_read(csp_conn_t * conn, uint32_t timeout); /** * Send packet on a connection. @@ -98,8 +97,8 @@ csp_packet_t *csp_read(csp_conn_t *conn, uint32_t timeout); * * @param[in] conn connection * @param[in] packet packet to send -*/ -void csp_send(csp_conn_t *conn, csp_packet_t *packet); + */ +void csp_send(csp_conn_t * conn, csp_packet_t * packet); /** * Change the default priority of the connection and send a packet. @@ -111,26 +110,26 @@ void csp_send(csp_conn_t *conn, csp_packet_t *packet); * @param[in] conn connection * @param[in] packet packet to send */ -void csp_send_prio(uint8_t prio, csp_conn_t *conn, csp_packet_t *packet); +void csp_send_prio(uint8_t prio, csp_conn_t * conn, csp_packet_t * packet); /** * Perform an entire request & reply transaction. * Creates a connection, send \a outbuf, wait for reply, copy reply to \a inbuf and close the connection. -* -* @param[in] prio priority, see #csp_prio_t -* @param[in] dst destination address -* @param[in] dst_port destination port -* @param[in] timeout timeout in mS to wait for a reply -* @param[in] outbuf outgoing data (request) -* @param[in] outlen length of data in \a outbuf (request) -* @param[out] inbuf user provided buffer for receiving data (reply) -* @param[in] inlen length of expected reply, -1 for unknown size (inbuf MUST be large enough), 0 for no reply. -* @param[in] opts connection options, see @ref CSP_CONNECTION_OPTIONS. -* -* Returns: -* int: 1 or reply size on success, 0 on failure (error, incoming length does not match, timeout) -*/ -int csp_transaction_w_opts(uint8_t prio, uint16_t dst, uint8_t dst_port, uint32_t timeout, void *outbuf, int outlen, void *inbuf, int inlen, uint32_t opts); + * + * @param[in] prio priority, see #csp_prio_t + * @param[in] dst destination address + * @param[in] dst_port destination port + * @param[in] timeout timeout in mS to wait for a reply + * @param[in] outbuf outgoing data (request) + * @param[in] outlen length of data in \a outbuf (request) + * @param[out] inbuf user provided buffer for receiving data (reply) + * @param[in] inlen length of expected reply, -1 for unknown size (inbuf MUST be large enough), 0 for no reply. + * @param[in] opts connection options, see @ref CSP_CONNECTION_OPTIONS. + * + * Returns: + * int: 1 or reply size on success, 0 on failure (error, incoming length does not match, timeout) + */ +int csp_transaction_w_opts(uint8_t prio, uint16_t dst, uint8_t dst_port, uint32_t timeout, void * outbuf, int outlen, void * inbuf, int inlen, uint32_t opts); /** * Perform an entire request & reply transaction. @@ -147,7 +146,7 @@ int csp_transaction_w_opts(uint8_t prio, uint16_t dst, uint8_t dst_port, uint32_ * @return 1 or reply size on success, 0 on failure (error, incoming length does not match, timeout) */ static inline int csp_transaction(uint8_t prio, uint16_t dest, uint8_t port, uint32_t timeout, void * outbuf, int outlen, void * inbuf, int inlen) { - return csp_transaction_w_opts(prio, dest, port, timeout, outbuf, outlen, inbuf, inlen, 0); + return csp_transaction_w_opts(prio, dest, port, timeout, outbuf, outlen, inbuf, inlen, 0); } /** @@ -162,7 +161,7 @@ static inline int csp_transaction(uint8_t prio, uint16_t dest, uint8_t port, uin * @param[in] inlen length of expected reply, -1 for unknown size (inbuf MUST be large enough), 0 for no reply. * @return 1 or reply size on success, 0 on failure (error, incoming length does not match, timeout) */ -int csp_transaction_persistent(csp_conn_t *conn, uint32_t timeout, void *outbuf, int outlen, void *inbuf, int inlen); +int csp_transaction_persistent(csp_conn_t * conn, uint32_t timeout, void * outbuf, int outlen, void * inbuf, int inlen); /** * Read data from a connection-less server socket. @@ -171,7 +170,7 @@ int csp_transaction_persistent(csp_conn_t *conn, uint32_t timeout, void *outbuf, * @param[in] timeout timeout in mS to wait for a packet, use #CSP_MAX_TIMEOUT for infinite timeout. * @return Packet on success, or NULL on failure or timeout. */ -csp_packet_t *csp_recvfrom(csp_socket_t *socket, uint32_t timeout); +csp_packet_t * csp_recvfrom(csp_socket_t * socket, uint32_t timeout); /** * Send a packet (without connection). @@ -183,7 +182,7 @@ csp_packet_t *csp_recvfrom(csp_socket_t *socket, uint32_t timeout); * @param[in] opts connection options, see @ref CSP_CONNECTION_OPTIONS. * @param[in] packet packet to send */ -void csp_sendto(uint8_t prio, uint16_t dst, uint8_t dst_port, uint8_t src_port, uint32_t opts, csp_packet_t *packet); +void csp_sendto(uint8_t prio, uint16_t dst, uint8_t dst_port, uint8_t src_port, uint32_t opts, csp_packet_t * packet); /** * Send a packet as a reply to a request (without a connection). @@ -206,8 +205,8 @@ void csp_sendto_reply(const csp_packet_t * request, csp_packet_t * reply, uint32 * @param[in] timeout unused. * @param[in] opts connection options, see @ref CSP_CONNECTION_OPTIONS. * @return Established connection or NULL on failure (no free connections, timeout). -*/ -csp_conn_t *csp_connect(uint8_t prio, uint16_t dst, uint8_t dst_port, uint32_t timeout, uint32_t opts); + */ +csp_conn_t * csp_connect(uint8_t prio, uint16_t dst, uint8_t dst_port, uint32_t timeout, uint32_t opts); /** * Close an open connection. @@ -216,7 +215,7 @@ csp_conn_t *csp_connect(uint8_t prio, uint16_t dst, uint8_t dst_port, uint32_t t * @param[in] conn connection. Closing a NULL connection is acceptable. * @return #CSP_ERR_NONE on success, otherwise an error code. */ -int csp_close(csp_conn_t *conn); +int csp_close(csp_conn_t * conn); /** * Close a socket, freeing it's RX queue and unbinding it from the associated @@ -225,7 +224,7 @@ int csp_close(csp_conn_t *conn); * @param[in] sock Socket * @return #CSP_ERR_NONE on success, otherwise an error code. */ -int csp_socket_close(csp_socket_t* sock); +int csp_socket_close(csp_socket_t * sock); /** * Return destination port of connection. @@ -233,7 +232,7 @@ int csp_socket_close(csp_socket_t* sock); * @param[in] conn connection * @return destination port of an incoming connection */ -int csp_conn_dport(csp_conn_t *conn); +int csp_conn_dport(csp_conn_t * conn); /** * Return source port of connection. @@ -241,7 +240,7 @@ int csp_conn_dport(csp_conn_t *conn); * @param[in] conn connection * @return source port of an incoming connection */ -int csp_conn_sport(csp_conn_t *conn); +int csp_conn_sport(csp_conn_t * conn); /** * Return destination address of connection. @@ -249,7 +248,7 @@ int csp_conn_sport(csp_conn_t *conn); * @param[in] conn connection * @return destination address of an incoming connection */ -int csp_conn_dst(csp_conn_t *conn); +int csp_conn_dst(csp_conn_t * conn); /** * Return source address of connection. @@ -257,7 +256,7 @@ int csp_conn_dst(csp_conn_t *conn); * @param[in] conn connection * @return source address of an incoming connection */ -int csp_conn_src(csp_conn_t *conn); +int csp_conn_src(csp_conn_t * conn); /** * Return flags of connection. @@ -265,7 +264,7 @@ int csp_conn_src(csp_conn_t *conn); * @param[in] conn connection * @return flags of an incoming connection, see @ref CSP_HEADER_FLAGS */ -int csp_conn_flags(csp_conn_t *conn); +int csp_conn_flags(csp_conn_t * conn); /** * Set socket to listen for incoming connections. @@ -273,8 +272,8 @@ int csp_conn_flags(csp_conn_t *conn); * @param[in] socket socket * @param[in] backlog max length of backlog queue. The backlog queue holds incoming connections, waiting to be returned by call to csp_accept(). * @return #CSP_ERR_NONE on success, otherwise an error code. -*/ -int csp_listen(csp_socket_t *socket, size_t backlog); + */ +int csp_listen(csp_socket_t * socket, size_t backlog); /** * Bind port to socket. @@ -283,8 +282,7 @@ int csp_listen(csp_socket_t *socket, size_t backlog); * @param[in] port port number to bind, use #CSP_ANY for all ports. Bindnig to a specific will take precedence over #CSP_ANY. * @return #CSP_ERR_NONE on success, otherwise an error code. */ -int csp_bind(csp_socket_t *socket, uint8_t port); - +int csp_bind(csp_socket_t * socket, uint8_t port); /** * Bind port to callback function. @@ -326,7 +324,7 @@ void csp_bridge_work(void); * * @param[in] packet first packet, obtained by using csp_read() */ -void csp_service_handler(csp_packet_t *packet); +void csp_service_handler(csp_packet_t * packet); /** * Send a single ping/echo packet. @@ -444,8 +442,8 @@ int csp_get_uptime(uint16_t node, uint32_t timeout, uint32_t * uptime); * */ void csp_rdp_set_opt(unsigned int window_size, unsigned int conn_timeout_ms, - unsigned int packet_timeout_ms, unsigned int delayed_acks, - unsigned int ack_timeout, unsigned int ack_delay_count); + unsigned int packet_timeout_ms, unsigned int delayed_acks, + unsigned int ack_timeout, unsigned int ack_delay_count); /** * Get RDP options. @see csp_rdp_set_opt() @@ -457,9 +455,9 @@ void csp_rdp_set_opt(unsigned int window_size, unsigned int conn_timeout_ms, * @param[out] ack_timeout acknowledgement timeout when delayed ACKs is enabled * @param[out] ack_delay_count send acknowledgement for every ack_delay_count packets */ -void csp_rdp_get_opt(unsigned int *window_size, unsigned int *conn_timeout_ms, - unsigned int *packet_timeout_ms, unsigned int *delayed_acks, - unsigned int *ack_timeout, unsigned int *ack_delay_count); +void csp_rdp_get_opt(unsigned int * window_size, unsigned int * conn_timeout_ms, + unsigned int * packet_timeout_ms, unsigned int * delayed_acks, + unsigned int * ack_timeout, unsigned int * ack_delay_count); /** * Set platform specific memory copy function. @@ -481,12 +479,12 @@ void csp_conn_print_table(void); * @param[in] len number of bytes to dump, starting from \a addr. * */ -void csp_hex_dump(const char *desc, void *addr, int len); +void csp_hex_dump(const char * desc, void * addr, int len); #else inline void csp_conn_print_table(void) {} -inline void csp_hex_dump(const char *desc, void *addr, int len) {} +inline void csp_hex_dump(const char * desc, void * addr, int len) {} #endif @@ -497,11 +495,11 @@ inline void csp_hex_dump(const char *desc, void *addr, int len) {} int csp_conn_print_table_str(char * str_buf, int str_size); #else inline int csp_conn_print_table_str(char * str_buf, int str_size) { - if (str_buf != NULL && str_size > 0) { - str_buf[0] = '\0'; - } + if (str_buf != NULL && str_size > 0) { + str_buf[0] = '\0'; + } - return CSP_ERR_NONE; + return CSP_ERR_NONE; } #endif diff --git a/include/csp/csp_cmp.h b/include/csp/csp_cmp.h index 96f5132ad..b7daa90ef 100644 --- a/include/csp/csp_cmp.h +++ b/include/csp/csp_cmp.h @@ -24,7 +24,7 @@ extern "C" { /** * CMP reply. */ -#define CSP_CMP_REPLY 0xff +#define CSP_CMP_REPLY 0xff /**@}*/ /** @@ -67,7 +67,7 @@ extern "C" { /** * CMP identification - max revision length. */ -#define CSP_CMP_IDENT_REV_LEN 20 +#define CSP_CMP_IDENT_REV_LEN 20 /** * CMP identification - max date length. */ @@ -161,15 +161,15 @@ struct csp_cmp_message { * @param[in,out] msg data. * @return #CSP_ERR_NONE on success, otherwise an error code */ -int csp_cmp(uint16_t node, uint32_t timeout, uint8_t code, int msg_size, struct csp_cmp_message *msg); +int csp_cmp(uint16_t node, uint32_t timeout, uint8_t code, int msg_size, struct csp_cmp_message * msg); /** * Macro for defining management handling function. */ -#define CMP_MESSAGE(_code, _memb) \ -static inline int csp_cmp_##_memb(uint16_t node, uint32_t timeout, struct csp_cmp_message *msg) { \ - return csp_cmp(node, timeout, _code, CMP_SIZE(_memb), msg); \ -} +#define CMP_MESSAGE(_code, _memb) \ + static inline int csp_cmp_##_memb(uint16_t node, uint32_t timeout, struct csp_cmp_message * msg) { \ + return csp_cmp(node, timeout, _code, CMP_SIZE(_memb), msg); \ + } CMP_MESSAGE(CSP_CMP_IDENT, ident) CMP_MESSAGE(CSP_CMP_ROUTE_SET_V1, route_set_v1) @@ -185,7 +185,7 @@ CMP_MESSAGE(CSP_CMP_ROUTE_SET_V2, route_set_v2) * @param[in/out] msg memory address and number of bytes to peek. (msg peeked/read memory) * @return #CSP_ERR_NONE on success, otherwise an error code. */ -static inline int csp_cmp_peek(uint16_t node, uint32_t timeout, struct csp_cmp_message *msg) { +static inline int csp_cmp_peek(uint16_t node, uint32_t timeout, struct csp_cmp_message * msg) { return csp_cmp(node, timeout, CSP_CMP_PEEK, CMP_SIZE(peek) - sizeof(msg->peek.data) + msg->peek.len, msg); } @@ -197,7 +197,7 @@ static inline int csp_cmp_peek(uint16_t node, uint32_t timeout, struct csp_cmp_m * @param[in] msg memory address, number of bytes and the actual bytes to poke/write. * @return #CSP_ERR_NONE on success, otherwise an error code. */ -static inline int csp_cmp_poke(uint16_t node, uint32_t timeout, struct csp_cmp_message *msg) { +static inline int csp_cmp_poke(uint16_t node, uint32_t timeout, struct csp_cmp_message * msg) { return csp_cmp(node, timeout, CSP_CMP_POKE, CMP_SIZE(poke) - sizeof(msg->poke.data) + msg->poke.len, msg); } diff --git a/include/csp/csp_crc32.h b/include/csp/csp_crc32.h index 83f30aed2..97d5dc0c0 100644 --- a/include/csp/csp_crc32.h +++ b/include/csp/csp_crc32.h @@ -48,7 +48,7 @@ uint32_t csp_crc32_memory(const uint8_t * addr, uint32_t length); Initialize the CRC32 object prior to calculating checksum. @param[in] crc CRC32 object previously created by the caller */ -void csp_crc32_init(csp_crc32_t *crc); +void csp_crc32_init(csp_crc32_t * crc); /** Update the CRC32 calculation with a chunk of data @@ -63,7 +63,7 @@ void csp_crc32_update(csp_crc32_t * crc, const uint8_t * data, uint32_t length); @param[in] crc CRC32 object previously created, init'ed and updated by the caller @return checksum */ -uint32_t csp_crc32_final(csp_crc32_t *crc); +uint32_t csp_crc32_final(csp_crc32_t * crc); #ifdef __cplusplus } diff --git a/include/csp/csp_debug.h b/include/csp/csp_debug.h index 8f4924100..920b9c7d1 100644 --- a/include/csp/csp_debug.h +++ b/include/csp/csp_debug.h @@ -22,7 +22,6 @@ extern "C" { #endif - /** Error counters */ extern uint8_t csp_dbg_buffer_out; extern uint8_t csp_dbg_conn_out; @@ -32,35 +31,35 @@ extern uint8_t csp_dbg_inval_reply; /* Central errno */ extern uint8_t csp_dbg_errno; -#define CSP_DBG_ERR_CORRUPT_BUFFER 1 -#define CSP_DBG_ERR_MTU_EXCEEDED 2 -#define CSP_DBG_ERR_ALREADY_FREE 3 -#define CSP_DBG_ERR_REFCOUNT 4 +#define CSP_DBG_ERR_CORRUPT_BUFFER 1 +#define CSP_DBG_ERR_MTU_EXCEEDED 2 +#define CSP_DBG_ERR_ALREADY_FREE 3 +#define CSP_DBG_ERR_REFCOUNT 4 #define CSP_DBG_ERR_INVALID_RTABLE_ENTRY 6 -#define CSP_DBG_ERR_UNSUPPORTED 7 -#define CSP_DBG_ERR_INVALID_BIND_PORT 8 -#define CSP_DBG_ERR_PORT_ALREADY_IN_USE 9 -#define CSP_DBG_ERR_ALREADY_CLOSED 10 -#define CSP_DBG_ERR_INVALID_POINTER 11 -#define CSP_DBG_ERR_CLOCK_SET_FAIL 12 +#define CSP_DBG_ERR_UNSUPPORTED 7 +#define CSP_DBG_ERR_INVALID_BIND_PORT 8 +#define CSP_DBG_ERR_PORT_ALREADY_IN_USE 9 +#define CSP_DBG_ERR_ALREADY_CLOSED 10 +#define CSP_DBG_ERR_INVALID_POINTER 11 +#define CSP_DBG_ERR_CLOCK_SET_FAIL 12 /* CAN protocol specific errno */ extern uint8_t csp_dbg_can_errno; -#define CSP_DBG_CAN_ERR_FRAME_LOST 1 -#define CSP_DBG_CAN_ERR_RX_OVF 2 -#define CSP_DBG_CAN_ERR_RX_OUT 3 +#define CSP_DBG_CAN_ERR_FRAME_LOST 1 +#define CSP_DBG_CAN_ERR_RX_OVF 2 +#define CSP_DBG_CAN_ERR_RX_OUT 3 #define CSP_DBG_CAN_ERR_SHORT_BEGIN 4 -#define CSP_DBG_CAN_ERR_INCOMPLETE 5 -#define CSP_DBG_CAN_ERR_UNKNOWN 6 +#define CSP_DBG_CAN_ERR_INCOMPLETE 5 +#define CSP_DBG_CAN_ERR_UNKNOWN 6 /* ETH protocol specific errno */ extern uint8_t csp_dbg_eth_errno; -#define CSP_DBG_ETH_ERR_FRAME_LOST 1 -#define CSP_DBG_ETH_ERR_RX_OVF 2 -#define CSP_DBG_ETH_ERR_RX_OUT 3 +#define CSP_DBG_ETH_ERR_FRAME_LOST 1 +#define CSP_DBG_ETH_ERR_RX_OVF 2 +#define CSP_DBG_ETH_ERR_RX_OUT 3 #define CSP_DBG_ETH_ERR_SHORT_BEGIN 4 -#define CSP_DBG_ETH_ERR_INCOMPLETE 5 -#define CSP_DBG_ETH_ERR_UNKNOWN 6 +#define CSP_DBG_ETH_ERR_INCOMPLETE 5 +#define CSP_DBG_ETH_ERR_UNKNOWN 6 /* Toogle flags for rdp and packet print */ extern uint8_t csp_dbg_rdp_print; @@ -73,12 +72,29 @@ void csp_print_func(const char * fmt, ...); #if (CSP_ENABLE_CSP_PRINT) #define csp_print(...) csp_print_func(__VA_ARGS__); #else -#define csp_print(...) do {} while(0) +#define csp_print(...) \ + do { \ + } while (0) #endif -#define csp_rdp_error(format, ...) { if (csp_dbg_rdp_print >= 1) { csp_print("\033[31m" format "\033[0m", ##__VA_ARGS__); }} -#define csp_rdp_protocol(format, ...) { if (csp_dbg_rdp_print >= 2) { csp_print("\033[34m" format "\033[0m", ##__VA_ARGS__); }} -#define csp_print_packet(format, ...) { if (csp_dbg_packet_print >= 1) { csp_print("\033[32m" format "\033[0m", ##__VA_ARGS__); }} +#define csp_rdp_error(format, ...) \ + { \ + if (csp_dbg_rdp_print >= 1) { \ + csp_print("\033[31m" format "\033[0m", ##__VA_ARGS__); \ + } \ + } +#define csp_rdp_protocol(format, ...) \ + { \ + if (csp_dbg_rdp_print >= 2) { \ + csp_print("\033[34m" format "\033[0m", ##__VA_ARGS__); \ + } \ + } +#define csp_print_packet(format, ...) \ + { \ + if (csp_dbg_packet_print >= 1) { \ + csp_print("\033[32m" format "\033[0m", ##__VA_ARGS__); \ + } \ + } #ifdef __cplusplus } diff --git a/include/csp/csp_error.h b/include/csp/csp_error.h index 26a8da621..b2177fb83 100644 --- a/include/csp/csp_error.h +++ b/include/csp/csp_error.h @@ -9,21 +9,21 @@ @defgroup CSP_ERR CSP error codes. @{ */ -#define CSP_ERR_NONE 0 /**< No error */ -#define CSP_ERR_NOMEM -1 /**< Not enough memory */ -#define CSP_ERR_INVAL -2 /**< Invalid argument */ -#define CSP_ERR_TIMEDOUT -3 /**< Operation timed out */ -#define CSP_ERR_USED -4 /**< Resource already in use */ -#define CSP_ERR_NOTSUP -5 /**< Operation not supported */ -#define CSP_ERR_BUSY -6 /**< Device or resource busy */ -#define CSP_ERR_ALREADY -7 /**< Connection already in progress */ -#define CSP_ERR_RESET -8 /**< Connection reset */ -#define CSP_ERR_NOBUFS -9 /**< No more buffer space available */ -#define CSP_ERR_TX -10 /**< Transmission failed */ -#define CSP_ERR_DRIVER -11 /**< Error in driver layer */ -#define CSP_ERR_AGAIN -12 /**< Resource temporarily unavailable */ -#define CSP_ERR_NOSYS -38 /**< Function not implemented */ -#define CSP_ERR_HMAC -100 /**< HMAC failed */ -#define CSP_ERR_CRC32 -102 /**< CRC32 failed */ -#define CSP_ERR_SFP -103 /**< SFP protocol error or inconsistency */ +#define CSP_ERR_NONE 0 /**< No error */ +#define CSP_ERR_NOMEM -1 /**< Not enough memory */ +#define CSP_ERR_INVAL -2 /**< Invalid argument */ +#define CSP_ERR_TIMEDOUT -3 /**< Operation timed out */ +#define CSP_ERR_USED -4 /**< Resource already in use */ +#define CSP_ERR_NOTSUP -5 /**< Operation not supported */ +#define CSP_ERR_BUSY -6 /**< Device or resource busy */ +#define CSP_ERR_ALREADY -7 /**< Connection already in progress */ +#define CSP_ERR_RESET -8 /**< Connection reset */ +#define CSP_ERR_NOBUFS -9 /**< No more buffer space available */ +#define CSP_ERR_TX -10 /**< Transmission failed */ +#define CSP_ERR_DRIVER -11 /**< Error in driver layer */ +#define CSP_ERR_AGAIN -12 /**< Resource temporarily unavailable */ +#define CSP_ERR_NOSYS -38 /**< Function not implemented */ +#define CSP_ERR_HMAC -100 /**< HMAC failed */ +#define CSP_ERR_CRC32 -102 /**< CRC32 failed */ +#define CSP_ERR_SFP -103 /**< SFP protocol error or inconsistency */ /**@}*/ diff --git a/include/csp/csp_hooks.h b/include/csp/csp_hooks.h index 2f2d57aef..1962ff00f 100644 --- a/include/csp/csp_hooks.h +++ b/include/csp/csp_hooks.h @@ -22,8 +22,8 @@ uint32_t csp_memfree_hook(void); unsigned int csp_ps_hook(csp_packet_t * packet); /** Implement these, if you use csp_if_tun */ -int csp_crypto_decrypt(uint8_t * ciphertext_in, uint8_t ciphertext_len, uint8_t * msg_out); // Returns -1 for failure, length if ok -int csp_crypto_encrypt(uint8_t * msg_begin, uint8_t msg_len, uint8_t * ciphertext_out); // Returns length of encrypted data +int csp_crypto_decrypt(uint8_t * ciphertext_in, uint8_t ciphertext_len, uint8_t * msg_out); // Returns -1 for failure, length if ok +int csp_crypto_encrypt(uint8_t * msg_begin, uint8_t msg_len, uint8_t * ciphertext_out); // Returns length of encrypted data void csp_clock_get_time(csp_timestamp_t * time); int csp_clock_set_time(const csp_timestamp_t * time); diff --git a/include/csp/csp_iflist.h b/include/csp/csp_iflist.h index d6ee975f0..7d825e765 100644 --- a/include/csp/csp_iflist.h +++ b/include/csp/csp_iflist.h @@ -38,7 +38,7 @@ csp_iface_t * csp_iflist_get(void); /** * Convert bytes to readable string */ -unsigned long csp_bytesize(unsigned long bytes, char *postfix); +unsigned long csp_bytesize(unsigned long bytes, char * postfix); /** * Runs over the list of interfaces, and if no default interface is found diff --git a/include/csp/csp_interface.h b/include/csp/csp_interface.h index 33a9f4748..b03548c15 100644 --- a/include/csp/csp_interface.h +++ b/include/csp/csp_interface.h @@ -27,29 +27,28 @@ typedef int (*nexthop_t)(csp_iface_t * iface, uint16_t via, csp_packet_t * packe struct csp_iface_s { /* Interface settings */ - uint16_t addr; /**< Host address on this subnet */ - uint16_t netmask; /**< Subnet mask */ - const char * name; /**< Name, max compare length is #CSP_IFLIST_NAME_MAX */ - void * interface_data; /**< Interface data, only known/used by the interface layer, e.g. state information. */ - void * driver_data; /**< Driver data, only known/used by the driver layer, e.g. device/channel references. */ - nexthop_t nexthop; /**< Next hop (Tx) function */ - uint8_t is_default; /**< Set default IF flag (CSP supports multiple defaults) */ + uint16_t addr; /**< Host address on this subnet */ + uint16_t netmask; /**< Subnet mask */ + const char * name; /**< Name, max compare length is #CSP_IFLIST_NAME_MAX */ + void * interface_data; /**< Interface data, only known/used by the interface layer, e.g. state information. */ + void * driver_data; /**< Driver data, only known/used by the driver layer, e.g. device/channel references. */ + nexthop_t nexthop; /**< Next hop (Tx) function */ + uint8_t is_default; /**< Set default IF flag (CSP supports multiple defaults) */ /* Stats */ - uint32_t tx; /**< Successfully transmitted packets */ - uint32_t rx; /**< Successfully received packets */ - uint32_t tx_error; /**< Transmit errors (packets) */ - uint32_t rx_error; /**< Receive errors, e.g. too large message */ - uint32_t drop; /**< Dropped packets */ - uint32_t autherr; /**< Authentication errors (packets) */ - uint32_t frame; /**< Frame format errors (packets) */ - uint32_t txbytes; /**< Transmitted bytes */ - uint32_t rxbytes; /**< Received bytes */ - uint32_t irq; /**< Interrupts */ + uint32_t tx; /**< Successfully transmitted packets */ + uint32_t rx; /**< Successfully received packets */ + uint32_t tx_error; /**< Transmit errors (packets) */ + uint32_t rx_error; /**< Receive errors, e.g. too large message */ + uint32_t drop; /**< Dropped packets */ + uint32_t autherr; /**< Authentication errors (packets) */ + uint32_t frame; /**< Frame format errors (packets) */ + uint32_t txbytes; /**< Transmitted bytes */ + uint32_t rxbytes; /**< Received bytes */ + uint32_t irq; /**< Interrupts */ /* For linked lists*/ struct csp_iface_s * next; - }; /** diff --git a/include/csp/csp_promisc.h b/include/csp/csp_promisc.h index fd5f2eba1..6f53fefc7 100644 --- a/include/csp/csp_promisc.h +++ b/include/csp/csp_promisc.h @@ -35,7 +35,7 @@ void csp_promisc_disable(void); * @param[in] timeout Timeout in ms to wait for a packet. * @return Packet (free with csp_buffer_free() or re-use packet), NULL on error or timeout. */ -csp_packet_t *csp_promisc_read(uint32_t timeout); +csp_packet_t * csp_promisc_read(uint32_t timeout); #ifdef __cplusplus } diff --git a/include/csp/csp_rtable.h b/include/csp/csp_rtable.h index 9270b99c6..d656093ec 100644 --- a/include/csp/csp_rtable.h +++ b/include/csp/csp_rtable.h @@ -15,13 +15,13 @@ extern "C" { #endif -#define CSP_NO_VIA_ADDRESS 0xFFFF +#define CSP_NO_VIA_ADDRESS 0xFFFF typedef struct csp_route_s { uint16_t address; uint16_t netmask; - uint16_t via; - csp_iface_t * iface; + uint16_t via; + csp_iface_t * iface; } csp_route_t; /** @@ -39,7 +39,7 @@ csp_route_t * csp_rtable_find_route(uint16_t dest_address); * @param[in] via assosicated via address. * @return #CSP_ERR_NONE on success, or an error code. */ -int csp_rtable_set(uint16_t dest_address, int netmask, csp_iface_t *ifc, uint16_t via); +int csp_rtable_set(uint16_t dest_address, int netmask, csp_iface_t * ifc, uint16_t via); #if (CSP_HAVE_STDIO) /** diff --git a/include/csp/csp_sfp.h b/include/csp/csp_sfp.h index 68f35c8fb..923838e5b 100644 --- a/include/csp/csp_sfp.h +++ b/include/csp/csp_sfp.h @@ -11,7 +11,7 @@ ****************************************************************************/ #pragma once -#include // memcpy() +#include // memcpy() #include @@ -19,7 +19,6 @@ extern "C" { #endif - /** * Send data over a CSP connection. * @@ -53,7 +52,7 @@ int csp_sfp_send_own_memcpy(csp_conn_t * conn, const void * data, unsigned int d * @return #CSP_ERR_NONE on success, otherwise an error. */ static inline int csp_sfp_send(csp_conn_t * conn, const void * data, unsigned int datasize, unsigned int mtu, uint32_t timeout) { - return csp_sfp_send_own_memcpy(conn, data, datasize, mtu, timeout, (csp_memcpy_fnc_t) &memcpy); + return csp_sfp_send_own_memcpy(conn, data, datasize, mtu, timeout, (csp_memcpy_fnc_t)&memcpy); } /** @@ -83,7 +82,7 @@ int csp_sfp_recv_fp(csp_conn_t * conn, void ** dataout, int * datasize, uint32_t * @param[out] datasize size of received data. * @param[in] timeout timeout in ms to wait for csp_read() * @return #CSP_ERR_NONE on success, otherwise an error. -*/ + */ static inline int csp_sfp_recv(csp_conn_t * conn, void ** dataout, int * datasize, uint32_t timeout) { return csp_sfp_recv_fp(conn, dataout, datasize, timeout, NULL); } diff --git a/include/csp/csp_types.h b/include/csp/csp_types.h index dee5fd463..640f31f3e 100644 --- a/include/csp/csp_types.h +++ b/include/csp/csp_types.h @@ -9,7 +9,7 @@ #include #include -#include "csp/autoconfig.h" // -> CSP_X defines (compile configuration) +#include "csp/autoconfig.h" // -> CSP_X defines (compile configuration) #include #include @@ -26,78 +26,78 @@ typedef struct { * Reserved ports for CSP services. */ typedef enum { - CSP_CMP = 0, /*< CSP management, e.g. memory, routes, stats */ - CSP_PING = 1, /*< Ping - return ping */ - CSP_PS = 2, /*< Current process list */ - CSP_MEMFREE = 3, /*< Free memory */ - CSP_REBOOT = 4, /*< Reboot, see #CSP_REBOOT_MAGIC and #CSP_REBOOT_SHUTDOWN_MAGIC */ - CSP_BUF_FREE = 5, /*< Free CSP buffers */ - CSP_UPTIME = 6, /*< Uptime */ + CSP_CMP = 0, /*< CSP management, e.g. memory, routes, stats */ + CSP_PING = 1, /*< Ping - return ping */ + CSP_PS = 2, /*< Current process list */ + CSP_MEMFREE = 3, /*< Free memory */ + CSP_REBOOT = 4, /*< Reboot, see #CSP_REBOOT_MAGIC and #CSP_REBOOT_SHUTDOWN_MAGIC */ + CSP_BUF_FREE = 5, /*< Free CSP buffers */ + CSP_UPTIME = 6, /*< Uptime */ } csp_service_port_t; /** Listen on all ports, primarily used with csp_bind() */ -#define CSP_ANY 255 +#define CSP_ANY 255 /** Message priority. */ typedef enum { - CSP_PRIO_CRITICAL = 0, //!< Critical - CSP_PRIO_HIGH = 1, //!< High - CSP_PRIO_NORM = 2, //!< Normal (default) - CSP_PRIO_LOW = 3, //!< Low + CSP_PRIO_CRITICAL = 0, //!< Critical + CSP_PRIO_HIGH = 1, //!< High + CSP_PRIO_NORM = 2, //!< Normal (default) + CSP_PRIO_LOW = 3, //!< Low } csp_prio_t; /** CSP identifier/header. */ -typedef struct __packed { +typedef struct __packed { uint8_t pri; uint8_t flags; uint16_t src; uint16_t dst; uint8_t dport; uint8_t sport; -} csp_id_t ; +} csp_id_t; /** @defgroup CSP_HEADER_FLAGS CSP header flags. @{ */ -#define CSP_FRES1 0x80 /*< Reserved for future use */ -#define CSP_FRES2 0x40 /*< Reserved for future use */ -#define CSP_FRES3 0x20 /*< Reserved for future use */ -#define CSP_FFRAG 0x10 /*< Use fragmentation */ -#define CSP_FHMAC 0x08 /*< Use HMAC verification */ -#define CSP_FRDP 0x02 /*< Use RDP protocol */ -#define CSP_FCRC32 0x01 /*< Use CRC32 checksum */ +#define CSP_FRES1 0x80 /*< Reserved for future use */ +#define CSP_FRES2 0x40 /*< Reserved for future use */ +#define CSP_FRES3 0x20 /*< Reserved for future use */ +#define CSP_FFRAG 0x10 /*< Use fragmentation */ +#define CSP_FHMAC 0x08 /*< Use HMAC verification */ +#define CSP_FRDP 0x02 /*< Use RDP protocol */ +#define CSP_FCRC32 0x01 /*< Use CRC32 checksum */ /**@}*/ /** @defgroup CSP_SOCKET_OPTIONS CSP Socket options. @{ */ -#define CSP_SO_NONE 0x0000 /*< No socket options */ -#define CSP_SO_RDPREQ 0x0001 /*< Require RDP */ -#define CSP_SO_RDPPROHIB 0x0002 /*< Prohibit RDP */ -#define CSP_SO_HMACREQ 0x0004 /*< Require HMAC */ -#define CSP_SO_HMACPROHIB 0x0008 /*< Prohibit HMAC */ -#define CSP_SO_CRC32REQ 0x0040 /*< Require CRC32 */ -#define CSP_SO_CRC32PROHIB 0x0080 /*< Prohibit CRC32 */ -#define CSP_SO_CONN_LESS 0x0100 /*< Enable Connection Less mode */ -#define CSP_SO_SAME 0x8000 /*< Copy opts from incoming packet only apllies to csp_sendto_reply() */ +#define CSP_SO_NONE 0x0000 /*< No socket options */ +#define CSP_SO_RDPREQ 0x0001 /*< Require RDP */ +#define CSP_SO_RDPPROHIB 0x0002 /*< Prohibit RDP */ +#define CSP_SO_HMACREQ 0x0004 /*< Require HMAC */ +#define CSP_SO_HMACPROHIB 0x0008 /*< Prohibit HMAC */ +#define CSP_SO_CRC32REQ 0x0040 /*< Require CRC32 */ +#define CSP_SO_CRC32PROHIB 0x0080 /*< Prohibit CRC32 */ +#define CSP_SO_CONN_LESS 0x0100 /*< Enable Connection Less mode */ +#define CSP_SO_SAME 0x8000 /*< Copy opts from incoming packet only apllies to csp_sendto_reply() */ /**@}*/ /** CSP Connect options */ -#define CSP_O_NONE CSP_SO_NONE /*< No connection options */ -#define CSP_O_RDP CSP_SO_RDPREQ /*< Enable RDP */ -#define CSP_O_NORDP CSP_SO_RDPPROHIB /*< Disable RDP */ -#define CSP_O_HMAC CSP_SO_HMACREQ /*< Enable HMAC */ -#define CSP_O_NOHMAC CSP_SO_HMACPROHIB /*< Disable HMAC */ -#define CSP_O_CRC32 CSP_SO_CRC32REQ /*< Enable CRC32 */ -#define CSP_O_NOCRC32 CSP_SO_CRC32PROHIB /*< Disable CRC32 */ -#define CSP_O_SAME CSP_SO_SAME +#define CSP_O_NONE CSP_SO_NONE /*< No connection options */ +#define CSP_O_RDP CSP_SO_RDPREQ /*< Enable RDP */ +#define CSP_O_NORDP CSP_SO_RDPPROHIB /*< Disable RDP */ +#define CSP_O_HMAC CSP_SO_HMACREQ /*< Enable HMAC */ +#define CSP_O_NOHMAC CSP_SO_HMACPROHIB /*< Disable HMAC */ +#define CSP_O_CRC32 CSP_SO_CRC32REQ /*< Enable CRC32 */ +#define CSP_O_NOCRC32 CSP_SO_CRC32PROHIB /*< Disable CRC32 */ +#define CSP_O_SAME CSP_SO_SAME #ifndef CSP_PACKET_PADDING_BYTES #define CSP_PACKET_PADDING_BYTES 8 @@ -121,30 +121,28 @@ typedef struct csp_packet_s { /* Only used on layer 3 (RDP) */ struct { - uint32_t rdp_quarantine; /*< EACK quarantine period */ - uint32_t timestamp_tx; /*< Time the message was sent */ - uint32_t timestamp_rx; /*< Time the message was received */ - struct csp_conn_s * conn; /*< Associated connection (this is used in RDP queue) */ + uint32_t rdp_quarantine; /*< EACK quarantine period */ + uint32_t timestamp_tx; /*< Time the message was sent */ + uint32_t timestamp_rx; /*< Time the message was received */ + struct csp_conn_s * conn; /*< Associated connection (this is used in RDP queue) */ }; /* Only used on interface RX/TX (layer 2) */ struct { - uint16_t rx_count; /*< Received bytes */ - uint16_t remain; /*< Remaining packets */ - uint32_t cfpid; /*< Connection CFP identification number */ - uint32_t last_used; /*< Timestamp in ms for last use of buffer */ + uint16_t rx_count; /*< Received bytes */ + uint16_t remain; /*< Remaining packets */ + uint32_t cfpid; /*< Connection CFP identification number */ + uint32_t last_used; /*< Timestamp in ms for last use of buffer */ uint8_t * frame_begin; uint16_t frame_length; }; - }; - uint16_t length; /*< Data length */ - csp_id_t id; /*< CSP id (unpacked version CPU readable) */ + uint16_t length; /*< Data length */ + csp_id_t id; /*< CSP id (unpacked version CPU readable) */ struct csp_packet_s * next; /*< Used for lists / queues of packets */ - /** * Additional header bytes, to prepend packed data before transmission * This must be minimum 6 bytes to accomodate CSP 2.0. But some implementations @@ -179,7 +177,7 @@ struct csp_socket_s { csp_static_queue_t rx_queue_static; /*< Static storage for rx queue */ char rx_queue_static_data[sizeof(csp_packet_t *) * CSP_CONN_RXQUEUE_LEN]; - uint32_t opts; /*< Connection or socket options */ + uint32_t opts; /*< Connection or socket options */ }; /** Forward declaration of socket structure */ @@ -188,14 +186,14 @@ typedef struct csp_socket_s csp_socket_t; typedef struct csp_conn_s csp_conn_t; /** Max length of host name - including zero termination */ -#define CSP_HOSTNAME_LEN 20 +#define CSP_HOSTNAME_LEN 20 /** Max length of model name - including zero termination */ -#define CSP_MODEL_LEN 30 +#define CSP_MODEL_LEN 30 /** Magic number for reboot request, for service-code #CSP_REBOOT */ -#define CSP_REBOOT_MAGIC 0x80078007 +#define CSP_REBOOT_MAGIC 0x80078007 /** Magic number for shutdown request, for service-code #CSP_REBOOT */ -#define CSP_REBOOT_SHUTDOWN_MAGIC 0xD1E5529A +#define CSP_REBOOT_SHUTDOWN_MAGIC 0xD1E5529A #ifdef __AVR__ typedef uint32_t csp_memptr_t; @@ -215,7 +213,7 @@ typedef csp_memptr_t (*csp_memcpy_fnc_t)(csp_memptr_t, csp_const_memptr_t, size_ /** * Compile check/asserts. */ -#define CSP_STATIC_ASSERT(condition, name) typedef char name[(condition) ? 1 : -1] +#define CSP_STATIC_ASSERT(condition, name) typedef char name[(condition) ? 1 : -1] #ifdef __cplusplus } diff --git a/include/csp/drivers/can_zephyr.h b/include/csp/drivers/can_zephyr.h index 8169fd30e..ab291c56b 100644 --- a/include/csp/drivers/can_zephyr.h +++ b/include/csp/drivers/can_zephyr.h @@ -7,7 +7,7 @@ * CAN driver (Zephyr). * * @note This driver requires the CAN driver for target board. -*/ + */ #include #include @@ -24,7 +24,7 @@ * @param[in] filter_mask Bit mask you want to set in the RX filter. * @param[out] return_iface Added interface * @return #CSP_ERR_NONE on success, otherwise an error code. -*/ + */ int csp_can_open_and_add_interface(const struct device * device, const char * ifname, uint16_t address, uint32_t bitrate, uint16_t filter_addr, uint16_t filter_mask, @@ -37,7 +37,7 @@ int csp_can_open_and_add_interface(const struct device * device, const char * if * @param[in] filter_addr Destination address you want to set in the RX filter. * @param[in] filter_mask Bit mask you want to set in the RX filter. * @return Filter ID, a negative value on failure. -*/ + */ int csp_can_set_rx_filter(csp_iface_t * iface, uint16_t filter_addr, uint16_t filter_mask); /** @@ -45,5 +45,5 @@ int csp_can_set_rx_filter(csp_iface_t * iface, uint16_t filter_addr, uint16_t fi * * @param[in] iface Interface to stop. * @return #CSP_ERR_NONE on success, otherwise an error code. -*/ + */ int csp_can_stop(csp_iface_t * iface); diff --git a/include/csp/interfaces/csp_if_can.h b/include/csp/interfaces/csp_if_can.h index 7cb364529..e81714b14 100644 --- a/include/csp/interfaces/csp_if_can.h +++ b/include/csp/interfaces/csp_if_can.h @@ -32,19 +32,18 @@ extern "C" { #endif - /** @defgroup CFP_SIZE CAN message id field size. @{ */ /** Host - source/destination address. */ -#define CFP_HOST_SIZE 5 +#define CFP_HOST_SIZE 5 /** Type - begin fragment or more fragments. */ -#define CFP_TYPE_SIZE 1 +#define CFP_TYPE_SIZE 1 /** Remaining fragments */ -#define CFP_REMAIN_SIZE 8 +#define CFP_REMAIN_SIZE 8 /** CFP identification. */ -#define CFP_ID_SIZE 10 +#define CFP_ID_SIZE 10 /** @} */ /** @@ -52,17 +51,17 @@ extern "C" { @{ */ /** Helper macro */ -#define CFP_FIELD(id,rsiz,fsiz) ((uint32_t)((uint32_t)((id) >> (rsiz)) & (uint32_t)((1 << (fsiz)) - 1))) +#define CFP_FIELD(id, rsiz, fsiz) ((uint32_t)((uint32_t)((id) >> (rsiz)) & (uint32_t)((1 << (fsiz)) - 1))) /** Extract source address */ -#define CFP_SRC(id) CFP_FIELD(id, CFP_HOST_SIZE + CFP_TYPE_SIZE + CFP_REMAIN_SIZE + CFP_ID_SIZE, CFP_HOST_SIZE) +#define CFP_SRC(id) CFP_FIELD(id, CFP_HOST_SIZE + CFP_TYPE_SIZE + CFP_REMAIN_SIZE + CFP_ID_SIZE, CFP_HOST_SIZE) /** Extract destination address */ -#define CFP_DST(id) CFP_FIELD(id, CFP_TYPE_SIZE + CFP_REMAIN_SIZE + CFP_ID_SIZE, CFP_HOST_SIZE) +#define CFP_DST(id) CFP_FIELD(id, CFP_TYPE_SIZE + CFP_REMAIN_SIZE + CFP_ID_SIZE, CFP_HOST_SIZE) /** Extract type (begin or more) */ -#define CFP_TYPE(id) CFP_FIELD(id, CFP_REMAIN_SIZE + CFP_ID_SIZE, CFP_TYPE_SIZE) +#define CFP_TYPE(id) CFP_FIELD(id, CFP_REMAIN_SIZE + CFP_ID_SIZE, CFP_TYPE_SIZE) /** Extract remaining fragments */ -#define CFP_REMAIN(id) CFP_FIELD(id, CFP_ID_SIZE, CFP_REMAIN_SIZE) +#define CFP_REMAIN(id) CFP_FIELD(id, CFP_ID_SIZE, CFP_REMAIN_SIZE) /** Extract CFP identification */ -#define CFP_ID(id) CFP_FIELD(id, 0, CFP_ID_SIZE) +#define CFP_ID(id) CFP_FIELD(id, 0, CFP_ID_SIZE) /** @} */ /** @@ -70,24 +69,23 @@ extern "C" { @{ */ /** Helper macro */ -#define CFP_MAKE_FIELD(id,fsiz,rsiz) ((uint32_t)(((id) & (uint32_t)((uint32_t)(1 << (fsiz)) - 1)) << (rsiz))) +#define CFP_MAKE_FIELD(id, fsiz, rsiz) ((uint32_t)(((id) & (uint32_t)((uint32_t)(1 << (fsiz)) - 1)) << (rsiz))) /** Make source */ -#define CFP_MAKE_SRC(id) CFP_MAKE_FIELD(id, CFP_HOST_SIZE, CFP_HOST_SIZE + CFP_TYPE_SIZE + CFP_REMAIN_SIZE + CFP_ID_SIZE) +#define CFP_MAKE_SRC(id) CFP_MAKE_FIELD(id, CFP_HOST_SIZE, CFP_HOST_SIZE + CFP_TYPE_SIZE + CFP_REMAIN_SIZE + CFP_ID_SIZE) /** Make destination */ -#define CFP_MAKE_DST(id) CFP_MAKE_FIELD(id, CFP_HOST_SIZE, CFP_TYPE_SIZE + CFP_REMAIN_SIZE + CFP_ID_SIZE) +#define CFP_MAKE_DST(id) CFP_MAKE_FIELD(id, CFP_HOST_SIZE, CFP_TYPE_SIZE + CFP_REMAIN_SIZE + CFP_ID_SIZE) /** Make type */ -#define CFP_MAKE_TYPE(id) CFP_MAKE_FIELD(id, CFP_TYPE_SIZE, CFP_REMAIN_SIZE + CFP_ID_SIZE) +#define CFP_MAKE_TYPE(id) CFP_MAKE_FIELD(id, CFP_TYPE_SIZE, CFP_REMAIN_SIZE + CFP_ID_SIZE) /** Make remaining fragments */ -#define CFP_MAKE_REMAIN(id) CFP_MAKE_FIELD(id, CFP_REMAIN_SIZE, CFP_ID_SIZE) +#define CFP_MAKE_REMAIN(id) CFP_MAKE_FIELD(id, CFP_REMAIN_SIZE, CFP_ID_SIZE) /** Make CFP id */ -#define CFP_MAKE_ID(id) CFP_MAKE_FIELD(id, CFP_ID_SIZE, 0) +#define CFP_MAKE_ID(id) CFP_MAKE_FIELD(id, CFP_ID_SIZE, 0) /** @} */ /** Mask to uniquely separate connections */ -#define CFP_ID_CONN_MASK (CFP_MAKE_SRC((uint32_t)(1 << CFP_HOST_SIZE) - 1) | \ - CFP_MAKE_DST((uint32_t)(1 << CFP_HOST_SIZE) - 1) | \ - CFP_MAKE_ID((uint32_t)(1 << CFP_ID_SIZE) - 1)) - +#define CFP_ID_CONN_MASK (CFP_MAKE_SRC((uint32_t)(1 << CFP_HOST_SIZE) - 1) | \ + CFP_MAKE_DST((uint32_t)(1 << CFP_HOST_SIZE) - 1) | \ + CFP_MAKE_ID((uint32_t)(1 << CFP_ID_SIZE) - 1)) /** * CFP 2.0 @@ -101,52 +99,50 @@ extern "C" { * End: 1 */ -#define CFP2_PRIO_MASK 0x3 +#define CFP2_PRIO_MASK 0x3 #define CFP2_PRIO_OFFSET 27 -#define CFP2_DST_SIZE 14 -#define CFP2_DST_MASK 0x3FFF +#define CFP2_DST_SIZE 14 +#define CFP2_DST_MASK 0x3FFF #define CFP2_DST_OFFSET 13 -#define CFP2_SENDER_SIZE 6 -#define CFP2_SENDER_MASK 0x3F +#define CFP2_SENDER_SIZE 6 +#define CFP2_SENDER_MASK 0x3F #define CFP2_SENDER_OFFSET 7 -#define CFP2_SC_MASK 0x3 +#define CFP2_SC_MASK 0x3 #define CFP2_SC_OFFSET 5 -#define CFP2_FC_MASK 0x7 +#define CFP2_FC_MASK 0x7 #define CFP2_FC_OFFSET 2 -#define CFP2_BEGIN_MASK 0x1 +#define CFP2_BEGIN_MASK 0x1 #define CFP2_BEGIN_OFFSET 1 -#define CFP2_END_MASK 0x1 +#define CFP2_END_MASK 0x1 #define CFP2_END_OFFSET 0 -#define CFP2_SRC_SIZE 14 -#define CFP2_SRC_MASK 0x3FFF +#define CFP2_SRC_SIZE 14 +#define CFP2_SRC_MASK 0x3FFF #define CFP2_SRC_OFFSET 18 -#define CFP2_DPORT_MASK 0x3F +#define CFP2_DPORT_MASK 0x3F #define CFP2_DPORT_OFFSET 12 -#define CFP2_SPORT_MASK 0x3F +#define CFP2_SPORT_MASK 0x3F #define CFP2_SPORT_OFFSET 6 -#define CFP2_FLAGS_MASK 0x3F +#define CFP2_FLAGS_MASK 0x3F #define CFP2_FLAGS_OFFSET 0 - /** * Fields used to uniquely define a CSP packet within each fragment header */ -#define CFP2_ID_CONN_MASK ((CFP2_DST_MASK << CFP2_DST_OFFSET) | \ +#define CFP2_ID_CONN_MASK ((CFP2_DST_MASK << CFP2_DST_OFFSET) | \ (CFP2_SENDER_MASK << CFP2_SENDER_OFFSET) | \ - (CFP2_PRIO_MASK << CFP2_PRIO_OFFSET) | \ + (CFP2_PRIO_MASK << CFP2_PRIO_OFFSET) | \ (CFP2_SC_MASK << CFP2_SC_OFFSET)) - /** * Default interface name. */ @@ -171,7 +167,7 @@ typedef int (*csp_can_driver_tx_t)(void * driver_data, uint32_t id, const uint8_ typedef struct { uint32_t cfp_packet_counter; /**< CFP Identification number - same number on all fragments from same CSP packet. */ csp_can_driver_tx_t tx_func; /**< Tx function */ - csp_packet_t * pbufs; /**< PBUF queue */ + csp_packet_t * pbufs; /**< PBUF queue */ } csp_can_interface_data_t; /** @@ -180,7 +176,7 @@ typedef struct { * @param[in] iface CSP interface, initialized with name and inteface_data * pointing to a valid #csp_can_interface_data_t structure. * @return #CSP_ERR_NONE on success, otherwise an error code. -*/ + */ int csp_can_add_interface(csp_iface_t * iface); /** @@ -203,7 +199,7 @@ int csp_can_remove_interface(csp_iface_t * iface); * @param[in] packet CSP packet * @return #CSP_ERR_NONE on success, otherwise an error code. */ -int csp_can_tx(csp_iface_t * iface, uint16_t via, csp_packet_t *packet); +int csp_can_tx(csp_iface_t * iface, uint16_t via, csp_packet_t * packet); /** * Process received CAN frame. @@ -219,7 +215,7 @@ int csp_can_tx(csp_iface_t * iface, uint16_t via, csp_packet_t *packet); * @param[out] pxTaskWoken Valid reference if called from ISR, otherwise NULL! * @return #CSP_ERR_NONE on success, otherwise an error code. */ -int csp_can_rx(csp_iface_t * iface, uint32_t id, const uint8_t * data, uint8_t dlc, int *pxTaskWoken); +int csp_can_rx(csp_iface_t * iface, uint32_t id, const uint8_t * data, uint8_t dlc, int * pxTaskWoken); #ifdef __cplusplus } diff --git a/include/csp/interfaces/csp_if_eth.h b/include/csp/interfaces/csp_if_eth.h index ad9577213..df4565f12 100644 --- a/include/csp/interfaces/csp_if_eth.h +++ b/include/csp/interfaces/csp_if_eth.h @@ -48,7 +48,7 @@ /* Size of buffer that must be greater than the size of an ethernet frame carrying a maximum sized (~2k) CSP packet */ -#define CSP_ETH_BUF_SIZE 3000 +#define CSP_ETH_BUF_SIZE 3000 /* Max number of payload bytes per ETH frame, which is the Ethernet MTU */ #define CSP_ETH_FRAME_SIZE_MAX 1500 @@ -56,23 +56,22 @@ /** * Declarations same as found in Linux net/ethernet.h and linux/if_ether.h */ -#define CSP_ETH_ALEN 6 /* Octets in one ethernet addr */ +#define CSP_ETH_ALEN 6 /* Octets in one ethernet addr */ /** * Definition of ethernet header, including reqired MAC addresses * Frame data is required to proceed in memory space after this struct */ -typedef struct csp_eth_header_s -{ - uint8_t ether_dhost[CSP_ETH_ALEN]; /* destination eth addr */ - uint8_t ether_shost[CSP_ETH_ALEN]; /* source ether addr */ - uint16_t ether_type; /* packet type ID field */ +typedef struct csp_eth_header_s { + uint8_t ether_dhost[CSP_ETH_ALEN]; /* destination eth addr */ + uint8_t ether_shost[CSP_ETH_ALEN]; /* source ether addr */ + uint16_t ether_type; /* packet type ID field */ uint16_t packet_id; uint16_t src_addr; uint16_t seg_size; uint16_t packet_length; uint8_t frame_begin[]; -} __attribute__ ((__packed__)) csp_eth_header_t; +} __attribute__((__packed__)) csp_eth_header_t; /** * Send ETH frame (implemented by driver). diff --git a/include/csp/interfaces/csp_if_i2c.h b/include/csp/interfaces/csp_if_i2c.h index 28909d234..d9b01461b 100644 --- a/include/csp/interfaces/csp_if_i2c.h +++ b/include/csp/interfaces/csp_if_i2c.h @@ -11,7 +11,6 @@ extern "C" { #endif - /** * Default name of I2C interface. */ diff --git a/include/csp/interfaces/csp_if_kiss.h b/include/csp/interfaces/csp_if_kiss.h index 97a3ee1a4..379bc2ea8 100644 --- a/include/csp/interfaces/csp_if_kiss.h +++ b/include/csp/interfaces/csp_if_kiss.h @@ -24,16 +24,16 @@ extern "C" { * @param[in] len length of \a data. * @return #CSP_ERR_NONE on success, otherwise an error code. */ -typedef int (*csp_kiss_driver_tx_t)(void *driver_data, const uint8_t * data, size_t len); +typedef int (*csp_kiss_driver_tx_t)(void * driver_data, const uint8_t * data, size_t len); /** * KISS Rx mode/state. */ typedef enum { - KISS_MODE_NOT_STARTED, /**< No start detected */ - KISS_MODE_STARTED, /**< Started on a KISS frame */ - KISS_MODE_ESCAPED, /**< Rx escape character */ - KISS_MODE_SKIP_FRAME, /**< Skip remaining frame, wait for end character */ + KISS_MODE_NOT_STARTED, /**< No start detected */ + KISS_MODE_STARTED, /**< Started on a KISS frame */ + KISS_MODE_ESCAPED, /**< Rx escape character */ + KISS_MODE_SKIP_FRAME, /**< Skip remaining frame, wait for end character */ } csp_kiss_mode_t; /** @@ -41,11 +41,11 @@ typedef enum { */ typedef struct { csp_kiss_driver_tx_t tx_func; /**< Tx function */ - csp_kiss_mode_t rx_mode; /**< Rx mode/state. */ - unsigned int rx_length; /**< Rx length */ - bool rx_first; /**< Rx first - if set, waiting for first character - (== TNC_DATA) after start */ - csp_packet_t * rx_packet; /**< CSP packet for storing Rx data. */ + csp_kiss_mode_t rx_mode; /**< Rx mode/state. */ + unsigned int rx_length; /**< Rx length */ + bool rx_first; /**< Rx first - if set, waiting for first character + (== TNC_DATA) after start */ + csp_packet_t * rx_packet; /**< CSP packet for storing Rx data. */ } csp_kiss_interface_data_t; /** diff --git a/include/csp/interfaces/csp_if_zmqhub.h b/include/csp/interfaces/csp_if_zmqhub.h index 17d972442..81c5b6eaf 100644 --- a/include/csp/interfaces/csp_if_zmqhub.h +++ b/include/csp/interfaces/csp_if_zmqhub.h @@ -24,18 +24,18 @@ extern "C" { * zmqproxy default subscribe (rx) port. * The client must connect it's publish endpoint to the zmqproxy's subscribe port. */ -#define CSP_ZMQPROXY_SUBSCRIBE_PORT 6000 +#define CSP_ZMQPROXY_SUBSCRIBE_PORT 6000 /** * zmqproxy default publish (tx) port. * The client must connect it's subscribe endpoint to the zmqproxy's publish port. */ -#define CSP_ZMQPROXY_PUBLISH_PORT 7000 +#define CSP_ZMQPROXY_PUBLISH_PORT 7000 /** * Default ZMQ interface name. */ -#define CSP_ZMQHUB_IF_NAME "ZMQHUB" +#define CSP_ZMQHUB_IF_NAME "ZMQHUB" /** * Format endpoint connection string for ZMQ. @@ -106,7 +106,6 @@ int csp_zmqhub_init_w_name_endpoints_rxfilter(const char * ifname, uint16_t addr uint32_t flags, csp_iface_t ** return_interface); - /** * Setup filtered ZMQ interface. * The filter can be enabled with promisc = 0, or disabled with promisc = 1. @@ -122,7 +121,6 @@ int csp_zmqhub_init_w_name_endpoints_rxfilter(const char * ifname, uint16_t addr int csp_zmqhub_init_filter2(const char * ifname, const char * host, uint16_t addr, uint16_t netmask, int promisc, csp_iface_t ** return_interface, char * sec_key, uint16_t subport, uint16_t pubport); - #ifdef __cplusplus } #endif diff --git a/src/csp_bridge.c b/src/csp_bridge.c index 061aaefe2..4f9a7d846 100644 --- a/src/csp_bridge.c +++ b/src/csp_bridge.c @@ -17,15 +17,16 @@ void csp_bridge_set_interfaces(csp_iface_t * if_a, csp_iface_t * if_b) { __weak void csp_input_hook(csp_iface_t * iface, csp_packet_t * packet) { csp_print_packet("INP: S %u, D %u, Dp %u, Sp %u, Pr %u, Fl 0x%02X, Sz %" PRIu16 " VIA: %s, Tms %u\n", - packet->id.src, packet->id.dst, packet->id.dport, - packet->id.sport, packet->id.pri, packet->id.flags, packet->length, iface->name, csp_get_ms()); + packet->id.src, packet->id.dst, packet->id.dport, + packet->id.sport, packet->id.pri, packet->id.flags, packet->length, iface->name, csp_get_ms()); } void csp_bridge_work(void) { if ((bif_a == NULL) || (bif_b == NULL)) { - csp_print("Bridge interfaces are not setup yet. " - "Make sure to call csp_bridge_set_interfaces()\n"); + csp_print( + "Bridge interfaces are not setup yet. " + "Make sure to call csp_bridge_set_interfaces()\n"); return; } @@ -65,5 +66,4 @@ void csp_bridge_work(void) { /* Send to the interface directly, no hassle */ csp_send_direct_iface(&packet->id, packet, destif, CSP_NO_VIA_ADDRESS, 0); - } diff --git a/src/csp_buffer.c b/src/csp_buffer.c index 52499e278..a19c96af1 100644 --- a/src/csp_buffer.c +++ b/src/csp_buffer.c @@ -21,7 +21,7 @@ void csp_buffer_init(void) { * Chunk of memory allocated for CSP buffers: * This is marked as .noinit, because csp buffers can never be assumed zeroed out * Putting this section in a separate non .bss area, saves some boot time */ - static csp_skbf_t csp_buffer_pool[CSP_BUFFER_COUNT] __noinit; + static csp_skbf_t csp_buffer_pool[CSP_BUFFER_COUNT] __noinit; static csp_static_queue_t csp_buffers_queue __noinit; static char csp_buffer_queue_data[CSP_BUFFER_COUNT * sizeof(csp_skbf_t *)] __noinit; @@ -155,8 +155,7 @@ void csp_buffer_refc_inc(void * buffer) { csp_dbg_errno = CSP_DBG_ERR_CORRUPT_BUFFER; return; } - buf->refcount++; - + buf->refcount++; } int csp_buffer_remaining(void) { diff --git a/src/csp_conn.c b/src/csp_conn.c index 973db806b..a7e103266 100644 --- a/src/csp_conn.c +++ b/src/csp_conn.c @@ -106,7 +106,7 @@ csp_conn_t * csp_conn_find_existing(csp_id_t * id) { /* Outgoing connections are uniquely defined by the source port, * So only the incoming destination port must match. This means * that responses to broadcast addresses, are accepted as long - * as the incoming port matches the unique source port of the + * as the incoming port matches the unique source port of the * connection */ if (conn->type == CONN_CLIENT) { @@ -114,11 +114,11 @@ csp_conn_t * csp_conn_find_existing(csp_id_t * id) { if (conn->idin.dport != id->dport) continue; - /* Incoming connections are uniquely defined by the source amd - * destination port, as well as the source node. Incoming - * connections can never come from a brodcast address */ + /* Incoming connections are uniquely defined by the source amd + * destination port, as well as the source node. Incoming + * connections can never come from a brodcast address */ } else { - + /* Connection must match dport */ if (conn->idin.dport != id->dport) continue; @@ -130,11 +130,8 @@ csp_conn_t * csp_conn_find_existing(csp_id_t * id) { /* Connection must match source */ if (conn->idin.src != id->src) continue; - } - - /* All conditions found! */ return conn; } @@ -242,7 +239,7 @@ int csp_conn_close(csp_conn_t * conn, uint8_t closed_by) { /* Set to closed */ conn->state = CONN_CLOSED; - + return CSP_ERR_NONE; } @@ -250,17 +247,17 @@ csp_conn_t * csp_connect(uint8_t prio, uint16_t dest, uint8_t dport, uint32_t ti /* Force options on all connections */ opts |= csp_conf.conn_dfl_so; - + /* Generate identifier */ csp_id_t incoming_id, outgoing_id; /* Use 0 as incoming id (this disables the input filter on destination node) * This means that for this outgoing connection, we accept the answer coming to whatever address - * the outgoing interface has. CSP does not support "source address" on outgoing connections - * so the outgoing source address will be automatically applied after outgoing routing + * the outgoing interface has. CSP does not support "source address" on outgoing connections + * so the outgoing source address will be automatically applied after outgoing routing * selects which interface the packet will leavve from */ - incoming_id.dst = 0; - outgoing_id.src = 0; + incoming_id.dst = 0; + outgoing_id.src = 0; incoming_id.pri = prio; outgoing_id.pri = prio; @@ -363,12 +360,12 @@ void csp_conn_print_table(void) { for (unsigned int i = 0; i < CSP_CONN_MAX; i++) { __unused csp_conn_t * conn = &arr_conn[i]; csp_print("[%02u %p] S:%u, %u -> %u, %u -> %u (%u) fl %x\r\n", - i, conn, conn->state, conn->idin.src, conn->idin.dst, - conn->idin.dport, conn->idin.sport, conn->sport_outgoing, conn->idin.flags); + i, conn, conn->state, conn->idin.src, conn->idin.dst, + conn->idin.dport, conn->idin.sport, conn->sport_outgoing, conn->idin.flags); #if (CSP_USE_RDP) if (conn->idin.flags & CSP_FRDP) { - csp_print("\tRDP: S:%d (closed by 0x%x), rcv %u, snd %u, win %" PRIu32 "\n", - conn->rdp.state, conn->rdp.closed_by, conn->rdp.rcv_cur, conn->rdp.snd_una, conn->rdp.window_size); + csp_print("\tRDP: S:%d (closed by 0x%x), rcv %u, snd %u, win %" PRIu32 "\n", + conn->rdp.state, conn->rdp.closed_by, conn->rdp.rcv_cur, conn->rdp.snd_una, conn->rdp.window_size); } #endif } @@ -377,7 +374,7 @@ void csp_conn_print_table(void) { #endif #if (CSP_HAVE_STDIO) -#include // snprintf +#include // snprintf int csp_conn_print_table_str(char * str_buf, int str_size) { @@ -403,6 +400,6 @@ int csp_conn_print_table_str(char * str_buf, int str_size) { #endif const csp_conn_t * csp_conn_get_array(size_t * size) { - *size = CSP_CONN_MAX; - return arr_conn; + *size = CSP_CONN_MAX; + return arr_conn; } diff --git a/src/csp_conn.h b/src/csp_conn.h index 0415869ae..8cdcea2e1 100644 --- a/src/csp_conn.h +++ b/src/csp_conn.h @@ -57,8 +57,8 @@ typedef struct { /** @brief Connection struct */ struct csp_conn_s { - atomic_int type; /* Connection type (CONN_CLIENT or CONN_SERVER) */ - atomic_int state; /* Connection state (CONN_OPEN or CONN_CLOSED) */ + atomic_int type; /* Connection type (CONN_CLIENT or CONN_SERVER) */ + atomic_int state; /* Connection state (CONN_OPEN or CONN_CLOSED) */ csp_id_t idin; /* Identifier received */ csp_id_t idout; /* Identifier transmitted */ uint8_t sport_outgoing; /* When used for outgoing, use this sport */ @@ -77,8 +77,6 @@ struct csp_conn_s { #endif }; - - int csp_conn_enqueue_packet(csp_conn_t * conn, csp_packet_t * packet); void csp_conn_init(void); csp_conn_t * csp_conn_allocate(csp_conn_type_t type); diff --git a/src/csp_crc32.c b/src/csp_crc32.c index 2cf416afd..60fc1bee7 100644 --- a/src/csp_crc32.c +++ b/src/csp_crc32.c @@ -64,7 +64,7 @@ void csp_crc32_update(csp_crc32_t * crc, const uint8_t * data, uint32_t length) } } -uint32_t csp_crc32_final(csp_crc32_t *crc) { +uint32_t csp_crc32_final(csp_crc32_t * crc) { if (crc) { return ((*crc) ^ 0xFFFFFFFF); @@ -92,11 +92,11 @@ int csp_crc32_append(csp_packet_t * packet) { } /* Calculate CRC32, convert to network byte order */ -#if CSP_21 // In CSP 2.1 we change to include header per default - csp_id_prepend(packet); - crc = csp_crc32_memory(packet->frame_begin, packet->frame_length); +#if CSP_21 // In CSP 2.1 we change to include header per default + csp_id_prepend(packet); + crc = csp_crc32_memory(packet->frame_begin, packet->frame_length); #else - crc = csp_crc32_memory(packet->data, packet->length); + crc = csp_crc32_memory(packet->data, packet->length); #endif /* Convert to network byte order */ @@ -132,7 +132,6 @@ int csp_crc32_verify(csp_packet_t * packet) { if (memcmp(&packet->data[packet->length] - sizeof(crc), &crc, sizeof(crc)) != 0) { return CSP_ERR_CRC32; } - } /* Strip CRC32 */ diff --git a/src/csp_debug.c b/src/csp_debug.c index d1113fdd6..bc47816aa 100644 --- a/src/csp_debug.c +++ b/src/csp_debug.c @@ -18,10 +18,10 @@ uint8_t csp_dbg_packet_print; #include #include __weak void csp_print_func(const char * fmt, ...) { - va_list args; - va_start(args, fmt); - vprintf(fmt, args); - va_end(args); + va_list args; + va_start(args, fmt); + vprintf(fmt, args); + va_end(args); } #else __weak void csp_print_func(const char * fmt, ...) {} diff --git a/src/csp_dedup.c b/src/csp_dedup.c index 7d1d3a12f..12321049b 100644 --- a/src/csp_dedup.c +++ b/src/csp_dedup.c @@ -26,7 +26,7 @@ bool csp_dedup_is_duplicate(csp_packet_t * packet) { uint32_t time = csp_get_ms(); /* Check if we have received this packet before, start looking from newest packet */ - unsigned int i = (csp_dedup_in-1) % CSP_DEDUP_COUNT; + unsigned int i = (csp_dedup_in - 1) % CSP_DEDUP_COUNT; while (i != csp_dedup_in) { /* Check the timestamp */ if (time > csp_dedup_timestamp[i] + CSP_DEDUP_WINDOW_MS) { @@ -36,7 +36,7 @@ bool csp_dedup_is_duplicate(csp_packet_t * packet) { if (crc == csp_dedup_array[i]) { return true; } - i = (i-1) & (CSP_DEDUP_COUNT-1); + i = (i - 1) & (CSP_DEDUP_COUNT - 1); } /* If not, insert packet into duplicate list */ diff --git a/src/csp_dedup.h b/src/csp_dedup.h index 04933031d..3ccc28532 100644 --- a/src/csp_dedup.h +++ b/src/csp_dedup.h @@ -8,4 +8,3 @@ * @return false if not a duplicate, true if duplicate */ bool csp_dedup_is_duplicate(csp_packet_t * packet); - diff --git a/src/csp_id.c b/src/csp_id.c index df5cf3801..f618e451a 100644 --- a/src/csp_id.c +++ b/src/csp_id.c @@ -19,8 +19,8 @@ * */ -#define CSP_ID1_HOST_SIZE 5 -#define CSP_ID1_PORT_SIZE 6 +#define CSP_ID1_HOST_SIZE 5 +#define CSP_ID1_PORT_SIZE 6 #define CSP_ID1_PRIO_MASK 0x3 #define CSP_ID1_PRIO_OFFSET 30 @@ -98,8 +98,8 @@ static void csp_id1_setup_rx(csp_packet_t * packet) { * */ -#define CSP_ID2_HOST_SIZE 14 -#define CSP_ID2_PORT_SIZE 6 +#define CSP_ID2_HOST_SIZE 14 +#define CSP_ID2_PORT_SIZE 6 #define CSP_ID2_PRIO_MASK 0x3 #define CSP_ID2_PRIO_OFFSET 46 diff --git a/src/csp_iflist.c b/src/csp_iflist.c index 448a2c162..481482ff3 100644 --- a/src/csp_iflist.c +++ b/src/csp_iflist.c @@ -17,7 +17,7 @@ int csp_iflist_is_within_subnet(uint16_t addr, csp_iface_t * ifc) { if (ifc == NULL) { return 0; } - + uint16_t netmask = ((1 << ifc->netmask) - 1) << (csp_id_get_host_bits() - ifc->netmask); uint16_t network_a = ifc->addr & netmask; uint16_t network_b = addr & netmask; @@ -27,7 +27,6 @@ int csp_iflist_is_within_subnet(uint16_t addr, csp_iface_t * ifc) { } else { return 0; } - } csp_iface_t * csp_iflist_get_by_subnet(uint16_t addr, csp_iface_t * ifc) { @@ -36,7 +35,7 @@ csp_iface_t * csp_iflist_get_by_subnet(uint16_t addr, csp_iface_t * ifc) { if (ifc == NULL) { ifc = interfaces; - /* Otherwise, continue from user defined ifc */ + /* Otherwise, continue from user defined ifc */ } else { ifc = ifc->next; } @@ -57,7 +56,6 @@ csp_iface_t * csp_iflist_get_by_subnet(uint16_t addr, csp_iface_t * ifc) { } return NULL; - } csp_iface_t * csp_iflist_get_by_isdfl(csp_iface_t * ifc) { @@ -66,7 +64,7 @@ csp_iface_t * csp_iflist_get_by_isdfl(csp_iface_t * ifc) { if (ifc == NULL) { ifc = interfaces; - /* Otherwise, continue from user defined ifc */ + /* Otherwise, continue from user defined ifc */ } else { ifc = ifc->next; } @@ -79,11 +77,9 @@ csp_iface_t * csp_iflist_get_by_isdfl(csp_iface_t * ifc) { ifc = ifc->next; continue; - } return NULL; - } csp_iface_t * csp_iflist_iterate(csp_iface_t * ifc) { @@ -92,13 +88,12 @@ csp_iface_t * csp_iflist_iterate(csp_iface_t * ifc) { if (ifc == NULL) { ifc = interfaces; - /* Otherwise, continue from user defined ifc */ + /* Otherwise, continue from user defined ifc */ } else { ifc = ifc->next; } return ifc; - } void csp_iflist_check_dfl(void) { @@ -130,7 +125,6 @@ csp_iface_t * csp_iflist_get_by_addr(uint16_t addr) { } return NULL; - } csp_iface_t * csp_iflist_get_by_name(const char * name) { @@ -146,7 +140,7 @@ csp_iface_t * csp_iflist_get_by_name(const char * name) { csp_iface_t * csp_iflist_get_by_index(int idx) { csp_iface_t * ifc = interfaces; - while(ifc && idx--) { + while (ifc && idx--) { ifc = ifc->next; } return ifc; @@ -200,7 +194,7 @@ csp_iface_t * csp_iflist_get(void) { return interfaces; } -unsigned long csp_bytesize(unsigned long bytes, char *postfix) { +unsigned long csp_bytesize(unsigned long bytes, char * postfix) { unsigned long size; if (bytes >= (1024 * 1024)) { @@ -227,9 +221,12 @@ void csp_iflist_print(void) { while (i) { tx = csp_bytesize(i->txbytes, &tx_postfix); rx = csp_bytesize(i->rxbytes, &rx_postfix); - csp_print("%-10s addr: %"PRIu16" netmask: %"PRIu16" dfl: %" PRIu32 "\r\n" - " tx: %05" PRIu32 " rx: %05" PRIu32 " txe: %05" PRIu32 " rxe: %05" PRIu32 "\r\n" - " drop: %05" PRIu32 " autherr: %05" PRIu32 " frame: %05" PRIu32 "\r\n" + csp_print("%-10s addr: %" PRIu16 " netmask: %" PRIu16 " dfl: %" PRIu32 + "\r\n" + " tx: %05" PRIu32 " rx: %05" PRIu32 " txe: %05" PRIu32 " rxe: %05" PRIu32 + "\r\n" + " drop: %05" PRIu32 " autherr: %05" PRIu32 " frame: %05" PRIu32 + "\r\n" " txb: %" PRIu32 " (%" PRIu32 "%c) rxb: %" PRIu32 " (%" PRIu32 "%c) \r\n\r\n", i->name, i->addr, i->netmask, i->is_default, i->tx, i->rx, i->tx_error, i->rx_error, i->drop, i->autherr, i->frame, i->txbytes, tx, tx_postfix, i->rxbytes, rx, rx_postfix); diff --git a/src/csp_init.c b/src/csp_init.c index 5910b65c8..1c70d0174 100644 --- a/src/csp_init.c +++ b/src/csp_init.c @@ -39,7 +39,6 @@ void csp_init(void) { /* Loopback */ csp_if_lo.netmask = csp_id_get_host_bits(); csp_iflist_add(&csp_if_lo); - } const csp_conf_t * csp_get_conf(void) { diff --git a/src/csp_io.c b/src/csp_io.c index b6c60dd34..0977d2635 100644 --- a/src/csp_io.c +++ b/src/csp_io.c @@ -75,7 +75,7 @@ void csp_id_copy(csp_id_t * target, csp_id_t * source) { target->flags = source->flags; } -void csp_send_direct(csp_id_t* idout, csp_packet_t * packet, csp_iface_t * routed_from) { +void csp_send_direct(csp_id_t * idout, csp_packet_t * packet, csp_iface_t * routed_from) { int from_me = (routed_from == NULL ? 1 : 0); @@ -117,7 +117,6 @@ void csp_send_direct(csp_id_t* idout, csp_packet_t * packet, csp_iface_t * route if (copy != NULL) { csp_send_direct_iface(idout, copy, iface, via, from_me); } - } /* If the above worked, we don't want to look at the routing table */ @@ -135,7 +134,7 @@ void csp_send_direct(csp_id_t* idout, csp_packet_t * packet, csp_iface_t * route route_found = 1; /* Do not send back to same inteface (split horizon) - * This check is is similar to that below, but faster */ + * This check is is similar to that below, but faster */ if (route->iface == routed_from) { continue; } @@ -191,29 +190,26 @@ void csp_send_direct(csp_id_t* idout, csp_packet_t * packet, csp_iface_t * route if (copy != NULL) { csp_send_direct_iface(idout, copy, iface, via, from_me); } - } csp_buffer_free(packet); - } __weak void csp_output_hook(csp_id_t * idout, csp_packet_t * packet, csp_iface_t * iface, uint16_t via, int from_me) { csp_print_packet("OUT: S %u, D %u, Dp %u, Sp %u, Pr %u, Fl 0x%02X, Sz %u VIA: %s (%u), Tms %u\n", - idout->src, idout->dst, idout->dport, idout->sport, idout->pri, idout->flags, packet->length, iface->name, (via != CSP_NO_VIA_ADDRESS) ? via : idout->dst, csp_get_ms()); + idout->src, idout->dst, idout->dport, idout->sport, idout->pri, idout->flags, packet->length, iface->name, (via != CSP_NO_VIA_ADDRESS) ? via : idout->dst, csp_get_ms()); return; } -void csp_send_direct_iface(csp_id_t* idout, csp_packet_t * packet, csp_iface_t * iface, uint16_t via, int from_me) { +void csp_send_direct_iface(csp_id_t * idout, csp_packet_t * packet, csp_iface_t * iface, uint16_t via, int from_me) { csp_output_hook(idout, packet, iface, via, from_me); /* Copy identifier to packet (before crc and hmac) */ - if(idout != &packet->id) { + if (idout != &packet->id) { csp_id_copy(&packet->id, idout); } - #if (CSP_USE_PROMISC) /* Loopback traffic is added to promisc queue by the router */ if (from_me && (iface != &csp_if_lo)) { @@ -245,7 +241,6 @@ void csp_send_direct_iface(csp_id_t* idout, csp_packet_t * packet, csp_iface_t * goto tx_err; } } - } /* Store length before passing to interface */ @@ -286,7 +281,6 @@ void csp_send(csp_conn_t * conn, csp_packet_t * packet) { #endif csp_send_direct(&conn->idout, packet, NULL); - } void csp_send_prio(uint8_t prio, csp_conn_t * conn, csp_packet_t * packet) { @@ -379,12 +373,11 @@ void csp_sendto(uint8_t prio, uint16_t dest, uint8_t dport, uint8_t src_port, ui packet->id.dst = dest; packet->id.dport = dport; - packet->id.src = 0; // The source address will be filled by csp_send_direct + packet->id.src = 0; // The source address will be filled by csp_send_direct packet->id.sport = src_port; packet->id.pri = prio; csp_send_direct(&packet->id, packet, NULL); - } void csp_sendto_reply(const csp_packet_t * request_packet, csp_packet_t * reply_packet, uint32_t opts) { diff --git a/src/csp_io.h b/src/csp_io.h index a4030ed11..53cabdda3 100644 --- a/src/csp_io.h +++ b/src/csp_io.h @@ -5,12 +5,12 @@ #include /** - * + * * @param packet packet to send - this may not be freed if error code is returned * @param from_me 1 if from me, 0 if routed message * @return #CSP_ERR_NONE on success, otherwise an error code. - * + * */ -void csp_send_direct(csp_id_t* idout, csp_packet_t * packet, csp_iface_t * routed_from); -void csp_send_direct_iface(csp_id_t* idout, csp_packet_t * packet, csp_iface_t * iface, uint16_t via, int from_me); +void csp_send_direct(csp_id_t * idout, csp_packet_t * packet, csp_iface_t * routed_from); +void csp_send_direct_iface(csp_id_t * idout, csp_packet_t * packet, csp_iface_t * iface, uint16_t via, int from_me); diff --git a/src/csp_macro.h b/src/csp_macro.h index 90fa08080..d9a741531 100644 --- a/src/csp_macro.h +++ b/src/csp_macro.h @@ -11,6 +11,6 @@ #define __weak __attribute__((__weak__)) #define CONTAINER_OF(ptr, type, member) \ - ((type *)(void *)((char *)(ptr) - offsetof(type, member))) + ((type *)(void *)((char *)(ptr)-offsetof(type, member))) #endif diff --git a/src/csp_port.c b/src/csp_port.c index 0b044ff71..7f72517a1 100644 --- a/src/csp_port.c +++ b/src/csp_port.c @@ -127,7 +127,6 @@ int csp_bind_callback(csp_callback_t callback, uint8_t port) { ports[port].state = PORT_OPEN_CB; return 0; - } int csp_socket_close(csp_socket_t * sock) { diff --git a/src/csp_rdp.c b/src/csp_rdp.c index c4a74de6d..543be6e41 100644 --- a/src/csp_rdp.c +++ b/src/csp_rdp.c @@ -31,7 +31,6 @@ #define CSP_USE_RDP_FAST_CLOSE 1 #endif - static uint32_t csp_rdp_window_size = 4; static uint32_t csp_rdp_conn_timeout = 10000; static uint32_t csp_rdp_packet_timeout = 1000; @@ -133,7 +132,7 @@ static int csp_rdp_send_cmp(csp_conn_t * conn, csp_packet_t * packet, int flags, /* Add a bit of ephemeral data to avoid CMP's to be deduplicated */ static uint8_t csp_rdp_incr = 0; - //header->flags = flags; + // header->flags = flags; header->flags |= csp_rdp_incr++ << 4 | flags; /* Send copy to tx_queue, before sending packet to IF */ @@ -425,7 +424,7 @@ void csp_rdp_check_timeouts(csp_conn_t * conn) { if (conn->dest_socket != NULL) { if (csp_rdp_time_after(time_now, conn->timestamp + conn->rdp.conn_timeout)) { csp_rdp_error("RDP %p: Found a lost connection (now: %" PRIu32 ", ts: %" PRIu32 ", to: %" PRIu32 "), closing\n", - conn, time_now, conn->timestamp, conn->rdp.conn_timeout); + conn, time_now, conn->timestamp, conn->rdp.conn_timeout); csp_conn_close(conn, CSP_RDP_CLOSED_BY_USERSPACE | CSP_RDP_CLOSED_BY_PROTOCOL | CSP_RDP_CLOSED_BY_TIMEOUT); return; } @@ -480,7 +479,6 @@ void csp_rdp_check_timeouts(csp_conn_t * conn) { /* Requeue the TX element */ csp_rdp_queue_tx_add(conn, packet); - } if (conn->rdp.state == RDP_OPEN) { @@ -492,13 +490,12 @@ void csp_rdp_check_timeouts(csp_conn_t * conn) { /* Wake user task if additional Tx can be done */ if (csp_rdp_is_conn_ready_for_tx(conn)) { - //csp_rdp_protocol("RDP %p: Wake Tx task (check timeouts)\n", conn); + // csp_rdp_protocol("RDP %p: Wake Tx task (check timeouts)\n", conn); csp_bin_sem_post(&conn->rdp.tx_wait); } } csp_rdp_rx_queue_flush(conn); - } bool csp_rdp_new_packet(csp_conn_t * conn, csp_packet_t * packet) { @@ -674,7 +671,7 @@ bool csp_rdp_new_packet(csp_conn_t * conn, csp_packet_t * packet) { /* Check sequence number */ if (!csp_rdp_seq_between(rx_header->seq_nr, conn->rdp.rcv_cur + 1, conn->rdp.rcv_cur + (conn->rdp.window_size * 2))) { - csp_rdp_protocol("RDP %p: Invalid sequence number! %u not between %u and %" PRIu32"\n", + csp_rdp_protocol("RDP %p: Invalid sequence number! %u not between %u and %" PRIu32 "\n", conn, rx_header->seq_nr, conn->rdp.rcv_cur + 1U, conn->rdp.rcv_cur + (conn->rdp.window_size * 2U)); /* If duplicate SYN received, send another SYN/ACK */ if (conn->rdp.state == RDP_SYN_RCVD) @@ -936,7 +933,6 @@ void csp_rdp_init(csp_conn_t * conn) { /* Create a binary semaphore to wait on for tasks */ csp_bin_sem_init(&conn->rdp.tx_wait); - } /** diff --git a/src/csp_rdp_queue.c b/src/csp_rdp_queue.c index f553f421f..67fd3aecf 100644 --- a/src/csp_rdp_queue.c +++ b/src/csp_rdp_queue.c @@ -18,7 +18,6 @@ void csp_rdp_queue_init(void) { /* Create RX queue */ rx_queue = csp_queue_create_static(CSP_RDP_MAX_WINDOW * 2, sizeof(csp_packet_t *), rx_queue_static_data, &rx_queue_static); - } static int __csp_rdp_queue_flush(csp_queue_handle_t queue, csp_conn_t * conn) { @@ -35,9 +34,9 @@ static int __csp_rdp_queue_flush(csp_queue_handle_t queue, csp_conn_t * conn) { break; } - if (conn == packet->conn) { - csp_buffer_free(packet); - } else { + if (conn == packet->conn) { + csp_buffer_free(packet); + } else { /* put it back */ ret = csp_queue_enqueue(queue, packet, 0); if (ret != CSP_QUEUE_OK) { @@ -62,58 +61,57 @@ void csp_rdp_queue_flush(csp_conn_t * conn) { } int csp_rdp_queue_tx_size(void) { - return csp_queue_size(tx_queue); + return csp_queue_size(tx_queue); } void csp_rdp_queue_tx_add(csp_conn_t * conn, csp_packet_t * packet) { - packet->conn = conn; - if (csp_queue_enqueue(tx_queue, &packet, 0) != CSP_QUEUE_OK) { + packet->conn = conn; + if (csp_queue_enqueue(tx_queue, &packet, 0) != CSP_QUEUE_OK) { csp_buffer_free(packet); - } + } } csp_packet_t * csp_rdp_queue_tx_get(csp_conn_t * conn) { - csp_packet_t * packet; - int size = csp_queue_size(tx_queue); - while(size--) { - if (csp_queue_dequeue(tx_queue, &packet, 0) != CSP_QUEUE_OK) { - return NULL; - } - - if (packet->conn == conn) { - return packet; - } else { - csp_rdp_queue_tx_add(conn, packet); - } - } - return NULL; + csp_packet_t * packet; + int size = csp_queue_size(tx_queue); + while (size--) { + if (csp_queue_dequeue(tx_queue, &packet, 0) != CSP_QUEUE_OK) { + return NULL; + } + + if (packet->conn == conn) { + return packet; + } else { + csp_rdp_queue_tx_add(conn, packet); + } + } + return NULL; } int csp_rdp_queue_rx_size(void) { - return csp_queue_size(rx_queue); + return csp_queue_size(rx_queue); } void csp_rdp_queue_rx_add(csp_conn_t * conn, csp_packet_t * packet) { - packet->conn = conn; - if (csp_queue_enqueue(rx_queue, &packet, 0) != CSP_QUEUE_OK) { - csp_buffer_free(packet); - } + packet->conn = conn; + if (csp_queue_enqueue(rx_queue, &packet, 0) != CSP_QUEUE_OK) { + csp_buffer_free(packet); + } } csp_packet_t * csp_rdp_queue_rx_get(csp_conn_t * conn) { - csp_packet_t * packet; - int size = csp_queue_size(rx_queue); - while(size--) { - if (csp_queue_dequeue(rx_queue, &packet, 0) != CSP_QUEUE_OK) { - return NULL; - } - - if (packet->conn == conn) { - return packet; - } else { - csp_rdp_queue_rx_add(conn, packet); - } - } - return NULL; + csp_packet_t * packet; + int size = csp_queue_size(rx_queue); + while (size--) { + if (csp_queue_dequeue(rx_queue, &packet, 0) != CSP_QUEUE_OK) { + return NULL; + } + if (packet->conn == conn) { + return packet; + } else { + csp_rdp_queue_rx_add(conn, packet); + } + } + return NULL; } diff --git a/src/csp_route.c b/src/csp_route.c index 161c06c8b..35d46eb6b 100644 --- a/src/csp_route.c +++ b/src/csp_route.c @@ -28,7 +28,6 @@ */ static int csp_route_check_options(csp_iface_t * iface, csp_packet_t * packet) { - #if (CSP_USE_HMAC == 0) /* Drop HMAC packets */ if (packet->id.flags & CSP_FHMAC) { @@ -58,7 +57,6 @@ static int csp_route_check_options(csp_iface_t * iface, csp_packet_t * packet) { */ static int csp_route_security_check(uint32_t security_opts, csp_iface_t * iface, csp_packet_t * packet) { - /* CRC32 verified packet */ if (packet->id.flags & CSP_FCRC32) { /* Verify CRC32 (does not include header for backwards compatability with csp1.x) */ @@ -99,11 +97,10 @@ static int csp_route_security_check(uint32_t security_opts, csp_iface_t * iface, return CSP_ERR_NONE; } - __weak void csp_input_hook(csp_iface_t * iface, csp_packet_t * packet) { csp_print_packet("INP: S %u, D %u, Dp %u, Sp %u, Pr %u, Fl 0x%02X, Sz %" PRIu16 " VIA: %s, Tms %u\n", - packet->id.src, packet->id.dst, packet->id.dport, - packet->id.sport, packet->id.pri, packet->id.flags, packet->length, iface->name, csp_get_ms()); + packet->id.src, packet->id.dst, packet->id.dport, + packet->id.sport, packet->id.pri, packet->id.flags, packet->length, iface->name, csp_get_ms()); } int csp_route_work(void) { @@ -161,7 +158,6 @@ int csp_route_work(void) { /* Otherwise, actually send the message */ csp_send_direct(&packet->id, packet, input.iface); return CSP_ERR_NONE; - } /* Discard packets with unsupported options */ @@ -171,7 +167,7 @@ int csp_route_work(void) { } /** - * Callbacks + * Callbacks */ csp_callback_t callback = csp_port_get_callback(packet->id.dport); if (callback) { @@ -186,7 +182,7 @@ int csp_route_work(void) { } /** - * Sockets + * Sockets */ /* The message is to me, search for incoming socket */ @@ -205,7 +201,7 @@ int csp_route_work(void) { csp_buffer_free(packet); return 0; } - + return CSP_ERR_NONE; } diff --git a/src/csp_rtable_cidr.c b/src/csp_rtable_cidr.c index 8dc9ed42b..f869f5bfe 100644 --- a/src/csp_rtable_cidr.c +++ b/src/csp_rtable_cidr.c @@ -26,19 +26,19 @@ static csp_route_t * csp_rtable_find_exact(uint16_t addr, uint16_t netmask, csp_ csp_route_t * csp_rtable_search_backward(csp_route_t * start_route) { - if (start_route == NULL || start_route <= rtable) { - return NULL; - } + if (start_route == NULL || start_route <= rtable) { + return NULL; + } - /* Start searching backward from the route before start_route */ - for (csp_route_t * route = start_route - 1; route >= rtable; route--) { + /* Start searching backward from the route before start_route */ + for (csp_route_t * route = start_route - 1; route >= rtable; route--) { - if (route->netmask == start_route->netmask && route->address == start_route->address) { - return route; - } - } + if (route->netmask == start_route->netmask && route->address == start_route->address) { + return route; + } + } - return NULL; + return NULL; } csp_route_t * csp_rtable_find_route(uint16_t addr) { diff --git a/src/csp_rtable_stdio.c b/src/csp_rtable_stdio.c index 6401007d1..b3bf3840d 100644 --- a/src/csp_rtable_stdio.c +++ b/src/csp_rtable_stdio.c @@ -41,7 +41,7 @@ static int csp_rtable_parse(const char * rtable, int dry_run) { csp_iface_t * ifc = csp_iflist_get_by_name(name); if ((address > csp_id_get_max_nodeid()) || (netmask > (int)csp_id_get_host_bits()) || (ifc == NULL)) { - csp_dbg_errno = CSP_DBG_ERR_INVALID_RTABLE_ENTRY; + csp_dbg_errno = CSP_DBG_ERR_INVALID_RTABLE_ENTRY; return CSP_ERR_INVAL; } @@ -67,8 +67,6 @@ int csp_rtable_check(const char * rtable) { return csp_rtable_parse(rtable, 1); } - - typedef struct { char * buffer; size_t len; diff --git a/src/csp_semaphore.h b/src/csp_semaphore.h index e8ed093b7..535452f3b 100644 --- a/src/csp_semaphore.h +++ b/src/csp_semaphore.h @@ -4,19 +4,19 @@ #include "csp/autoconfig.h" -#define CSP_SEMAPHORE_OK 0 -#define CSP_SEMAPHORE_ERROR -1 +#define CSP_SEMAPHORE_OK 0 +#define CSP_SEMAPHORE_ERROR -1 #if (CSP_POSIX || __DOXYGEN__) - #include - typedef sem_t csp_bin_sem_t; +#include +typedef sem_t csp_bin_sem_t; #elif (CSP_FREERTOS) - #include - #include - typedef TaskHandle_t csp_bin_sem_t; +#include +#include +typedef TaskHandle_t csp_bin_sem_t; #elif (CSP_ZEPHYR) - #include - typedef struct k_sem csp_bin_sem_t; +#include +typedef struct k_sem csp_bin_sem_t; #endif /** diff --git a/src/csp_service_handler.c b/src/csp_service_handler.c index a9eb05c20..24322d725 100644 --- a/src/csp_service_handler.c +++ b/src/csp_service_handler.c @@ -234,7 +234,7 @@ void csp_service_handler(csp_packet_t * packet) { uint32_t total = 0; total = csp_memfree_hook(); - + total = htobe32(total); memcpy(packet->data, &total, sizeof(total)); packet->length = sizeof(total); diff --git a/src/csp_sfp.c b/src/csp_sfp.c index 0f1cf4679..8be676eb0 100644 --- a/src/csp_sfp.c +++ b/src/csp_sfp.c @@ -71,7 +71,7 @@ int csp_sfp_send_own_memcpy(csp_conn_t * conn, const void * data, unsigned int t } /* Print debug */ - //csp_print("%s: %d:%d, sending at %p size %u\n", __FUNCTION__, csp_conn_src(conn), csp_conn_sport(conn), ((uint8_t *)data) + count, size); + // csp_print("%s: %d:%d, sending at %p size %u\n", __FUNCTION__, csp_conn_src(conn), csp_conn_sport(conn), ((uint8_t *)data) + count, size); /* Copy data */ (memcpyfcn)((csp_memptr_t)(uintptr_t)packet->data, (csp_memptr_t)(uintptr_t)(((uint8_t *)data) + count), size); @@ -119,18 +119,18 @@ int csp_sfp_recv_fp(csp_conn_t * conn, void ** return_data, int * return_datasiz /* Read SFP header */ sfp_header_t * sfp_header = csp_sfp_header_remove(packet); if (sfp_header == NULL) { - //csp_print("%s: %u:%u, invalid message, id.flags: 0x%x, length: %u\n", __FUNCTION__, packet->id.src, packet->id.sport, packet->id.flags, packet->length); + // csp_print("%s: %u:%u, invalid message, id.flags: 0x%x, length: %u\n", __FUNCTION__, packet->id.src, packet->id.sport, packet->id.flags, packet->length); csp_buffer_free(packet); error = CSP_ERR_SFP; goto error; } - //csp_print("%s: %u:%u, fragment %" PRIu32 "/%" PRIu32 "\n", __FUNCTION__, packet->id.src, packet->id.sport, sfp_header->offset + packet->length, sfp_header->totalsize); + // csp_print("%s: %u:%u, fragment %" PRIu32 "/%" PRIu32 "\n", __FUNCTION__, packet->id.src, packet->id.sport, sfp_header->offset + packet->length, sfp_header->totalsize); /* Consistency check */ if (sfp_header->offset != data_offset) { - //csp_print("%s: %u:%u, invalid message, offset %" PRIu32 " (expected %" PRIu32 "), length: %u, totalsize %" PRIu32 "\n", __FUNCTION__, packet->id.src, packet->id.sport, sfp_header->offset, data_offset, packet->length, sfp_header->totalsize); + // csp_print("%s: %u:%u, invalid message, offset %" PRIu32 " (expected %" PRIu32 "), length: %u, totalsize %" PRIu32 "\n", __FUNCTION__, packet->id.src, packet->id.sport, sfp_header->offset, data_offset, packet->length, sfp_header->totalsize); csp_buffer_free(packet); error = CSP_ERR_SFP; @@ -142,7 +142,7 @@ int csp_sfp_recv_fp(csp_conn_t * conn, void ** return_data, int * return_datasiz datasize = sfp_header->totalsize; data = malloc(datasize); if (data == NULL) { - //csp_print("%s: %u:%u, malloc(%" PRIu32 ") failed\n", __FUNCTION__, packet->id.src, packet->id.sport, datasize); + // csp_print("%s: %u:%u, malloc(%" PRIu32 ") failed\n", __FUNCTION__, packet->id.src, packet->id.sport, datasize); csp_buffer_free(packet); error = CSP_ERR_NOMEM; @@ -152,7 +152,7 @@ int csp_sfp_recv_fp(csp_conn_t * conn, void ** return_data, int * return_datasiz /* Consistency check */ if (((data_offset + packet->length) > datasize) || (datasize != sfp_header->totalsize)) { - //csp_print("%s: %u:%u, invalid size, sfp.offset: %" PRIu32 ", length: %u, total: %" PRIu32 " / %" PRIu32 "\n", __FUNCTION__, packet->id.src, packet->id.sport, sfp_header->offset, packet->length, datasize, sfp_header->totalsize); + // csp_print("%s: %u:%u, invalid size, sfp.offset: %" PRIu32 ", length: %u, total: %" PRIu32 " / %" PRIu32 "\n", __FUNCTION__, packet->id.src, packet->id.sport, sfp_header->offset, packet->length, datasize, sfp_header->totalsize); csp_buffer_free(packet); error = CSP_ERR_SFP; @@ -174,7 +174,7 @@ int csp_sfp_recv_fp(csp_conn_t * conn, void ** return_data, int * return_datasiz /* Consistency check */ if (packet->length == 0) { - //csp_print("%s: %u:%u, invalid size, sfp.offset: %" PRIu32 ", length: %u, total: %" PRIu32 " / %" PRIu32 "\n", __FUNCTION__, packet->id.src, packet->id.sport, sfp_header->offset, packet->length, datasize, sfp_header->totalsize); + // csp_print("%s: %u:%u, invalid size, sfp.offset: %" PRIu32 ", length: %u, total: %" PRIu32 " / %" PRIu32 "\n", __FUNCTION__, packet->id.src, packet->id.sport, sfp_header->offset, packet->length, datasize, sfp_header->totalsize); csp_buffer_free(packet); error = CSP_ERR_SFP; diff --git a/src/csp_yaml.c b/src/csp_yaml.c index 797eeb418..13030ced5 100644 --- a/src/csp_yaml.c +++ b/src/csp_yaml.c @@ -55,7 +55,7 @@ static void csp_yaml_end_if(struct data_s * data, unsigned int * dfl_addr) { } /* UART */ - if (strcmp(data->driver, "kiss") == 0) { + if (strcmp(data->driver, "kiss") == 0) { /* Check for valid options */ if (!data->baudrate) { @@ -113,8 +113,7 @@ static void csp_yaml_end_if(struct data_s * data, unsigned int * dfl_addr) { #if (CSP_HAVE_LIBZMQ) /* ZMQ */ - else if (strcmp(data->driver, "zmq") == 0) { - + else if (strcmp(data->driver, "zmq") == 0) { /* Check for valid server */ if (!data->server) { @@ -151,11 +150,11 @@ static void csp_yaml_end_if(struct data_s * data, unsigned int * dfl_addr) { } #endif - /* Unsupported interface */ + /* Unsupported interface */ else { - csp_print("Unsupported driver %s\n", data->driver); - return; - } + csp_print("Unsupported driver %s\n", data->driver); + return; + } iface->addr = addr; iface->netmask = atoi(data->netmask); @@ -163,7 +162,6 @@ static void csp_yaml_end_if(struct data_s * data, unsigned int * dfl_addr) { iface->is_default = (data->is_dfl) ? 1 : 0; csp_print(" %s addr: %u netmask %u %s\n", iface->name, iface->addr, iface->netmask, (iface->is_default) ? "DFL" : ""); - } static void csp_yaml_key_value(struct data_s * data, char * key, char * value) { @@ -201,7 +199,7 @@ static void csp_yaml_key_value(struct data_s * data, char * key, char * value) { void csp_yaml_init(char * filename, unsigned int * dfl_addr) { - struct data_s data; + struct data_s data; csp_print(" Reading config from %s\n", filename); FILE * file = fopen(filename, "rb"); @@ -261,11 +259,11 @@ void csp_yaml_init(char * filename, unsigned int * dfl_addr) { } if (event.type == YAML_SCALAR_EVENT) { - + /* Got key, parse the value too */ yaml_event_t event_val; yaml_parser_parse(&parser, &event_val); - csp_yaml_key_value(&data, (char *) event.data.scalar.value, (char *) event_val.data.scalar.value); + csp_yaml_key_value(&data, (char *)event.data.scalar.value, (char *)event_val.data.scalar.value); yaml_event_delete(&event_val); yaml_event_delete(&event); @@ -291,5 +289,4 @@ void csp_yaml_init(char * filename, unsigned int * dfl_addr) { free(data.listen_port); free(data.remote_port); free(data.promisc); - }