Skip to content

Commit

Permalink
[dsme] Make dsme message type identifiers unique. JB#38500
Browse files Browse the repository at this point in the history
There were non-unique dsme message type identifiers:
  0x00000320 = SET_THERMAL_STATUS = BATTERY_EMPTY_IND
  0x00000506 = PROCESSWD_PING = PROCESSWD_PONG

Add how-to instructions in every header that defines message types to
make it less likely that similar problems arise again in the future.

Replace custom get-message-type-name functions with common
functionality made available from libdsme.

Signed-off-by: Simo Piiroinen <simo.piiroinen@jollamobile.com>
  • Loading branch information
spiiroin committed Mar 29, 2018
1 parent 7124900 commit ebab367
Show file tree
Hide file tree
Showing 11 changed files with 101 additions and 107 deletions.
50 changes: 1 addition & 49 deletions dsme/modulebase.c
Expand Up @@ -41,54 +41,6 @@
#include <sys/types.h>
#include <unistd.h>

/** Message type id to human readable string debug helper
*/
static const char *msg_type_repr(int type)
{
#define X(name,value) if( type == value ) return #name
X(CLOSE, 0x00000001);
X(DBUS_CONNECT, 0x00000100);
X(DBUS_DISCONNECT, 0x00000101);
X(DBUS_CONNECTED, 0x00000102);
X(STATE_CHANGE_IND, 0x00000301);
X(STATE_QUERY, 0x00000302);
X(SAVE_DATA_IND, 0x00000304);
X(POWERUP_REQ, 0x00000305);
X(SHUTDOWN_REQ, 0x00000306);
X(SET_ALARM_STATE, 0x00000307);
X(REBOOT_REQ, 0x00000308);
X(STATE_REQ_DENIED_IND, 0x00000309);
X(THERMAL_SHUTDOWN_IND, 0x00000310);
X(SET_CHARGER_STATE, 0x00000311);
X(SET_THERMAL_STATE, 0x00000312);
X(SET_EMERGENCY_CALL_STATE, 0x00000313);
X(SET_BATTERY_STATE, 0x00000314);
X(BATTERY_EMPTY_IND, 0x00000315);
X(SHUTDOWN, 0x00000316);
X(SET_USB_STATE, 0x00000317);
X(TELINIT, 0x00000318);
X(CHANGE_RUNLEVEL, 0x00000319);
X(PROCESSWD_CREATE, 0x00000500);
X(PROCESSWD_DELETE, 0x00000501);
X(PROCESSWD_CLEAR, 0x00000502);
X(PROCESSWD_SET_INTERVAL, 0x00000503);
X(PROCESSWD_PING, 0x00000504);
X(PROCESSWD_PONG, 0x00000504);
X(PROCESSWD_MANUAL_PING, 0x00000505);
X(WAIT, 0x00000600);
X(WAKEUP, 0x00000601);
X(HEARTBEAT, 0x00000702);
X(ENTER_MALF, 0x00000900);
X(GET_VERSION, 0x00001100);
X(DSME_VERSION, 0x00001101);
X(SET_TA_TEST_MODE, 0x00001102);
X(SET_LOGGING_VERBOSITY, 0x00001103);
X(IDLE, 0x00001337);
X(DISK_SPACE, 0x00002000);
#undef X
return "UNKNOWN";
}

