Skip to content

Latest commit

 

History

History
1222 lines (997 loc) · 35 KB

mce-dsme.c

File metadata and controls

1222 lines (997 loc) · 35 KB
 
Dec 16, 2010
Dec 16, 2010
1
2
3
4
5
6
/**
* @file mce-dsme.c
* Interface code and logic between
* DSME (the Device State Management Entity)
* and MCE (the Mode Control Entity)
* <p>
May 12, 2011
May 12, 2011
7
* Copyright © 2004-2011 Nokia Corporation and/or its subsidiary(-ies).
May 17, 2019
May 17, 2019
8
* Copyright © 2012-2019 Jolla Ltd.
Dec 16, 2010
Dec 16, 2010
9
10
11
* <p>
* @author David Weinehall <david.weinehall@nokia.com>
* @author Ismo Laitinen <ismo.laitinen@nokia.com>
May 17, 2019
May 17, 2019
12
13
* @author Tapio Rantala <ext-tapio.rantala@nokia.com>
* @author Santtu Lakkala <ext-santtu.1.lakkala@nokia.com>
Sep 5, 2015
Sep 5, 2015
14
* @author Simo Piiroinen <simo.piiroinen@jollamobile.com>
Dec 16, 2010
Dec 16, 2010
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
*
* mce 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.
*
* mce 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 mce. If not, see <http://www.gnu.org/licenses/>.
*/
#include "mce-dsme.h"
May 27, 2014
May 27, 2014
31
32
33
#include "mce.h"
#include "mce-log.h"
#include "mce-dbus.h"
Nov 10, 2015
Nov 10, 2015
34
#include "mce-worker.h"
May 27, 2014
May 27, 2014
35
36
37
38
39
40
41
#include <stdlib.h>
#include <unistd.h>
#include <dsme/state.h>
#include <dsme/protocol.h>
#include <dsme/processwd.h>
Nov 23, 2018
Nov 23, 2018
42
#include <dsme/thermalmanager_dbus_if.h>
Dec 16, 2010
Dec 16, 2010
43
Sep 5, 2015
Sep 5, 2015
44
45
46
47
48
49
50
51
52
53
54
55
56
/* ========================================================================= *
* MODULE DATA
* ========================================================================= */
/** Pointer to the dsmesock connection */
static dsmesock_connection_t *mce_dsme_socket_connection = NULL;
/** I/O watch for mce_dsme_socket_connection */
static guint mce_dsme_socket_recv_id = 0;
/** ID for delayed state transition reporting timer */
static guint mce_dsme_transition_id = 0;
Feb 28, 2018
Feb 28, 2018
57
58
/** Availability of dsme; from dsme_service_state_pipe */
static service_state_t dsme_service_state = SERVICE_STATE_UNDEF;
Feb 12, 2015
Feb 12, 2015
59
Nov 23, 2018
Nov 23, 2018
60
61
62
/** Availability of thermalmanager; from thermalmanager_service_state_pipe */
static service_state_t thermalmanager_service_state = SERVICE_STATE_UNDEF;
Feb 12, 2015
Feb 12, 2015
63
/** System state from dsme; fed to system_state_pipe */
Feb 28, 2018
Feb 28, 2018
64
static system_state_t system_state = MCE_SYSTEM_STATE_UNDEF;
Jun 17, 2014
Jun 17, 2014
65
Nov 23, 2018
Nov 23, 2018
66
67
68
/** Thermal state from thermalmanager (dsme); fed to thermal_state_pipe */
static thermal_state_t thermal_state = THERMAL_STATE_UNDEF;
Sep 5, 2015
Sep 5, 2015
69
70
/** Shutdown warning from dsme; fed to shutting_down_pipe */
static bool mce_dsme_shutting_down_flag = false;
Jun 17, 2014
Jun 17, 2014
71
Mar 16, 2018
Mar 16, 2018
72
73
74
/** Cached init_done state; assume unknown */
static tristate_t init_done = TRISTATE_UNKNOWN;
Sep 5, 2015
Sep 5, 2015
75
76
77
/* ========================================================================= *
* MODULE FUNCTIONS
* ========================================================================= */
Dec 16, 2010
Dec 16, 2010
78
Sep 5, 2015
Sep 5, 2015
79
80
81
/* ------------------------------------------------------------------------- *
* UTILITY_FUNCTIONS
* ------------------------------------------------------------------------- */
Dec 16, 2010
Dec 16, 2010
82
Nov 23, 2018
Nov 23, 2018
83
84
static thermal_state_t mce_dsme_parse_thermal_state (const char *name);
static system_state_t mce_dsme_normalise_system_state (dsme_state_t dsmestate);
Sep 5, 2015
Sep 5, 2015
85
Nov 10, 2015
Nov 10, 2015
86
87
88
89
90
91
92
93
/* ------------------------------------------------------------------------- *
* WORKER_WATCHDOG
* ------------------------------------------------------------------------- */
static void mce_dsme_worker_done_cb (void *aptr, void *reply);
static void *mce_dsme_worker_pong_cb (void *aptr);
static void mce_dsme_worker_ping (void);;
Sep 5, 2015
Sep 5, 2015
94
95
96
97
98
99
100
101
102
103
104
/* ------------------------------------------------------------------------- *
* PROCESS_WATCHDOG
* ------------------------------------------------------------------------- */
static void mce_dsme_processwd_pong (void);
static void mce_dsme_processwd_init (void);
static void mce_dsme_processwd_quit (void);
/* ------------------------------------------------------------------------- *
* SYSTEM_STATE
* ------------------------------------------------------------------------- */
Sep 5, 2015
Sep 5, 2015
105
Sep 5, 2015
Sep 5, 2015
106
107
108
109
static void mce_dsme_query_system_state (void);
void mce_dsme_request_powerup (void);
void mce_dsme_request_reboot (void);
void mce_dsme_request_normal_shutdown (void);
Jun 17, 2014
Jun 17, 2014
110
Sep 5, 2015
Sep 5, 2015
111
112
113
/* ------------------------------------------------------------------------- *
* TRANSITION_SUBMODE
* ------------------------------------------------------------------------- */
Jun 17, 2014
Jun 17, 2014
114
Sep 5, 2015
Sep 5, 2015
115
116
117
static gboolean mce_dsme_transition_cb (gpointer data);
static void mce_dsme_transition_cancel (void);
static void mce_dsme_transition_schedule (void);
Sep 5, 2015
Sep 5, 2015
118
Sep 5, 2015
Sep 5, 2015
119
120
121
/* ------------------------------------------------------------------------- *
* SHUTTING_DOWN
* ------------------------------------------------------------------------- */
Mar 14, 2014
Mar 14, 2014
122
Sep 5, 2015
Sep 5, 2015
123
124
static bool mce_dsme_is_shutting_down (void);
static void mce_dsme_set_shutting_down (bool shutting_down);
Sep 5, 2015
Sep 5, 2015
125
Sep 5, 2015
Sep 5, 2015
126
127
128
/* ------------------------------------------------------------------------- *
* SOCKET_CONNECTION
* ------------------------------------------------------------------------- */
Jun 17, 2014
Jun 17, 2014
129
Mar 29, 2018
Mar 29, 2018
130
static bool mce_dsme_socket_send (void *msg);
Sep 5, 2015
Sep 5, 2015
131
132
133
134
135
136
137
138
static gboolean mce_dsme_socket_recv_cb (GIOChannel *source, GIOCondition condition, gpointer data);
static bool mce_dsme_socket_is_connected (void);
static bool mce_dsme_socket_connect (void);
static void mce_dsme_socket_disconnect (void);
/* ------------------------------------------------------------------------- *
* DBUS_HANDLERS
* ------------------------------------------------------------------------- */
Sep 5, 2015
Sep 5, 2015
139
Nov 23, 2018
Nov 23, 2018
140
141
142
143
144
static gboolean mce_dsme_dbus_thermal_state_change_cb (DBusMessage *const msg);
static void mce_dsme_dbus_thermal_state_reply_cb (DBusPendingCall *pc, void *aptr);
static void mce_dsme_dbus_cancel_thermal_state_query(void);
static void mce_dsme_dbus_start_thermal_state_query (void);
Sep 5, 2015
Sep 5, 2015
145
146
147
148
149
static gboolean mce_dsme_dbus_init_done_cb (DBusMessage *const msg);
static gboolean mce_dsme_dbus_shutdown_cb (DBusMessage *const msg);
static gboolean mce_dsme_dbus_thermal_shutdown_cb (DBusMessage *const msg);
static gboolean mce_dsme_dbus_battery_empty_shutdown_cb (DBusMessage *const msg);
Sep 5, 2015
Sep 5, 2015
150
151
static void mce_dsme_dbus_init(void);
static void mce_dsme_dbus_quit(void);
Jun 17, 2014
Jun 17, 2014
152
Sep 5, 2015
Sep 5, 2015
153
154
155
/* ------------------------------------------------------------------------- *
* DATAPIPE_TRACKING
* ------------------------------------------------------------------------- */
Jun 17, 2014
Jun 17, 2014
156
Nov 23, 2018
Nov 23, 2018
157
158
static void mce_dsme_datapipe_set_thermal_state (thermal_state_t state);
Feb 28, 2018
Feb 28, 2018
159
static void mce_dsme_datapipe_dsme_service_state_cb (gconstpointer data);
Nov 23, 2018
Nov 23, 2018
160
static void mce_dsme_datapipe_thermalmanager_service_state_cb(gconstpointer const data);
Mar 16, 2018
Mar 16, 2018
161
162
static void mce_dsme_datapipe_init_done_cb (gconstpointer data);
static void mce_dsme_datapipe_system_state_cb (gconstpointer data);
Dec 16, 2010
Dec 16, 2010
163
Sep 5, 2015
Sep 5, 2015
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
static void mce_dsme_datapipe_init(void);
static void mce_dsme_datapipe_quit(void);
/* ------------------------------------------------------------------------- *
* MODULE_INIT_EXIT
* ------------------------------------------------------------------------- */
gboolean mce_dsme_init(void);
void mce_dsme_exit(void);
/* ========================================================================= *
* UTILITY_FUNCTIONS
* ========================================================================= */
/** Convert system states used by dsme to the ones used in mce datapipes
*
* @param dsmestate System state constant used by dsme
*
* @return System state constant used within mce
*/
static system_state_t mce_dsme_normalise_system_state(dsme_state_t dsmestate)
{
Feb 28, 2018
Feb 28, 2018
186
system_state_t state = MCE_SYSTEM_STATE_UNDEF;
Jun 17, 2014
Jun 17, 2014
187
Sep 5, 2015
Sep 5, 2015
188
189
switch (dsmestate) {
case DSME_STATE_SHUTDOWN:
Feb 28, 2018
Feb 28, 2018
190
state = MCE_SYSTEM_STATE_SHUTDOWN;
Sep 5, 2015
Sep 5, 2015
191
break;
Jun 17, 2014
Jun 17, 2014
192
Sep 5, 2015
Sep 5, 2015
193
case DSME_STATE_USER:
Feb 28, 2018
Feb 28, 2018
194
state = MCE_SYSTEM_STATE_USER;
Sep 5, 2015
Sep 5, 2015
195
196
197
break;
case DSME_STATE_ACTDEAD:
Feb 28, 2018
Feb 28, 2018
198
state = MCE_SYSTEM_STATE_ACTDEAD;
Sep 5, 2015
Sep 5, 2015
199
200
201
break;
case DSME_STATE_REBOOT:
Feb 28, 2018
Feb 28, 2018
202
state = MCE_SYSTEM_STATE_REBOOT;
Sep 5, 2015
Sep 5, 2015
203
204
205
break;
case DSME_STATE_BOOT:
Feb 28, 2018
Feb 28, 2018
206
state = MCE_SYSTEM_STATE_BOOT;
Sep 5, 2015
Sep 5, 2015
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
break;
case DSME_STATE_NOT_SET:
break;
case DSME_STATE_TEST:
mce_log(LL_WARN,
"Received DSME_STATE_TEST; treating as undefined");
break;
case DSME_STATE_MALF:
mce_log(LL_WARN,
"Received DSME_STATE_MALF; treating as undefined");
break;
case DSME_STATE_LOCAL:
mce_log(LL_WARN,
"Received DSME_STATE_LOCAL; treating as undefined");
break;
default:
mce_log(LL_ERR,
"Received an unknown state from DSME; "
"treating as undefined");
break;
}
return state;
Dec 16, 2010
Dec 16, 2010
235
236
}
Nov 23, 2018
Nov 23, 2018
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
/** Convert thermal manager thermal state name to mce thermal_state_t
*
* @param name Thermal state name as received over D-Bus
*
* @return name mapped to thermal_state_t enumeration value
*/
static thermal_state_t mce_dsme_parse_thermal_state(const char *name)
{
thermal_state_t state = THERMAL_STATE_UNDEF;
if( name == 0 )
;
else if( !strcmp(name, thermalmanager_thermal_status_low) )
state = THERMAL_STATE_OK;
else if( !strcmp(name, thermalmanager_thermal_status_normal) )
state = THERMAL_STATE_OK;
else if( !strcmp(name, thermalmanager_thermal_status_warning) )
state = THERMAL_STATE_OK;
else if( !strcmp(name, thermalmanager_thermal_status_alert) )
state = THERMAL_STATE_OVERHEATED;
else if( !strcmp(name, thermalmanager_thermal_status_fatal) )
state = THERMAL_STATE_OVERHEATED;
return state;
}
Nov 10, 2015
Nov 10, 2015
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
/* ========================================================================= *
* WORKER_WATCHDOG
* ========================================================================= */
/** Validation context for the jobs passed from this module */
#define MCE_DSME_WORKERWD_JOB_CONTEXT "mce-dsme"
/** Descriptive name for the dummy sanity check worker thread jobs */
#define MCE_DSME_WORKERWD_JOB_NAME "ping"
/** Number of worker jobs scheduled */
static guint mce_dsme_worker_ping_cnt = 0;
/** Number of worker jobs executed */
static guint mce_dsme_worker_pong_cnt = 0;
/** Number of worker jobs notified */
static guint mce_dsme_worker_done_cnt = 0;
/** Flag for: worker thread issues noticed */
static bool mce_dsme_worker_misbehaving = false;
/** Handle dummy job finished notification
*
* @param aptr Ping count passed to the worker thread (as void pointer)
* @param reply Ping count returned from the worker thread (as void pointer)
*/
static void mce_dsme_worker_done_cb(void *aptr, void *reply)
{
(void)reply;
mce_dsme_worker_done_cnt = GPOINTER_TO_INT(aptr);
/* Check if the last job scheduled matches what got executed
* and notified as finished */
if( mce_dsme_worker_ping_cnt != mce_dsme_worker_pong_cnt ||
mce_dsme_worker_ping_cnt != mce_dsme_worker_done_cnt ) {
mce_log(LL_CRIT, "worker thread is misbehaving");
mce_dsme_worker_misbehaving = true;
}
}
/** Dummy job to be executed by the worker thread
*
* @param aptr Ping count (as void pointer)
*
* @return Ping count (as void pointer)
*/
static void *mce_dsme_worker_pong_cb(void *aptr)
{
/* Note: This is executed in the worker thread context */
mce_dsme_worker_pong_cnt = GPOINTER_TO_INT(aptr);
/* Check if the job we got to execute is the latest one
* scheduled from the main thread */
if( mce_dsme_worker_ping_cnt != mce_dsme_worker_pong_cnt ) {
mce_log(LL_CRIT, "worker thread is misbehaving");
mce_dsme_worker_misbehaving = true;
}
return aptr;
}
/** Run a dummy job through worker thread to make sure it is still functioning
*/
static void mce_dsme_worker_ping(void)
{
/* Check if previous job got executed as expected */
if( mce_dsme_worker_ping_cnt != mce_dsme_worker_pong_cnt ||
mce_dsme_worker_ping_cnt != mce_dsme_worker_done_cnt ) {
mce_log(LL_CRIT, "worker thread is possibly stuck");
mce_dsme_worker_misbehaving = true;
}
else if( mce_dsme_worker_misbehaving ) {
mce_dsme_worker_misbehaving = false;
mce_log(LL_CRIT, "worker thread is working again");
}
mce_dsme_worker_ping_cnt += 1;
mce_worker_add_job(MCE_DSME_WORKERWD_JOB_CONTEXT,
MCE_DSME_WORKERWD_JOB_NAME,
mce_dsme_worker_pong_cb,
mce_dsme_worker_done_cb,
GINT_TO_POINTER(mce_dsme_worker_ping_cnt));
}
Sep 5, 2015
Sep 5, 2015
353
354
355
356
/* ========================================================================= *
* PROCESS_WATCHDOG
* ========================================================================= */
Dec 16, 2010
Dec 16, 2010
357
358
359
/**
* Send pong message to the DSME process watchdog
*/
Sep 5, 2015
Sep 5, 2015
360
static void mce_dsme_processwd_pong(void)
Dec 16, 2010
Dec 16, 2010
361
{
Sep 5, 2015
Sep 5, 2015
362
363
364
365
/* Set up the message */
DSM_MSGTYPE_PROCESSWD_PONG msg =
DSME_MSG_INIT(DSM_MSGTYPE_PROCESSWD_PONG);
msg.pid = getpid();
Dec 16, 2010
Dec 16, 2010
366
Sep 5, 2015
Sep 5, 2015
367
/* Send the message */
Mar 29, 2018
Mar 29, 2018
368
mce_dsme_socket_send(&msg);
Nov 22, 2011
Nov 22, 2011
369
Nov 10, 2015
Nov 10, 2015
370
371
372
/* Run worker thread sanity check */
mce_dsme_worker_ping();
Sep 5, 2015
Sep 5, 2015
373
/* Execute hearbeat actions even if ping-pong ipc failed */
Sep 19, 2018
Sep 19, 2018
374
datapipe_exec_full(&heartbeat_event_pipe, GINT_TO_POINTER(0));
Dec 16, 2010
Dec 16, 2010
375
376
377
378
379
}
/**
* Register to DSME process watchdog
*/
Sep 5, 2015
Sep 5, 2015
380
static void mce_dsme_processwd_init(void)
Dec 16, 2010
Dec 16, 2010
381
{
Sep 5, 2015
Sep 5, 2015
382
383
384
385
/* Set up the message */
DSM_MSGTYPE_PROCESSWD_CREATE msg =
DSME_MSG_INIT(DSM_MSGTYPE_PROCESSWD_CREATE);
msg.pid = getpid();
Dec 16, 2010
Dec 16, 2010
386
Sep 5, 2015
Sep 5, 2015
387
/* Send the message */
Mar 29, 2018
Mar 29, 2018
388
mce_dsme_socket_send(&msg);
Dec 16, 2010
Dec 16, 2010
389
390
391
392
393
}
/**
* Unregister from DSME process watchdog
*/
Sep 5, 2015
Sep 5, 2015
394
static void mce_dsme_processwd_quit(void)
Dec 16, 2010
Dec 16, 2010
395
{
Sep 5, 2015
Sep 5, 2015
396
mce_log(LL_DEBUG, "Disabling DSME process watchdog");
Dec 16, 2010
Dec 16, 2010
397
Sep 5, 2015
Sep 5, 2015
398
399
400
401
/* Set up the message */
DSM_MSGTYPE_PROCESSWD_DELETE msg =
DSME_MSG_INIT(DSM_MSGTYPE_PROCESSWD_DELETE);
msg.pid = getpid();
Dec 16, 2010
Dec 16, 2010
402
Sep 5, 2015
Sep 5, 2015
403
/* Send the message */
Mar 29, 2018
Mar 29, 2018
404
mce_dsme_socket_send(&msg);
Dec 16, 2010
Dec 16, 2010
405
406
}
Sep 5, 2015
Sep 5, 2015
407
408
409
410
411
/* ========================================================================= *
* SYSTEM_STATE
* ========================================================================= */
/** Send system state inquiry
Dec 16, 2010
Dec 16, 2010
412
*/
Jun 17, 2014
Jun 17, 2014
413
static void mce_dsme_query_system_state(void)
Dec 16, 2010
Dec 16, 2010
414
{
Sep 5, 2015
Sep 5, 2015
415
416
/* Set up the message */
DSM_MSGTYPE_STATE_QUERY msg = DSME_MSG_INIT(DSM_MSGTYPE_STATE_QUERY);
Dec 16, 2010
Dec 16, 2010
417
Sep 5, 2015
Sep 5, 2015
418
/* Send the message */
Mar 29, 2018
Mar 29, 2018
419
mce_dsme_socket_send(&msg);
Dec 16, 2010
Dec 16, 2010
420
421
}
Sep 5, 2015
Sep 5, 2015
422
/** Request powerup
Dec 16, 2010
Dec 16, 2010
423
*/
Jun 17, 2014
Jun 17, 2014
424
void mce_dsme_request_powerup(void)
Dec 16, 2010
Dec 16, 2010
425
{
Sep 5, 2015
Sep 5, 2015
426
427
/* Set up the message */
DSM_MSGTYPE_POWERUP_REQ msg = DSME_MSG_INIT(DSM_MSGTYPE_POWERUP_REQ);
Dec 16, 2010
Dec 16, 2010
428
Sep 5, 2015
Sep 5, 2015
429
/* Send the message */
Mar 29, 2018
Mar 29, 2018
430
mce_dsme_socket_send(&msg);
Dec 16, 2010
Dec 16, 2010
431
432
}
Sep 5, 2015
Sep 5, 2015
433
/** Request reboot
Dec 16, 2010
Dec 16, 2010
434
*/
Jun 17, 2014
Jun 17, 2014
435
void mce_dsme_request_reboot(void)
Dec 16, 2010
Dec 16, 2010
436
{
Feb 28, 2018
Feb 28, 2018
437
if( datapipe_get_gint(osupdate_running_pipe) ) {
Sep 5, 2015
Sep 5, 2015
438
439
440
mce_log(LL_WARN, "reboot blocked; os update in progress");
goto EXIT;
}
Jun 12, 2014
Jun 12, 2014
441
Sep 5, 2015
Sep 5, 2015
442
443
/* Set up the message */
DSM_MSGTYPE_REBOOT_REQ msg = DSME_MSG_INIT(DSM_MSGTYPE_REBOOT_REQ);
Dec 16, 2010
Dec 16, 2010
444
Sep 5, 2015
Sep 5, 2015
445
/* Send the message */
Mar 29, 2018
Mar 29, 2018
446
mce_dsme_socket_send(&msg);
Jun 12, 2014
Jun 12, 2014
447
EXIT:
Sep 5, 2015
Sep 5, 2015
448
return;
Dec 16, 2010
Dec 16, 2010
449
450
}
Sep 5, 2015
Sep 5, 2015
451
452
453
454
/** Request normal shutdown
*/
void mce_dsme_request_normal_shutdown(void)
{
Feb 28, 2018
Feb 28, 2018
455
if( datapipe_get_gint(osupdate_running_pipe) ) {
Sep 5, 2015
Sep 5, 2015
456
457
458
459
460
461
462
463
mce_log(LL_WARN, "shutdown blocked; os update in progress");
goto EXIT;
}
/* Set up the message */
DSM_MSGTYPE_SHUTDOWN_REQ msg = DSME_MSG_INIT(DSM_MSGTYPE_SHUTDOWN_REQ);
/* Send the message */
Mar 29, 2018
Mar 29, 2018
464
mce_dsme_socket_send(&msg);
Sep 5, 2015
Sep 5, 2015
465
466
467
468
469
470
471
472
473
474
475
EXIT:
return;
}
/* ========================================================================= *
* TRANSITION_SUBMODE
* ========================================================================= */
/** Timer callback for ending transition submode
*
* @param data (not used)
Dec 16, 2010
Dec 16, 2010
476
477
478
*
* @return Always returns FALSE, to disable the timeout
*/
Sep 5, 2015
Sep 5, 2015
479
static gboolean mce_dsme_transition_cb(gpointer data)
Dec 16, 2010
Dec 16, 2010
480
{
Sep 5, 2015
Sep 5, 2015
481
(void)data;
Dec 16, 2010
Dec 16, 2010
482
Sep 5, 2015
Sep 5, 2015
483
mce_dsme_transition_id = 0;
Dec 16, 2010
Dec 16, 2010
484
Feb 28, 2018
Feb 28, 2018
485
mce_rem_submode_int32(MCE_SUBMODE_TRANSITION);
Dec 16, 2010
Dec 16, 2010
486
Sep 5, 2015
Sep 5, 2015
487
return FALSE;
Dec 16, 2010
Dec 16, 2010
488
489
}
Sep 5, 2015
Sep 5, 2015
490
/** Cancel delayed end of transition submode
Dec 16, 2010
Dec 16, 2010
491
*/
Sep 5, 2015
Sep 5, 2015
492
static void mce_dsme_transition_cancel(void)
Dec 16, 2010
Dec 16, 2010
493
{
Sep 5, 2015
Sep 5, 2015
494
495
496
497
if( mce_dsme_transition_id ) {
g_source_remove(mce_dsme_transition_id),
mce_dsme_transition_id = 0;
}
Dec 16, 2010
Dec 16, 2010
498
499
}
Sep 5, 2015
Sep 5, 2015
500
/** Schedule delayed end of transition submode
Dec 16, 2010
Dec 16, 2010
501
*/
Sep 5, 2015
Sep 5, 2015
502
static void mce_dsme_transition_schedule(void)
Dec 16, 2010
Dec 16, 2010
503
{
Sep 5, 2015
Sep 5, 2015
504
505
506
507
/* Remove existing timeout */
mce_dsme_transition_cancel();
/* Check if we have transition to end */
Feb 28, 2018
Feb 28, 2018
508
if( !(mce_get_submode_int32() & MCE_SUBMODE_TRANSITION) )
Sep 5, 2015
Sep 5, 2015
509
goto EXIT;
Dec 16, 2010
Dec 16, 2010
510
Aug 22, 2013
Aug 22, 2013
511
#if TRANSITION_DELAY > 0
Sep 5, 2015
Sep 5, 2015
512
513
514
/* Setup new timeout */
mce_dsme_transition_id =
g_timeout_add(TRANSITION_DELAY, mce_dsme_transition_cb, NULL);
Aug 22, 2013
Aug 22, 2013
515
#elif TRANSITION_DELAY == 0
Sep 5, 2015
Sep 5, 2015
516
517
518
/* Set up idle callback */
mce_dsme_transition_id =
g_idle_add(mce_dsme_transition_cb, NULL);
Aug 22, 2013
Aug 22, 2013
519
#else
Sep 5, 2015
Sep 5, 2015
520
521
/* Trigger immediately */
mce_dsme_transition_cb(0);
Aug 22, 2013
Aug 22, 2013
522
#endif
Dec 16, 2010
Dec 16, 2010
523
Jun 12, 2014
Jun 12, 2014
524
EXIT:
Sep 5, 2015
Sep 5, 2015
525
return;
Dec 16, 2010
Dec 16, 2010
526
527
}
Sep 5, 2015
Sep 5, 2015
528
529
530
531
/* ========================================================================= *
* SHUTTING_DOWN
* ========================================================================= */
Feb 12, 2015
Feb 12, 2015
532
533
534
535
/** Predicate for: device is shutting down
*
* @return true if shutdown is in progress, false otherwise
*/
Sep 5, 2015
Sep 5, 2015
536
static bool mce_dsme_is_shutting_down(void)
Feb 12, 2015
Feb 12, 2015
537
{
Sep 5, 2015
Sep 5, 2015
538
return mce_dsme_shutting_down_flag;
Sep 5, 2015
Sep 5, 2015
539
}
Feb 12, 2015
Feb 12, 2015
540
Sep 5, 2015
Sep 5, 2015
541
542
543
544
545
546
/** Update device is shutting down state
*
* @param shutting_down true if shutdown has started, false otherwise
*/
static void mce_dsme_set_shutting_down(bool shutting_down)
{
Sep 5, 2015
Sep 5, 2015
547
548
if( mce_dsme_shutting_down_flag == shutting_down )
goto EXIT;
Feb 12, 2015
Feb 12, 2015
549
Sep 5, 2015
Sep 5, 2015
550
mce_dsme_shutting_down_flag = shutting_down;
Sep 5, 2015
Sep 5, 2015
551
Sep 5, 2015
Sep 5, 2015
552
553
mce_log(LL_DEVEL, "Shutdown %s",
mce_dsme_shutting_down_flag ? "started" : "canceled");
Sep 5, 2015
Sep 5, 2015
554
Apr 26, 2017
Apr 26, 2017
555
556
557
558
/* Re-evaluate dsmesock connection */
if( !mce_dsme_shutting_down_flag )
mce_dsme_socket_connect();
Feb 28, 2018
Feb 28, 2018
559
datapipe_exec_full(&shutting_down_pipe,
Sep 19, 2018
Sep 19, 2018
560
GINT_TO_POINTER(mce_dsme_shutting_down_flag));
Feb 12, 2015
Feb 12, 2015
561
Sep 5, 2015
Sep 5, 2015
562
EXIT:
Sep 5, 2015
Sep 5, 2015
563
return;
Feb 12, 2015
Feb 12, 2015
564
565
}
Sep 5, 2015
Sep 5, 2015
566
567
568
569
/* ========================================================================= *
* SOCKET_CONNECTION
* ========================================================================= */
Dec 16, 2010
Dec 16, 2010
570
/**
Sep 5, 2015
Sep 5, 2015
571
* Generic send function for dsmesock messages
Dec 16, 2010
Dec 16, 2010
572
*
Sep 5, 2015
Sep 5, 2015
573
* @param msg A pointer to the message to send
Dec 16, 2010
Dec 16, 2010
574
*/
Mar 29, 2018
Mar 29, 2018
575
static bool mce_dsme_socket_send(void *msg)
Dec 16, 2010
Dec 16, 2010
576
{
Sep 5, 2015
Sep 5, 2015
577
578
579
580
bool res = false;
if( !mce_dsme_socket_connection ) {
mce_log(LL_WARN, "failed to send %s to dsme; %s",
Mar 29, 2018
Mar 29, 2018
581
dsmemsg_name(msg), "not connected");
Sep 5, 2015
Sep 5, 2015
582
583
goto EXIT;
}
Dec 16, 2010
Dec 16, 2010
584
Sep 5, 2015
Sep 5, 2015
585
586
if( dsmesock_send(mce_dsme_socket_connection, msg) == -1) {
mce_log(LL_ERR, "failed to send %s to dsme; %m",
Mar 29, 2018
Mar 29, 2018
587
dsmemsg_name(msg));
Sep 5, 2015
Sep 5, 2015
588
}
Dec 16, 2010
Dec 16, 2010
589
Mar 29, 2018
Mar 29, 2018
590
mce_log(LL_DEBUG, "%s sent to DSME", dsmemsg_name(msg));
Dec 16, 2010
Dec 16, 2010
591
Sep 5, 2015
Sep 5, 2015
592
res = true;
Dec 16, 2010
Dec 16, 2010
593
Sep 5, 2015
Sep 5, 2015
594
595
596
EXIT:
return res;
}
Dec 16, 2010
Dec 16, 2010
597
Sep 5, 2015
Sep 5, 2015
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
/** Callback for pending I/O from dsmesock
*
* @param source (not used)
* @param condition I/O condition that caused the callback to be called
* @param data (not used)
*
* @return TRUE if iowatch is to be kept, or FALSE if it should be removed
*/
static gboolean mce_dsme_socket_recv_cb(GIOChannel *source,
GIOCondition condition,
gpointer data)
{
gboolean keep_going = TRUE;
dsmemsg_generic_t *msg = 0;
DSM_MSGTYPE_STATE_CHANGE_IND *msg2;
(void)source;
(void)data;
if( condition & (G_IO_ERR | G_IO_HUP | G_IO_NVAL) ) {
if( !mce_dsme_is_shutting_down() )
mce_log(LL_CRIT, "DSME socket hangup/error");
keep_going = FALSE;
goto EXIT;
}
if( !(msg = dsmesock_receive(mce_dsme_socket_connection)) )
goto EXIT;
if( DSMEMSG_CAST(DSM_MSGTYPE_CLOSE, msg) ) {
if( !mce_dsme_is_shutting_down() )
mce_log(LL_WARN, "DSME socket closed");
keep_going = FALSE;
}
else if( DSMEMSG_CAST(DSM_MSGTYPE_PROCESSWD_PING, msg) ) {
mce_dsme_processwd_pong();
}
else if( (msg2 = DSMEMSG_CAST(DSM_MSGTYPE_STATE_CHANGE_IND, msg)) ) {
system_state_t state = mce_dsme_normalise_system_state(msg2->state);
Feb 28, 2018
Feb 28, 2018
638
datapipe_exec_full(&system_state_pipe,
Sep 19, 2018
Sep 19, 2018
639
GINT_TO_POINTER(state));
Sep 5, 2015
Sep 5, 2015
640
641
}
else {
Mar 29, 2018
Mar 29, 2018
642
643
mce_log(LL_DEBUG, "Unhandled %s message received from DSME",
dsmemsg_name(msg));
Sep 5, 2015
Sep 5, 2015
644
}
Dec 16, 2010
Dec 16, 2010
645
Sep 5, 2015
Sep 5, 2015
646
647
EXIT:
free(msg);
Dec 16, 2010
Dec 16, 2010
648
Sep 5, 2015
Sep 5, 2015
649
650
651
652
653
if( !keep_going ) {
if( !mce_dsme_is_shutting_down() ) {
mce_log(LL_WARN, "DSME i/o notifier disabled;"
" assuming dsme was stopped");
}
Dec 16, 2010
Dec 16, 2010
654
Sep 5, 2015
Sep 5, 2015
655
656
/* mark notifier as removed */
mce_dsme_socket_recv_id = 0;
Dec 16, 2010
Dec 16, 2010
657
Sep 5, 2015
Sep 5, 2015
658
659
660
/* close and wait for possible dsme restart */
mce_dsme_socket_disconnect();
}
Dec 16, 2010
Dec 16, 2010
661
Sep 5, 2015
Sep 5, 2015
662
return keep_going;
Dec 16, 2010
Dec 16, 2010
663
664
}
Sep 5, 2015
Sep 5, 2015
665
/** Predicate for: socket connection to dsme exists
Feb 12, 2015
Feb 12, 2015
666
*
Sep 5, 2015
Sep 5, 2015
667
668
669
670
671
672
673
674
* @return true if connected, false otherwise
*/
static bool mce_dsme_socket_is_connected(void)
{
return mce_dsme_socket_connection && mce_dsme_socket_recv_id;
}
/** Initialise dsmesock connection
Feb 12, 2015
Feb 12, 2015
675
*
Sep 5, 2015
Sep 5, 2015
676
* @return true on success, false on failure
Feb 12, 2015
Feb 12, 2015
677
*/
Sep 5, 2015
Sep 5, 2015
678
static bool mce_dsme_socket_connect(void)
Feb 12, 2015
Feb 12, 2015
679
{
Sep 5, 2015
Sep 5, 2015
680
GIOChannel *iochan = NULL;
Feb 12, 2015
Feb 12, 2015
681
Apr 26, 2017
Apr 26, 2017
682
683
684
685
686
/* No new connections during shutdown */
if( mce_dsme_is_shutting_down() )
goto EXIT;
/* No new connections unless dsme dbus service is up */
Feb 28, 2018
Feb 28, 2018
687
if( dsme_service_state != SERVICE_STATE_RUNNING )
Apr 26, 2017
Apr 26, 2017
688
689
690
691
692
goto EXIT;
/* Already connected ? */
if( mce_dsme_socket_recv_id )
goto EXIT;
Feb 12, 2015
Feb 12, 2015
693
Sep 5, 2015
Sep 5, 2015
694
mce_log(LL_DEBUG, "Opening DSME socket");
Feb 12, 2015
Feb 12, 2015
695
Sep 5, 2015
Sep 5, 2015
696
697
698
699
if( !(mce_dsme_socket_connection = dsmesock_connect()) ) {
mce_log(LL_ERR, "Failed to open DSME socket");
goto EXIT;
}
Feb 12, 2015
Feb 12, 2015
700
Sep 5, 2015
Sep 5, 2015
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
mce_log(LL_DEBUG, "Adding DSME socket notifier");
if( !(iochan = g_io_channel_unix_new(mce_dsme_socket_connection->fd)) ) {
mce_log(LL_ERR,"Failed to set up I/O channel for DSME socket");
goto EXIT;
}
mce_dsme_socket_recv_id =
g_io_add_watch(iochan,
G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL,
mce_dsme_socket_recv_cb, NULL);
/* Query the current system state; if the mainloop isn't running,
* this will trigger an update when the mainloop starts
*/
mce_dsme_query_system_state();
/* Register with DSME's process watchdog */
mce_dsme_processwd_init();
Dec 16, 2010
Dec 16, 2010
720
Jun 17, 2014
Jun 17, 2014
721
EXIT:
Sep 5, 2015
Sep 5, 2015
722
723
if( iochan ) g_io_channel_unref(iochan);
Apr 26, 2017
Apr 26, 2017
724
725
726
if( !mce_dsme_socket_recv_id )
mce_dsme_socket_disconnect();
Sep 5, 2015
Sep 5, 2015
727
728
729
730
731
732
733
734
735
736
737
return mce_dsme_socket_is_connected();
}
/** Close dsmesock connection
*/
static void mce_dsme_socket_disconnect(void)
{
if( mce_dsme_socket_recv_id ) {
mce_log(LL_DEBUG, "Removing DSME socket notifier");
g_source_remove(mce_dsme_socket_recv_id);
mce_dsme_socket_recv_id = 0;
Apr 26, 2017
Apr 26, 2017
738
739
740
741
742
/* Still having had a live socket notifier means: We have
* initiated the dsmesock disconnect and need to deactivate
* the process watchdog before actually disconnecting. */
mce_dsme_processwd_quit();
Sep 5, 2015
Sep 5, 2015
743
}
Dec 16, 2010
Dec 16, 2010
744
Sep 5, 2015
Sep 5, 2015
745
746
747
748
749
if( mce_dsme_socket_connection ) {
mce_log(LL_DEBUG, "Closing DSME socket");
dsmesock_close(mce_dsme_socket_connection);
mce_dsme_socket_connection = 0;
}
Dec 16, 2010
Dec 16, 2010
750
751
}
Sep 5, 2015
Sep 5, 2015
752
753
754
755
/* ========================================================================= *
* DBUS_HANDLERS
* ========================================================================= */
Nov 23, 2018
Nov 23, 2018
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
/** Pending thermal state query */
static DBusPendingCall *mce_dsme_thermal_state_query_pc = 0;
/** D-Bus callback for the thermal state change notification signal
*
* @param msg The D-Bus message
*
* @return TRUE
*/
static gboolean
mce_dsme_dbus_thermal_state_change_cb(DBusMessage *const msg)
{
DBusError error = DBUS_ERROR_INIT;
const char *name = 0;
if( !dbus_message_get_args(msg, &error,
DBUS_TYPE_STRING, &name,
DBUS_TYPE_INVALID)) {
mce_log(LL_ERR, "Failed to parse %s.%s; %s: %s",
dbus_message_get_interface(msg),
dbus_message_get_member(msg),
error.name, error.message);
goto EXIT;
}
mce_log(LL_WARN, "thermal state signal: %s", name);
thermal_state_t state = mce_dsme_parse_thermal_state(name);
mce_dsme_datapipe_set_thermal_state(state);
EXIT:
dbus_error_free(&error);
return TRUE;
}
/** Handle reply to async query made from mce_dsme_thermal_state_query_async()
*/
static void
mce_dsme_dbus_thermal_state_reply_cb(DBusPendingCall *pc, void *aptr)
{
(void)aptr;
DBusMessage *rsp = 0;
DBusError err = DBUS_ERROR_INIT;
const char *name = 0;
if( pc != mce_dsme_thermal_state_query_pc )
goto EXIT;
dbus_pending_call_unref(mce_dsme_thermal_state_query_pc),
mce_dsme_thermal_state_query_pc = 0;
if( !(rsp = dbus_pending_call_steal_reply(pc)) ) {
mce_log(LL_WARN, "no reply");
goto EXIT;
}
if( dbus_set_error_from_message(&err, rsp) ) {
mce_log(LL_WARN, "error reply: %s: %s", err.name, err.message);
goto EXIT;
}
if( !dbus_message_get_args(rsp, &err,
DBUS_TYPE_STRING, &name,
DBUS_TYPE_INVALID) ) {
mce_log(LL_WARN, "parse error: %s: %s", err.name, err.message);
goto EXIT;
}
mce_log(LL_DEBUG, "thermal state reply: %s", name);
thermal_state_t state = mce_dsme_parse_thermal_state(name);
mce_dsme_datapipe_set_thermal_state(state);
EXIT:
if( rsp ) dbus_message_unref(rsp);
dbus_error_free(&err);
return;
}
/** Cancel pending async thermal state query
*/
static void
mce_dsme_dbus_cancel_thermal_state_query(void)
{
if( mce_dsme_thermal_state_query_pc ) {
mce_log(LL_DEBUG, "cancel thermal state query");
dbus_pending_call_cancel(mce_dsme_thermal_state_query_pc);
dbus_pending_call_unref(mce_dsme_thermal_state_query_pc);
mce_dsme_thermal_state_query_pc = 0;
}
}
/** Initiate async query to find out current thermal state
*/
static void
mce_dsme_dbus_start_thermal_state_query(void)
{
mce_dsme_dbus_cancel_thermal_state_query();
mce_log(LL_DEBUG, "start thermal state query");
dbus_send_ex(thermalmanager_service,
thermalmanager_path,
thermalmanager_interface,
thermalmanager_get_thermal_state,
mce_dsme_dbus_thermal_state_reply_cb, 0, 0,
&mce_dsme_thermal_state_query_pc,
DBUS_TYPE_INVALID);
}
Sep 5, 2015
Sep 5, 2015
864
/** D-Bus callback for the init done notification signal
Dec 16, 2010
Dec 16, 2010
865
866
*
* @param msg The D-Bus message
Sep 5, 2015
Sep 5, 2015
867
868
*
* @return TRUE
Dec 16, 2010
Dec 16, 2010
869
*/
Sep 5, 2015
Sep 5, 2015
870
static gboolean mce_dsme_dbus_init_done_cb(DBusMessage *const msg)
Dec 16, 2010
Dec 16, 2010
871
{
Sep 5, 2015
Sep 5, 2015
872
(void)msg;
Dec 16, 2010
Dec 16, 2010
873
Sep 5, 2015
Sep 5, 2015
874
mce_log(LL_DEVEL, "Received init done notification");
Dec 16, 2010
Dec 16, 2010
875
Sep 5, 2015
Sep 5, 2015
876
877
/* Remove transition submode after brief delay */
mce_dsme_transition_schedule();
Dec 16, 2010
Dec 16, 2010
878
Sep 5, 2015
Sep 5, 2015
879
return TRUE;
Sep 5, 2015
Sep 5, 2015
880
881
882
883
884
885
886
887
888
889
}
/** D-Bus callback for the shutdown notification signal
*
* @param msg The D-Bus message
*
* @return TRUE
*/
static gboolean mce_dsme_dbus_shutdown_cb(DBusMessage *const msg)
{
Sep 5, 2015
Sep 5, 2015
890
(void)msg;
Sep 5, 2015
Sep 5, 2015
891
Sep 5, 2015
Sep 5, 2015
892
893
mce_log(LL_WARN, "Received shutdown notification");
mce_dsme_set_shutting_down(true);
Sep 5, 2015
Sep 5, 2015
894
Sep 5, 2015
Sep 5, 2015
895
return TRUE;
Sep 5, 2015
Sep 5, 2015
896
897
898
899
900
901
902
903
904
905
906
}
/** D-Bus callback for the thermal shutdown notification signal
*
* @param msg The D-Bus message
*
* @return TRUE
*/
static gboolean
mce_dsme_dbus_thermal_shutdown_cb(DBusMessage *const msg)
{
Sep 5, 2015
Sep 5, 2015
907
(void)msg;
Sep 5, 2015
Sep 5, 2015
908
Sep 5, 2015
Sep 5, 2015
909
mce_log(LL_WARN, "Received thermal shutdown notification");
Apr 10, 2018
Apr 10, 2018
910
mce_datapipe_request_display_state(MCE_DISPLAY_ON);
Sep 5, 2015
Sep 5, 2015
911
Sep 5, 2015
Sep 5, 2015
912
return TRUE;
Sep 5, 2015
Sep 5, 2015
913
914
915
916
917
918
919
920
921
922
923
}
/** D-Bus callback for the battery empty shutdown notification signal
*
* @param msg The D-Bus message
*
* @return TRUE
*/
static gboolean
mce_dsme_dbus_battery_empty_shutdown_cb(DBusMessage *const msg)
{
Sep 5, 2015
Sep 5, 2015
924
(void)msg;
Sep 5, 2015
Sep 5, 2015
925
Sep 5, 2015
Sep 5, 2015
926
mce_log(LL_WARN, "Received battery empty shutdown notification");
Apr 10, 2018
Apr 10, 2018
927
mce_datapipe_request_display_state(MCE_DISPLAY_ON);
Dec 16, 2010
Dec 16, 2010
928
Sep 5, 2015
Sep 5, 2015
929
return TRUE;
Dec 16, 2010
Dec 16, 2010
930
931
}
Sep 5, 2015
Sep 5, 2015
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
/** Array of dbus message handlers */
static mce_dbus_handler_t mce_dsme_dbus_handlers[] =
{
/* signals */
{
.interface = "com.nokia.startup.signal",
.name = "init_done",
.type = DBUS_MESSAGE_TYPE_SIGNAL,
.callback = mce_dsme_dbus_init_done_cb,
},
{
.interface = "com.nokia.dsme.signal",
.name = "shutdown_ind",
.type = DBUS_MESSAGE_TYPE_SIGNAL,
.callback = mce_dsme_dbus_shutdown_cb,
},
{
.interface = "com.nokia.dsme.signal",
.name = "thermal_shutdown_ind",
.type = DBUS_MESSAGE_TYPE_SIGNAL,
.callback = mce_dsme_dbus_thermal_shutdown_cb,
},
{
.interface = "com.nokia.dsme.signal",
.name = "battery_empty_ind",
.type = DBUS_MESSAGE_TYPE_SIGNAL,
.callback = mce_dsme_dbus_battery_empty_shutdown_cb,
},
Nov 23, 2018
Nov 23, 2018
960
961
962
963
964
965
{
.interface = thermalmanager_interface,
.name = thermalmanager_state_change_ind,
.type = DBUS_MESSAGE_TYPE_SIGNAL,
.callback = mce_dsme_dbus_thermal_state_change_cb,
},
Sep 5, 2015
Sep 5, 2015
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
/* sentinel */
{
.interface = 0
}
};
/** Add dbus handlers
*/
static void mce_dsme_dbus_init(void)
{
mce_dbus_handler_register_array(mce_dsme_dbus_handlers);
}
/** Remove dbus handlers
*/
static void mce_dsme_dbus_quit(void)
{
mce_dbus_handler_unregister_array(mce_dsme_dbus_handlers);
}
/* ========================================================================= *
* DATAPIPE_TRACKING
* ========================================================================= */
Nov 23, 2018
Nov 23, 2018
990
991
992
993
994
995
996
997
998
999
1000
static void mce_dsme_datapipe_set_thermal_state(thermal_state_t state)
{
if( thermal_state != state ) {
/* All thermal state transitions are of interest - except for the
* UNDEF -> OK that is expected to happen during mce startup. */
int level = LL_WARN;
if( thermal_state == THERMAL_STATE_UNDEF && state == THERMAL_STATE_OK )
level = LL_DEBUG;
mce_log(level, "thermal state changed: %s -> %s",
thermal_state_repr(thermal_state),
thermal_state_repr(state));