From 2dfd76ed2b8e8f8ec8ffa35cdc4ac66703c76a30 Mon Sep 17 00:00:00 2001 From: Eyal Ilsar Date: Wed, 3 Jan 2018 13:37:12 +0200 Subject: [PATCH] diag: router: Add handling of Event Report Control command (cmd_id=96) Implemented and registered a handler for the Event Report Control command request. Signed-off-by: Eyal Ilsar [bjorn: Moved implementation to common_cmds.c, removed uncessary error handling of unkown status values, use return value to return bad command errors] Signed-off-by: Bjorn Andersson --- common_cmds.c | 29 +++++++++++++++++++++++++++++ masks.c | 9 ++++----- masks.h | 2 +- 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/common_cmds.c b/common_cmds.c index c99e26e..536867a 100644 --- a/common_cmds.c +++ b/common_cmds.c @@ -71,6 +71,8 @@ struct diag_log_cmd_mask { #define DIAG_CMD_SET_MASK 0x82 +#define DIAG_CMD_EVENT_REPORT_CONTROL 0x60 + static int handle_logging_configuration(struct diag_client *client, const void *buf, size_t len) { @@ -540,10 +542,37 @@ static int handle_event_set_mask(struct diag_client *client, return 0; } +static int handle_event_report_control(struct diag_client *client, + const void *buf, size_t len) +{ + const struct { + uint8_t cmd_code; + uint8_t operation_switch; + } __packed *req = buf; + struct { + uint8_t cmd_code; + uint16_t length; + } __packed pkt; + + if (sizeof(*req) != len) + return -EMSGSIZE; + + diag_cmd_toggle_events(!!req->operation_switch); + peripheral_broadcast_event_mask(); + + pkt.cmd_code = DIAG_CMD_EVENT_REPORT_CONTROL; + pkt.length = 0; + + hdlc_enqueue(&client->outq, &pkt, sizeof(pkt)); + + return 0; +} + void register_common_cmds(void) { register_common_cmd(DIAG_CMD_LOGGING_CONFIGURATION, handle_logging_configuration); register_common_cmd(DIAG_CMD_EXTENDED_MESSAGE_CONFIGURATION, handle_extended_message_configuration); register_common_cmd(DIAG_CMD_GET_MASK, handle_event_get_mask); register_common_cmd(DIAG_CMD_SET_MASK, handle_event_set_mask); + register_common_cmd(DIAG_CMD_EVENT_REPORT_CONTROL, handle_event_report_control); } diff --git a/masks.c b/masks.c index 16f1852..53a9451 100644 --- a/masks.c +++ b/masks.c @@ -588,11 +588,10 @@ int diag_cmd_update_event_mask(uint16_t num_bits, const uint8_t *mask) return 0; } -void diag_cmd_toggle_events(uint8_t operation) +void diag_cmd_toggle_events(bool enabled) { - if (operation == DIAG_CTRL_MASK_ALL_DISABLED) { - memset(event_mask.ptr, 0xFF, event_mask.mask_len); - } else if (operation == DIAG_CTRL_MASK_ALL_ENABLED) { + if (enabled) memset(event_mask.ptr, 0x00, event_mask.mask_len); - } + else + memset(event_mask.ptr, 0xff, event_mask.mask_len); } diff --git a/masks.h b/masks.h index 0fa95f2..e82e837 100644 --- a/masks.h +++ b/masks.h @@ -144,6 +144,6 @@ void diag_cmd_set_all_msg_mask(uint32_t mask); uint8_t diag_get_event_mask_status(); int diag_cmd_get_event_mask(uint16_t num_bits, uint8_t **mask); int diag_cmd_update_event_mask(uint16_t num_bits, const uint8_t *mask); -void diag_cmd_toggle_events(uint8_t operation); +void diag_cmd_toggle_events(bool enabled); #endif /* MASKS_H_ */