/
message.c
166 lines (144 loc) · 5 KB
/
message.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/**
@file message.c
Implements DSME message methods.
<p>
Copyright (C) 2004-2009 Nokia Corporation.
Copyright (C) 2015-2018 Jolla Ltd.
@author Semi Malinen <semi.malinen@nokia.com>
@author Simo Piiroinen <simo.piiroinen@jollamobile.com>
This file is part of Dsme.
Dsme is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License
version 2.1 as published by the Free Software Foundation.
Dsme is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with Dsme. If not, see <http://www.gnu.org/licenses/>.
*/
#include "include/dsme/messages.h"
#include <stdio.h>
#include <stdlib.h>
/** Lookup table for message type id <-> name
*
* Due to the way dsme message types are defined
* (i.e. scattered in multiple enums across several
* separate source trees), this must be hardcoded.
*/
static const struct
{
const char *name;
uint32_t id;
} dsmemsg_id_lut[] =
{
{ "CLOSE", 0x00000001 },
{ "DBUS_CONNECT", 0x00000100 },
{ "DBUS_DISCONNECT", 0x00000101 },
{ "DBUS_CONNECTED", 0x00000102 },
{ "STATE_CHANGE_IND", 0x00000301 },
{ "STATE_QUERY", 0x00000302 },
{ "SAVE_DATA_IND", 0x00000304 },
{ "POWERUP_REQ", 0x00000305 },
{ "SHUTDOWN_REQ", 0x00000306 },
{ "SET_ALARM_STATE", 0x00000307 },
{ "REBOOT_REQ", 0x00000308 },
{ "STATE_REQ_DENIED_IND", 0x00000309 },
{ "THERMAL_SHUTDOWN_IND", 0x00000310 },
{ "SET_CHARGER_STATE", 0x00000311 },
{ "SET_THERMAL_STATE", 0x00000312 },
{ "SET_EMERGENCY_CALL_STATE", 0x00000313 },
{ "SET_BATTERY_STATE", 0x00000314 },
{ "BATTERY_EMPTY_IND", 0x00000315 },
{ "SHUTDOWN", 0x00000316 },
{ "SET_USB_STATE", 0x00000317 },
{ "TELINIT", 0x00000318 },
{ "CHANGE_RUNLEVEL", 0x00000319 },
{ "SET_BATTERY_LEVEL", 0x0000031a },
{ "SET_THERMAL_STATUS", 0x00000320 },
{ "PROCESSWD_CREATE", 0x00000500 },
{ "PROCESSWD_DELETE", 0x00000501 },
{ "PROCESSWD_CLEAR", 0x00000502 },
{ "PROCESSWD_SET_INTERVAL", 0x00000503 },
{ "PROCESSWD_PING", 0x00000504 },
{ "PROCESSWD_MANUAL_PING", 0x00000505 },
{ "PROCESSWD_PONG", 0x00000506 },
{ "WAIT", 0x00000600 },
{ "WAKEUP", 0x00000601 },
{ "HEARTBEAT", 0x00000702 },
{ "ENTER_MALF", 0x00000900 },
{ "GET_VERSION", 0x00001100 },
{ "DSME_VERSION", 0x00001101 },
{ "SET_TA_TEST_MODE", 0x00001102 },
{ "SET_LOGGING_VERBOSITY", 0x00001103 },
{ "ADD_LOGGING_INCLUDE", 0x00001104 },
{ "ADD_LOGGING_EXCLUDE", 0x00001105 },
{ "USE_LOGGING_DEFAULTS", 0x00001106 },
{ "IDLE", 0x00001337 },
{ "DISK_SPACE", 0x00002000 },
// sentinel
{ 0, 0x00000000 }
};
const char *
dsmemsg_id_name(uint32_t id)
{
for( size_t i = 0; dsmemsg_id_lut[i].name; ++i ) {
if( dsmemsg_id_lut[i].id == id )
return dsmemsg_id_lut[i].name;
}
static char buf[32];
snprintf(buf, sizeof buf, "UNKNOWN_%08lx",
(unsigned long)id);
return buf;
}
void *
dsmemsg_new(uint32_t id, size_t size, size_t extra)
{
dsmemsg_generic_t *msg = calloc(1, size + extra);
if (msg == NULL) {
/* TODO */
exit(EXIT_FAILURE);
}
msg->line_size_ = size + extra;
msg->size_ = size;
msg->type_ = id;
return msg;
}
uint32_t dsmemsg_id(const dsmemsg_generic_t *msg)
{
return msg->type_;
}
const char *
dsmemsg_name(const dsmemsg_generic_t *msg)
{
if( !msg )
return "NULL_MESSAGE";
return dsmemsg_id_name(dsmemsg_id(msg));
}
size_t
dsmemsg_size(const dsmemsg_generic_t *msg)
{
return msg->size_;
}
size_t
dsmemsg_line_size(const dsmemsg_generic_t *msg)
{
return msg->line_size_;
}
size_t
dsmemsg_extra_size(const dsmemsg_generic_t *msg)
{
size_t body = dsmemsg_size(msg);
size_t line = dsmemsg_line_size(msg);
return (line > body) ? (line - body) : 0;
}
const void *
dsmemsg_extra_data(const dsmemsg_generic_t *msg)
{
const void *data = 0;
size_t extra = dsmemsg_extra_size(msg);
if( extra > 0 ) {
data = (char *)msg + dsmemsg_size(msg);
}
return data;
}