/**
Loaded module information.
*/
Expand Down Expand Up @@ -620,7 +572,7 @@ static int handle_message(endpoint_t* from,
msg->size_ == handler->msg_size)
{
dsme_log(LOG_DEBUG, "EVENT %s@%s",
msg_type_repr(msg->type_),
dsmemsg_id_name(msg->type_),
handler->owner->name);

currently_handling_module = handler->owner;
Expand Down
12 changes: 12 additions & 0 deletions include/dsme/logging.h
Expand Up @@ -59,6 +59,18 @@ typedef dsmemsg_generic_t DSM_MSGTYPE_USE_LOGGING_DEFAULTS;

enum
{
/* NOTE: dsme message types are defined in:
* - libdsme
* - libiphb
* - dsme
*
* When adding new message types
* 1) uniqueness of the identifiers must be
* ensured accross all these source trees
* 2) the dsmemsg_id_name() function in libdsme
* must be made aware of the new message type
*/

DSME_MSG_ENUM(DSM_MSGTYPE_SET_LOGGING_VERBOSITY, 0x00001103),
DSME_MSG_ENUM(DSM_MSGTYPE_ADD_LOGGING_INCLUDE, 0x00001104),
DSME_MSG_ENUM(DSM_MSGTYPE_ADD_LOGGING_EXCLUDE, 0x00001105),
Expand Down
12 changes: 12 additions & 0 deletions include/dsme/modulebase.h
Expand Up @@ -106,6 +106,18 @@ int add_single_handler(u_int32_t msg_type,
void dsme_exit(int exit_code);

enum {
/* NOTE: dsme message types are defined in:
* - libdsme
* - libiphb
* - dsme
*
* When adding new message types
* 1) uniqueness of the identifiers must be
* ensured accross all these source trees
* 2) the dsmemsg_id_name() function in libdsme
* must be made aware of the new message type
*/

DSME_MSG_ENUM(DSM_MSGTYPE_IDLE, 0x00001337),
};

Expand Down
12 changes: 12 additions & 0 deletions modules/dbusproxy.h
Expand Up @@ -30,6 +30,18 @@
#include <dsme/messages.h>

enum {
/* NOTE: dsme message types are defined in:
* - libdsme
* - libiphb
* - dsme
*
* When adding new message types
* 1) uniqueness of the identifiers must be
* ensured accross all these source trees
* 2) the dsmemsg_id_name() function in libdsme
* must be made aware of the new message type
*/

DSME_MSG_ENUM(DSM_MSGTYPE_DBUS_CONNECT, 0x00000100),
DSME_MSG_ENUM(DSM_MSGTYPE_DBUS_DISCONNECT, 0x00000101),
DSME_MSG_ENUM(DSM_MSGTYPE_DBUS_CONNECTED, 0x00000102),
Expand Down
12 changes: 12 additions & 0 deletions modules/diskmonitor.h
Expand Up @@ -50,6 +50,18 @@ typedef struct {
} DSM_MSGTYPE_DISK_SPACE;

enum {
/* NOTE: dsme message types are defined in:
* - libdsme
* - libiphb
* - dsme
*
* When adding new message types
* 1) uniqueness of the identifiers must be
* ensured accross all these source trees
* 2) the dsmemsg_id_name() function in libdsme
* must be made aware of the new message type
*/

DSME_MSG_ENUM(DSM_MSGTYPE_DISK_SPACE, 0x00002000),
};

Expand Down
12 changes: 12 additions & 0 deletions modules/heartbeat.h
Expand Up @@ -27,6 +27,18 @@
#include <dsme/messages.h>

enum {
/* NOTE: dsme message types are defined in:
* - libdsme
* - libiphb
* - dsme
*
* When adding new message types
* 1) uniqueness of the identifiers must be
* ensured accross all these source trees
* 2) the dsmemsg_id_name() function in libdsme
* must be made aware of the new message type
*/

DSME_MSG_ENUM(DSM_MSGTYPE_HEARTBEAT, 0x00000702),
};

Expand Down
13 changes: 12 additions & 1 deletion modules/malf.h
Expand Up @@ -45,8 +45,19 @@ typedef struct {
} DSM_MSGTYPE_ENTER_MALF;

enum {
/* NOTE: dsme message types are defined in:
* - libdsme
* - libiphb
* - dsme
*
* When adding new message types
* 1) uniqueness of the identifiers must be
* ensured accross all these source trees
* 2) the dsmemsg_id_name() function in libdsme
* must be made aware of the new message type
*/

DSME_MSG_ENUM(DSM_MSGTYPE_ENTER_MALF, 0x00000900),
};


#endif
12 changes: 12 additions & 0 deletions modules/runlevel.h
Expand Up @@ -48,6 +48,18 @@ typedef struct {
} DSM_MSGTYPE_SHUTDOWN;

enum {
/* NOTE: dsme message types are defined in:
* - libdsme
* - libiphb
* - dsme
*
* When adding new message types
* 1) uniqueness of the identifiers must be
* ensured accross all these source trees
* 2) the dsmemsg_id_name() function in libdsme
* must be made aware of the new message type
*/

DSME_MSG_ENUM(DSM_MSGTYPE_CHANGE_RUNLEVEL, 0x00000319),
DSME_MSG_ENUM(DSM_MSGTYPE_SHUTDOWN, 0x00000316),
};
Expand Down
12 changes: 12 additions & 0 deletions modules/state-internal.h
Expand Up @@ -38,6 +38,18 @@ typedef dsmemsg_generic_t DSM_MSGTYPE_TELINIT;


enum {
/* NOTE: dsme message types are defined in:
* - libdsme
* - libiphb
* - dsme
*
* When adding new message types
* 1) uniqueness of the identifiers must be
* ensured accross all these source trees
* 2) the dsmemsg_id_name() function in libdsme
* must be made aware of the new message type
*/

DSME_MSG_ENUM(DSM_MSGTYPE_SET_USB_STATE, 0x00000317),
DSME_MSG_ENUM(DSM_MSGTYPE_TELINIT, 0x00000318),
};
Expand Down
4 changes: 2 additions & 2 deletions rpm/dsme.spec
Expand Up @@ -11,15 +11,15 @@ Source2: dsme-rpmlintrc
Requires: systemd
Requires: statefs
Requires: ngfd
Requires: libdsme >= 0.63.2
Requires: libdsme >= 0.65.0
Requires(preun): systemd
Requires(post): systemd
Requires(postun): systemd
BuildRequires: pkgconfig(glib-2.0) >= 2.32.0
BuildRequires: pkgconfig(dbus-1)
BuildRequires: pkgconfig(dbus-glib-1)
BuildRequires: pkgconfig(libiphb) >= 1.2.0
BuildRequires: pkgconfig(dsme) >= 0.63.2
BuildRequires: pkgconfig(dsme) >= 0.65.0
BuildRequires: pkgconfig(libsystemd)
BuildRequires: pkgconfig(mce) >= 1.12.3
BuildRequires: pkgconfig(libngf0) >= 0.24
Expand Down
57 changes: 2 additions & 55 deletions util/dsmetool.c
Expand Up @@ -76,7 +76,6 @@ static bool log_verbose = false;
* MISC_UTILS
* ------------------------------------------------------------------------- */

static const char *dsme_msg_type_repr(int type);
static const char *dsme_state_repr(dsme_state_t state);
static int64_t boottime_get_ms(void);

Expand Down Expand Up @@ -151,58 +150,6 @@ static int64_t boottime_get_ms(void)
return res;
}

static const char *dsme_msg_type_repr(int type)
{
#define X(name,value) if( type == value ) return #name

// public
X(CLOSE, 0x00000001);
X(STATE_CHANGE_IND, 0x00000301);
X(STATE_QUERY, 0x00000302);
X(SAVE_DATA_IND, 0x00000304);
X(POWERUP_REQ, 0x00000305);
X(SHUTDOWN_REQ, 0x00000306);
X(SET_ALARM_STATE, 0x00000307);
X(REBOOT_REQ, 0x00000308);
X(STATE_REQ_DENIED_IND, 0x00000309);
X(THERMAL_SHUTDOWN_IND, 0x00000310);
X(SET_CHARGER_STATE, 0x00000311);
X(SET_THERMAL_STATE, 0x00000312);
X(SET_EMERGENCY_CALL_STATE, 0x00000313);
X(SET_BATTERY_STATE, 0x00000314);
X(BATTERY_EMPTY_IND, 0x00000315);
X(PROCESSWD_CREATE, 0x00000500);
X(PROCESSWD_DELETE, 0x00000501);
X(PROCESSWD_CLEAR, 0x00000502);
X(PROCESSWD_SET_INTERVAL, 0x00000503);
X(PROCESSWD_PING, 0x00000504);
X(PROCESSWD_PONG, 0x00000504);
X(PROCESSWD_MANUAL_PING, 0x00000505);
X(WAIT, 0x00000600);
X(WAKEUP, 0x00000601);
X(GET_VERSION, 0x00001100);
X(DSME_VERSION, 0x00001101);
X(SET_TA_TEST_MODE, 0x00001102);

//internal
X(DBUS_CONNECT, 0x00000100);
X(DBUS_DISCONNECT, 0x00000101);
X(DBUS_CONNECTED, 0x00000102);
X(SHUTDOWN, 0x00000316);
X(SET_USB_STATE, 0x00000317);
X(TELINIT, 0x00000318);
X(CHANGE_RUNLEVEL, 0x00000319);
X(HEARTBEAT, 0x00000702);
X(ENTER_MALF, 0x00000900);
X(SET_LOGGING_VERBOSITY, 0x00001103);
X(IDLE, 0x00001337);
X(DISK_SPACE, 0x00002000);

#undef X

return "UNKNOWN";
}

static const char *dsme_state_repr(dsme_state_t state)
{
const char *repr = "UNKNOWN";
Expand Down Expand Up @@ -269,7 +216,7 @@ static void dsmeipc_send_full(const void *msg_, const void *data, size_t size)

dsmeipc_connect();

log_debug("send: %s", dsme_msg_type_repr(msg->type_));
log_debug("send: %s", dsmemsg_id_name(msg->type_));

if( dsmesock_send_with_extra(dsmeipc_conn, msg, size, data) == -1 ) {
log_error("dsmesock_send: %m");
Expand Down Expand Up @@ -324,7 +271,7 @@ static dsmemsg_generic_t *dsmeipc_read(void)
exit(EXIT_FAILURE);
}

log_debug("recv: %s", dsme_msg_type_repr(msg->type_));
log_debug("recv: %s", dsmemsg_id_name(msg->type_));

return msg;
}
Expand Down

0 comments on commit ebab367

Please sign in to comment.