| 1 |
// SPDX-License-Identifier: GPL-2.0-only |
| 2 |
/* |
| 3 |
* Copyright 2016 Cisco Systems, Inc. and/or its affiliates. All rights reserved. |
| 4 |
*/ |
| 5 |
|
| 6 |
#include <cerrno> |
| 7 |
#include <ctime> |
| 8 |
#include <string> |
| 9 |
#include <vector> |
| 10 |
|
| 11 |
#include <sys/ioctl.h> |
| 12 |
#include <unistd.h> |
| 13 |
|
| 14 |
#include "cec-compliance.h" |
| 15 |
|
| 16 |
|
| 17 |
static bool get_power_status(struct node *node, unsigned me, unsigned la, __u8 &power_status) |
| 18 |
{ |
| 19 |
struct cec_msg msg; |
| 20 |
|
| 21 |
cec_msg_init(&msg, me, la); |
| 22 |
cec_msg_give_device_power_status(&msg, true); |
| 23 |
msg.timeout = 2000; |
| 24 |
int res = doioctl(node, CEC_TRANSMIT, &msg); |
| 25 |
if (res == ENONET) { |
| 26 |
power_status = CEC_OP_POWER_STATUS_STANDBY; |
| 27 |
return true; |
| 28 |
} |
| 29 |
if (res || !(msg.tx_status & CEC_TX_STATUS_OK) || !(msg.rx_status & CEC_RX_STATUS_OK) || |
| 30 |
cec_msg_status_is_abort(&msg)) |
| 31 |
return false; |
| 32 |
cec_ops_report_power_status(&msg, &power_status); |
| 33 |
return true; |
| 34 |
} |
| 35 |
|
| 36 |
bool util_interactive_ensure_power_state(struct node *node, unsigned me, unsigned la, bool interactive, |
| 37 |
__u8 target_pwr) |
| 38 |
{ |
| 39 |
interactive_info(true, "Please ensure that the device is in state %s.", |
| 40 |
power_status2s(target_pwr)); |
| 41 |
|
| 42 |
if (!node->remote[la].has_power_status) |
| 43 |
return true; |
| 44 |
|
| 45 |
while (interactive) { |
| 46 |
__u8 pwr; |
| 47 |
|
| 48 |
if (!get_power_status(node, me, la, pwr)) |
| 49 |
announce("Failed to retrieve power status."); |
| 50 |
else if (pwr == target_pwr) |
| 51 |
return true; |
| 52 |
else |
| 53 |
announce("The device reported power status %s.", power_status2s(pwr)); |
| 54 |
if (!question("Retry?")) |
| 55 |
return false; |
| 56 |
} |
| 57 |
|
| 58 |
return true; |
| 59 |
} |
| 60 |
|
| 61 |
|
| 62 |
/* Give Device Power Status */ |
| 63 |
|
| 64 |
static int power_status_give(struct node *node, unsigned me, unsigned la, bool interactive) |
| 65 |
{ |
| 66 |
struct cec_msg msg; |
| 67 |
|
| 68 |
cec_msg_init(&msg, me, la); |
| 69 |
cec_msg_give_device_power_status(&msg, true); |
| 70 |
fail_on_test(!transmit_timeout(node, &msg)); |
| 71 |
fail_on_test(timed_out(&msg)); |
| 72 |
fail_on_test(unrecognized_op(&msg)); |
| 73 |
if (refused(&msg)) |
| 74 |
return OK_REFUSED; |
| 75 |
if (cec_msg_status_is_abort(&msg)) |
| 76 |
return OK_PRESUMED; |
| 77 |
|
| 78 |
__u8 power_status; |
| 79 |
cec_ops_report_power_status(&msg, &power_status); |
| 80 |
fail_on_test(power_status >= 4); |
| 81 |
|
| 82 |
return 0; |
| 83 |
} |
| 84 |
|
| 85 |
static int power_status_report(struct node *node, unsigned me, unsigned la, bool interactive) |
| 86 |
{ |
| 87 |
struct cec_msg msg; |
| 88 |
|
| 89 |
cec_msg_init(&msg, me, la); |
| 90 |
cec_msg_report_power_status(&msg, CEC_OP_POWER_STATUS_ON); |
| 91 |
fail_on_test(!transmit_timeout(node, &msg)); |
| 92 |
if (unrecognized_op(&msg)) |
| 93 |
return OK_NOT_SUPPORTED; |
| 94 |
if (refused(&msg)) |
| 95 |
return OK_REFUSED; |
| 96 |
|
| 97 |
return OK_PRESUMED; |
| 98 |
} |
| 99 |
|
| 100 |
const vec_remote_subtests power_status_subtests{ |
| 101 |
{ "Give Device Power Status", CEC_LOG_ADDR_MASK_ALL, power_status_give }, |
| 102 |
{ "Report Device Power Status", CEC_LOG_ADDR_MASK_ALL, power_status_report }, |
| 103 |
}; |
| 104 |
|
| 105 |
/* One Touch Play */ |
| 106 |
|
| 107 |
static int one_touch_play_view_on(struct node *node, unsigned me, unsigned la, |
| 108 |
bool interactive, bool use_raw, __u8 opcode) |
| 109 |
{ |
| 110 |
struct cec_msg msg; |
| 111 |
|
| 112 |
cec_msg_init(&msg, me, la); |
| 113 |
if (opcode == CEC_MSG_IMAGE_VIEW_ON) |
| 114 |
cec_msg_image_view_on(&msg); |
| 115 |
else if (opcode == CEC_MSG_TEXT_VIEW_ON) |
| 116 |
cec_msg_text_view_on(&msg); |
| 117 |
if (use_raw) |
| 118 |
msg.flags |= CEC_MSG_FL_RAW; |
| 119 |
|
| 120 |
int res = doioctl(node, CEC_TRANSMIT, &msg); |
| 121 |
|
| 122 |
if (res == ENONET && la == CEC_LOG_ADDR_TV) { |
| 123 |
msg.msg[0] = (CEC_LOG_ADDR_UNREGISTERED << 4) | la; |
| 124 |
res = doioctl(node, CEC_TRANSMIT, &msg); |
| 125 |
} |
| 126 |
fail_on_test(res || !(msg.tx_status & CEC_TX_STATUS_OK)); |
| 127 |
|
| 128 |
fail_on_test(is_tv(la, node->remote[la].prim_type) && unrecognized_op(&msg)); |
| 129 |
if (refused(&msg)) |
| 130 |
return OK_REFUSED; |
| 131 |
if (cec_msg_status_is_abort(&msg)) |
| 132 |
return OK_PRESUMED; |
| 133 |
if (opcode == CEC_MSG_IMAGE_VIEW_ON) |
| 134 |
node->remote[la].has_image_view_on = true; |
| 135 |
else if (opcode == CEC_MSG_TEXT_VIEW_ON) |
| 136 |
node->remote[la].has_text_view_on = true; |
| 137 |
|
| 138 |
return 0; |
| 139 |
} |
| 140 |
|
| 141 |
static int one_touch_play_image_view_on(struct node *node, unsigned me, unsigned la, bool interactive) |
| 142 |
{ |
| 143 |
return one_touch_play_view_on(node, me, la, interactive, false, CEC_MSG_IMAGE_VIEW_ON); |
| 144 |
} |
| 145 |
|
| 146 |
static int one_touch_play_text_view_on(struct node *node, unsigned me, unsigned la, bool interactive) |
| 147 |
{ |
| 148 |
return one_touch_play_view_on(node, me, la, interactive, false, CEC_MSG_TEXT_VIEW_ON); |
| 149 |
} |
| 150 |
|
| 151 |
static int one_touch_play_view_on_wakeup(struct node *node, unsigned me, unsigned la, bool interactive, |
| 152 |
__u8 opcode) |
| 153 |
{ |
| 154 |
fail_on_test(!util_interactive_ensure_power_state(node, me, la, interactive, CEC_OP_POWER_STATUS_STANDBY)); |
| 155 |
|
| 156 |
int ret = one_touch_play_view_on(node, me, la, interactive, false, opcode); |
| 157 |
|
| 158 |
if (ret && ret != OK_PRESUMED) |
| 159 |
return ret; |
| 160 |
fail_on_test(interactive && !question("Did the TV turn on?")); |
| 161 |
|
| 162 |
if (interactive) |
| 163 |
return 0; |
| 164 |
|
| 165 |
return OK_PRESUMED; |
| 166 |
} |
| 167 |
|
| 168 |
static int one_touch_play_image_view_on_wakeup(struct node *node, unsigned me, unsigned la, bool interactive) |
| 169 |
{ |
| 170 |
if (!interactive || !node->remote[la].has_image_view_on) |
| 171 |
return NOTAPPLICABLE; |
| 172 |
return one_touch_play_view_on_wakeup(node, me, la, interactive, CEC_MSG_IMAGE_VIEW_ON); |
| 173 |
} |
| 174 |
|
| 175 |
static int one_touch_play_text_view_on_wakeup(struct node *node, unsigned me, unsigned la, bool interactive) |
| 176 |
{ |
| 177 |
if (!interactive || !node->remote[la].has_text_view_on) |
| 178 |
return NOTAPPLICABLE; |
| 179 |
return one_touch_play_view_on_wakeup(node, me, la, interactive, CEC_MSG_TEXT_VIEW_ON); |
| 180 |
} |
| 181 |
|
| 182 |
static int one_touch_play_view_on_change(struct node *node, unsigned me, unsigned la, bool interactive, |
| 183 |
__u8 opcode) |
| 184 |
{ |
| 185 |
struct cec_msg msg; |
| 186 |
int ret; |
| 187 |
|
| 188 |
fail_on_test(!util_interactive_ensure_power_state(node, me, la, interactive, CEC_OP_POWER_STATUS_ON)); |
| 189 |
|
| 190 |
interactive_info(true, "Please switch the TV to another source."); |
| 191 |
ret = one_touch_play_view_on(node, me, la, interactive, false, opcode); |
| 192 |
if (ret && ret != OK_PRESUMED) |
| 193 |
return ret; |
| 194 |
cec_msg_init(&msg, me, la); |
| 195 |
cec_msg_active_source(&msg, node->phys_addr); |
| 196 |
fail_on_test(!transmit_timeout(node, &msg)); |
| 197 |
fail_on_test(interactive && !question("Did the TV switch to this source?")); |
| 198 |
|
| 199 |
if (interactive) |
| 200 |
return 0; |
| 201 |
|
| 202 |
return OK_PRESUMED; |
| 203 |
} |
| 204 |
|
| 205 |
static int one_touch_play_image_view_on_change(struct node *node, unsigned me, unsigned la, bool interactive) |
| 206 |
{ |
| 207 |
if (!interactive || !node->remote[la].has_text_view_on) |
| 208 |
return NOTAPPLICABLE; |
| 209 |
return one_touch_play_view_on_change(node, me, la, interactive, CEC_MSG_IMAGE_VIEW_ON); |
| 210 |
} |
| 211 |
|
| 212 |
static int one_touch_play_text_view_on_change(struct node *node, unsigned me, unsigned la, bool interactive) |
| 213 |
{ |
| 214 |
if (!interactive || !node->remote[la].has_text_view_on) |
| 215 |
return NOTAPPLICABLE; |
| 216 |
return one_touch_play_view_on_change(node, me, la, interactive, CEC_MSG_TEXT_VIEW_ON); |
| 217 |
} |
| 218 |
|
| 219 |
static int one_touch_play_req_active_source(struct node *node, unsigned me, unsigned la, bool interactive) |
| 220 |
{ |
| 221 |
struct cec_msg msg; |
| 222 |
|
| 223 |
cec_msg_init(&msg, me, la); |
| 224 |
cec_msg_active_source(&msg, node->phys_addr); |
| 225 |
fail_on_test(!transmit_timeout(node, &msg)); |
| 226 |
|
| 227 |
/* We have now said that we are active source, so receiving a reply to |
| 228 |
Request Active Source should fail the test. */ |
| 229 |
cec_msg_init(&msg, me, la); |
| 230 |
cec_msg_request_active_source(&msg, true); |
| 231 |
fail_on_test(!transmit_timeout(node, &msg)); |
| 232 |
fail_on_test(!timed_out(&msg)); |
| 233 |
|
| 234 |
return 0; |
| 235 |
} |
| 236 |
|
| 237 |
const vec_remote_subtests one_touch_play_subtests{ |
| 238 |
{ "Image View On", CEC_LOG_ADDR_MASK_TV, one_touch_play_image_view_on }, |
| 239 |
{ "Text View On", CEC_LOG_ADDR_MASK_TV, one_touch_play_text_view_on }, |
| 240 |
{ "Wakeup on Image View On", CEC_LOG_ADDR_MASK_TV, one_touch_play_image_view_on_wakeup }, |
| 241 |
{ "Wakeup Text View On", CEC_LOG_ADDR_MASK_TV, one_touch_play_text_view_on_wakeup }, |
| 242 |
{ "Input change on Image View On", CEC_LOG_ADDR_MASK_TV, one_touch_play_image_view_on_change }, |
| 243 |
{ "Input change on Text View On", CEC_LOG_ADDR_MASK_TV, one_touch_play_text_view_on_change }, |
| 244 |
{ "Active Source and Request Active Source", CEC_LOG_ADDR_MASK_ALL, one_touch_play_req_active_source }, |
| 245 |
}; |
| 246 |
|
| 247 |
/* Standby / Resume */ |
| 248 |
|
| 249 |
/* The default sleep time between power status requests. */ |
| 250 |
#define SLEEP_POLL_POWER_STATUS 2 |
| 251 |
|
| 252 |
static bool wait_changing_power_status(struct node *node, unsigned me, unsigned la, __u8 &new_status, |
| 253 |
unsigned &unresponsive_cnt) |
| 254 |
{ |
| 255 |
__u8 old_status; |
| 256 |
time_t t = time(nullptr); |
| 257 |
|
| 258 |
announce("Checking for power status change. This may take up to %llu s.", (long long)long_timeout); |
| 259 |
if (!get_power_status(node, me, la, old_status)) |
| 260 |
return false; |
| 261 |
while (time(nullptr) - t < long_timeout) { |
| 262 |
__u8 power_status; |
| 263 |
|
| 264 |
if (!get_power_status(node, me, la, power_status)) { |
| 265 |
/* Some TVs become completely unresponsive when transitioning |
| 266 |
between power modes. Register that this happens, but continue |
| 267 |
the test. */ |
| 268 |
unresponsive_cnt++; |
| 269 |
} else if (old_status != power_status) { |
| 270 |
new_status = power_status; |
| 271 |
return true; |
| 272 |
} |
| 273 |
sleep(SLEEP_POLL_POWER_STATUS); |
| 274 |
} |
| 275 |
new_status = old_status; |
| 276 |
return false; |
| 277 |
} |
| 278 |
|
| 279 |
static bool poll_stable_power_status(struct node *node, unsigned me, unsigned la, |
| 280 |
__u8 expected_status, unsigned &unresponsive_cnt) |
| 281 |
{ |
| 282 |
bool transient = false; |
| 283 |
unsigned time_to_transient = 0; |
| 284 |
time_t t = time(nullptr); |
| 285 |
|
| 286 |
/* Some devices can use several seconds to transition from one power |
| 287 |
state to another, so the power state must be repeatedly polled */ |
| 288 |
announce("Waiting for new stable power status. This may take up to %llu s.", (long long)long_timeout); |
| 289 |
while (time(nullptr) - t < long_timeout) { |
| 290 |
__u8 power_status; |
| 291 |
|
| 292 |
if (!get_power_status(node, me, la, power_status)) { |
| 293 |
/* Some TVs become completely unresponsive when transitioning |
| 294 |
between power modes. Register that this happens, but continue |
| 295 |
the test. */ |
| 296 |
unresponsive_cnt++; |
| 297 |
sleep(SLEEP_POLL_POWER_STATUS); |
| 298 |
continue; |
| 299 |
} |
| 300 |
if (!transient && (power_status == CEC_OP_POWER_STATUS_TO_ON || |
| 301 |
power_status == CEC_OP_POWER_STATUS_TO_STANDBY)) { |
| 302 |
time_to_transient = time(nullptr) - t; |
| 303 |
transient = true; |
| 304 |
warn_once_on_test(expected_status == CEC_OP_POWER_STATUS_ON && |
| 305 |
power_status == CEC_OP_POWER_STATUS_TO_STANDBY); |
| 306 |
warn_once_on_test(expected_status == CEC_OP_POWER_STATUS_STANDBY && |
| 307 |
power_status == CEC_OP_POWER_STATUS_TO_ON); |
| 308 |
} |
| 309 |
if (power_status == expected_status) { |
| 310 |
if (transient) |
| 311 |
announce("Transient state after %d s, stable state %s after %d s", |
| 312 |
time_to_transient, power_status2s(power_status), (int)(time(NULL) - t)); |
| 313 |
else |
| 314 |
announce("No transient state reported, stable state %s after %d s", |
| 315 |
power_status2s(power_status), (int)(time(NULL) - t)); |
| 316 |
return true; |
| 317 |
} |
| 318 |
sleep(SLEEP_POLL_POWER_STATUS); |
| 319 |
} |
| 320 |
return false; |
| 321 |
} |
| 322 |
|
| 323 |
static int standby_resume_standby(struct node *node, unsigned me, unsigned la, bool interactive) |
| 324 |
{ |
| 325 |
if (!node->remote[la].has_power_status) |
| 326 |
return NOTAPPLICABLE; |
| 327 |
|
| 328 |
struct cec_msg msg; |
| 329 |
unsigned unresponsive_cnt = 0; |
| 330 |
|
| 331 |
fail_on_test(!util_interactive_ensure_power_state(node, me, la, interactive, CEC_OP_POWER_STATUS_ON)); |
| 332 |
|
| 333 |
/* |
| 334 |
* Some displays only accept Standby from the Active Source. |
| 335 |
* So make us the Active Source before sending Standby. |
| 336 |
*/ |
| 337 |
if (is_tv(la, node->remote[la].prim_type)) { |
| 338 |
announce("Sending Active Source message."); |
| 339 |
cec_msg_init(&msg, me, la); |
| 340 |
cec_msg_active_source(&msg, node->phys_addr); |
| 341 |
fail_on_test(doioctl(node, CEC_TRANSMIT, &msg)); |
| 342 |
} |
| 343 |
announce("Sending Standby message."); |
| 344 |
|
| 345 |
cec_msg_init(&msg, me, la); |
| 346 |
cec_msg_standby(&msg); |
| 347 |
fail_on_test(!transmit_timeout(node, &msg)); |
| 348 |
fail_on_test(cec_msg_status_is_abort(&msg)); |
| 349 |
fail_on_test(!poll_stable_power_status(node, me, la, CEC_OP_POWER_STATUS_STANDBY, unresponsive_cnt)); |
| 350 |
fail_on_test(interactive && !question("Is the device in standby?")); |
| 351 |
node->remote[la].in_standby = true; |
| 352 |
|
| 353 |
if (unresponsive_cnt > 0) |
| 354 |
announce("The device went correctly into standby, but was unresponsive %d time%s during the transition.\n", |
| 355 |
unresponsive_cnt, unresponsive_cnt == 1 ? "" : "s"); |
| 356 |
|
| 357 |
return 0; |
| 358 |
} |
| 359 |
|
| 360 |
static int standby_resume_standby_toggle(struct node *node, unsigned me, unsigned la, bool interactive) |
| 361 |
{ |
| 362 |
if (!node->remote[la].in_standby) |
| 363 |
return NOTAPPLICABLE; |
| 364 |
|
| 365 |
struct cec_msg msg; |
| 366 |
unsigned unresponsive_cnt = 0; |
| 367 |
__u8 new_status; |
| 368 |
|
| 369 |
node->remote[la].in_standby = false; |
| 370 |
|
| 371 |
/* Send Standby again to test that it is not acting like a toggle */ |
| 372 |
announce("Sending Standby message."); |
| 373 |
cec_msg_init(&msg, me, la); |
| 374 |
cec_msg_standby(&msg); |
| 375 |
int res = doioctl(node, CEC_TRANSMIT, &msg); |
| 376 |
fail_on_test(res && res != ENONET); |
| 377 |
fail_on_test(cec_msg_status_is_abort(&msg)); |
| 378 |
fail_on_test(wait_changing_power_status(node, me, la, new_status, unresponsive_cnt)); |
| 379 |
fail_on_test(new_status != CEC_OP_POWER_STATUS_STANDBY); |
| 380 |
|
| 381 |
if (res == ENONET) { |
| 382 |
struct cec_caps caps = { }; |
| 383 |
doioctl(node, CEC_ADAP_G_CAPS, &caps); |
| 384 |
unsigned major = caps.version >> 16; |
| 385 |
unsigned minor = (caps.version >> 8) & 0xff; |
| 386 |
if (!strcmp(caps.driver, "pulse8-cec") && |
| 387 |
!((major == 4 && minor == 19) || major > 5 || |
| 388 |
(major == 5 && minor >= 4))) { |
| 389 |
// The cec framework had a bug that prevented it from reliably |
| 390 |
// working with displays that pull down the HPD. This was fixed |
| 391 |
// in commit ac479b51f3f4 for kernel 5.5 and backported to kernels |
| 392 |
// 4.19.94 and 5.4.9. We only warn when the pulse8-cec driver is used, |
| 393 |
// for other CEC devices you hopefully know what you are doing... |
| 394 |
warn("This display appears to pull down the HPD when in Standby. For such\n"); |
| 395 |
warn("displays kernel 4.19 or kernel 5.4 or higher is required.\n"); |
| 396 |
} |
| 397 |
} |
| 398 |
|
| 399 |
fail_on_test(interactive && !question("Is the device still in standby?")); |
| 400 |
node->remote[la].in_standby = true; |
| 401 |
if (unresponsive_cnt > 0) |
| 402 |
announce("The device went correctly into standby, but was unresponsive %d time%s during the transition.\n", |
| 403 |
unresponsive_cnt, unresponsive_cnt == 1 ? "" : "s"); |
| 404 |
|
| 405 |
return 0; |
| 406 |
} |
| 407 |
|
| 408 |
static int standby_resume_active_source_nowake(struct node *node, unsigned me, unsigned la, bool interactive) |
| 409 |
{ |
| 410 |
if (!node->remote[la].in_standby) |
| 411 |
return NOTAPPLICABLE; |
| 412 |
|
| 413 |
struct cec_msg msg; |
| 414 |
unsigned unresponsive_cnt = 0; |
| 415 |
__u8 new_status; |
| 416 |
|
| 417 |
node->remote[la].in_standby = false; |
| 418 |
|
| 419 |
/* |
| 420 |
* In CEC 2.0 it is specified that a device shall not go out of standby |
| 421 |
* if an Active Source message is received. The CEC 1.4 implies this as |
| 422 |
* well, even though it is not as clear about this as the 2.0 spec. |
| 423 |
*/ |
| 424 |
announce("Sending Active Source message."); |
| 425 |
cec_msg_init(&msg, me, la); |
| 426 |
cec_msg_active_source(&msg, node->phys_addr); |
| 427 |
int res = doioctl(node, CEC_TRANSMIT, &msg); |
| 428 |
fail_on_test(res && res != ENONET); |
| 429 |
fail_on_test_v2_warn(node->remote[la].cec_version, |
| 430 |
wait_changing_power_status(node, me, la, new_status, unresponsive_cnt)); |
| 431 |
fail_on_test_v2_warn(node->remote[la].cec_version, |
| 432 |
new_status != CEC_OP_POWER_STATUS_STANDBY); |
| 433 |
if (new_status != CEC_OP_POWER_STATUS_STANDBY) |
| 434 |
return standby_resume_standby(node, me, la, interactive); |
| 435 |
|
| 436 |
node->remote[la].in_standby = true; |
| 437 |
if (unresponsive_cnt > 0) |
| 438 |
warn("The device stayed correctly in standby, but was unresponsive %d time%s.\n", |
| 439 |
unresponsive_cnt, unresponsive_cnt == 1 ? "" : "s"); |
| 440 |
return 0; |
| 441 |
} |
| 442 |
|
| 443 |
static int wakeup_rc(struct node *node, unsigned me, unsigned la) |
| 444 |
{ |
| 445 |
struct cec_msg msg; |
| 446 |
struct cec_op_ui_command rc_press = {}; |
| 447 |
|
| 448 |
/* Todo: A release should be sent after this */ |
| 449 |
cec_msg_init(&msg, me, la); |
| 450 |
rc_press.ui_cmd = CEC_OP_UI_CMD_POWER_ON_FUNCTION; |
| 451 |
cec_msg_user_control_pressed(&msg, &rc_press); |
| 452 |
fail_on_test(!transmit_timeout(node, &msg)); |
| 453 |
fail_on_test(cec_msg_status_is_abort(&msg)); |
| 454 |
|
| 455 |
return 0; |
| 456 |
} |
| 457 |
|
| 458 |
static int wakeup_tv(struct node *node, unsigned me, unsigned la) |
| 459 |
{ |
| 460 |
struct cec_msg msg; |
| 461 |
|
| 462 |
cec_msg_init(&msg, me, la); |
| 463 |
cec_msg_image_view_on(&msg); |
| 464 |
msg.timeout = 2000; |
| 465 |
int res = doioctl(node, CEC_TRANSMIT, &msg); |
| 466 |
if (res == ENONET && la == CEC_LOG_ADDR_TV) { |
| 467 |
msg.msg[0] = (CEC_LOG_ADDR_UNREGISTERED << 4) | la; |
| 468 |
res = doioctl(node, CEC_TRANSMIT, &msg); |
| 469 |
} |
| 470 |
fail_on_test(res || !(msg.tx_status & CEC_TX_STATUS_OK)); |
| 471 |
if (!cec_msg_status_is_abort(&msg)) |
| 472 |
return 0; |
| 473 |
|
| 474 |
cec_msg_init(&msg, me, la); |
| 475 |
cec_msg_text_view_on(&msg); |
| 476 |
fail_on_test(!transmit_timeout(node, &msg)); |
| 477 |
if (!cec_msg_status_is_abort(&msg)) |
| 478 |
return 0; |
| 479 |
|
| 480 |
return wakeup_rc(node, me, la); |
| 481 |
} |
| 482 |
|
| 483 |
static int wakeup_source(struct node *node, unsigned me, unsigned la) |
| 484 |
{ |
| 485 |
struct cec_msg msg; |
| 486 |
|
| 487 |
cec_msg_init(&msg, me, la); |
| 488 |
cec_msg_set_stream_path(&msg, node->remote[la].phys_addr); |
| 489 |
fail_on_test(!transmit_timeout(node, &msg)); |
| 490 |
if (!cec_msg_status_is_abort(&msg)) |
| 491 |
return 0; |
| 492 |
|
| 493 |
return wakeup_rc(node, me, la); |
| 494 |
} |
| 495 |
|
| 496 |
int standby_resume_wakeup(struct node *node, unsigned me, unsigned la, bool interactive) |
| 497 |
{ |
| 498 |
if (!node->remote[la].in_standby) |
| 499 |
return NOTAPPLICABLE; |
| 500 |
|
| 501 |
int ret; |
| 502 |
|
| 503 |
if (is_tv(la, node->remote[la].prim_type)) |
| 504 |
ret = wakeup_tv(node, me, la); |
| 505 |
else |
| 506 |
ret = wakeup_source(node, me, la); |
| 507 |
if (ret) |
| 508 |
return ret; |
| 509 |
|
| 510 |
unsigned unresponsive_cnt = 0; |
| 511 |
|
| 512 |
announce("Wait for device to wake up"); |
| 513 |
fail_on_test(!poll_stable_power_status(node, me, la, CEC_OP_POWER_STATUS_ON, unresponsive_cnt)); |
| 514 |
fail_on_test(interactive && !question("Is the device in On state?")); |
| 515 |
|
| 516 |
if (unresponsive_cnt > 0) |
| 517 |
announce("The device went correctly out of standby, but was unresponsive %d time%s during the transition.\n", |
| 518 |
unresponsive_cnt, unresponsive_cnt == 1 ? "" : "s"); |
| 519 |
|
| 520 |
return 0; |
| 521 |
} |
| 522 |
|
| 523 |
static int standby_resume_wakeup_view_on(struct node *node, unsigned me, unsigned la, bool interactive, |
| 524 |
__u8 opcode, bool from_unregistered) |
| 525 |
{ |
| 526 |
if (!is_tv(la, node->remote[la].prim_type)) |
| 527 |
return NOTAPPLICABLE; |
| 528 |
if (me == CEC_LOG_ADDR_UNREGISTERED && from_unregistered) |
| 529 |
return NOTAPPLICABLE; |
| 530 |
|
| 531 |
if (from_unregistered) { |
| 532 |
cec_msg msg; |
| 533 |
int res; |
| 534 |
|
| 535 |
// Check if we have permission to use CEC_MSG_FL_RAW. |
| 536 |
// It relies on CAP_SYS_RAWIO being set. |
| 537 |
cec_msg_init(&msg, me, la); |
| 538 |
msg.flags |= CEC_MSG_FL_RAW; |
| 539 |
res = doioctl(node, CEC_TRANSMIT, &msg); |
| 540 |
if (res == EPERM) |
| 541 |
return NOTAPPLICABLE; |
| 542 |
} |
| 543 |
|
| 544 |
unsigned unresponsive_cnt = 0; |
| 545 |
|
| 546 |
sleep(5); |
| 547 |
fail_on_test(!poll_stable_power_status(node, me, la, CEC_OP_POWER_STATUS_ON, unresponsive_cnt)); |
| 548 |
|
| 549 |
int ret = standby_resume_standby(node, me, la, interactive); |
| 550 |
|
| 551 |
if (ret && opcode == CEC_MSG_TEXT_VIEW_ON) { |
| 552 |
ret = standby_resume_standby(node, me, la, interactive); |
| 553 |
if (!ret) |
| 554 |
warn("A STANDBY was sent right after the display reports it was powered on, but it was ignored.\n"); |
| 555 |
} |
| 556 |
|
| 557 |
if (ret) |
| 558 |
return ret; |
| 559 |
|
| 560 |
sleep(6); |
| 561 |
|
| 562 |
ret = one_touch_play_view_on(node, from_unregistered ? CEC_LOG_ADDR_UNREGISTERED : me, |
| 563 |
la, interactive, from_unregistered, opcode); |
| 564 |
|
| 565 |
if (ret) |
| 566 |
return ret; |
| 567 |
|
| 568 |
announce("Wait for device to wake up"); |
| 569 |
unresponsive_cnt = 0; |
| 570 |
fail_on_test(!poll_stable_power_status(node, me, la, CEC_OP_POWER_STATUS_ON, unresponsive_cnt)); |
| 571 |
fail_on_test(interactive && !question("Is the device in On state?")); |
| 572 |
|
| 573 |
struct cec_msg msg; |
| 574 |
|
| 575 |
cec_msg_init(&msg, me, la); |
| 576 |
cec_msg_active_source(&msg, node->phys_addr); |
| 577 |
fail_on_test(!transmit_timeout(node, &msg)); |
| 578 |
|
| 579 |
if (unresponsive_cnt > 0) |
| 580 |
announce("The device went correctly out of standby, but was unresponsive %d time%s during the transition.\n", |
| 581 |
unresponsive_cnt, unresponsive_cnt == 1 ? "" : "s"); |
| 582 |
|
| 583 |
return 0; |
| 584 |
} |
| 585 |
|
| 586 |
static int standby_resume_wakeup_image_view_on(struct node *node, unsigned me, unsigned la, bool interactive) |
| 587 |
{ |
| 588 |
return standby_resume_wakeup_view_on(node, me, la, interactive, CEC_MSG_IMAGE_VIEW_ON, false); |
| 589 |
} |
| 590 |
|
| 591 |
static int standby_resume_wakeup_text_view_on(struct node *node, unsigned me, unsigned la, bool interactive) |
| 592 |
{ |
| 593 |
return standby_resume_wakeup_view_on(node, me, la, interactive, CEC_MSG_TEXT_VIEW_ON, false); |
| 594 |
} |
| 595 |
|
| 596 |
static int standby_resume_wakeup_unreg_image_view_on(struct node *node, unsigned me, unsigned la, bool interactive) |
| 597 |
{ |
| 598 |
return standby_resume_wakeup_view_on(node, me, la, interactive, CEC_MSG_IMAGE_VIEW_ON, true); |
| 599 |
} |
| 600 |
|
| 601 |
static int standby_resume_wakeup_unreg_text_view_on(struct node *node, unsigned me, unsigned la, bool interactive) |
| 602 |
{ |
| 603 |
return standby_resume_wakeup_view_on(node, me, la, interactive, CEC_MSG_TEXT_VIEW_ON, true); |
| 604 |
} |
| 605 |
|
| 606 |
/* Test CEC 2.0 Power State Transitions (see HDMI 2.1, 11.5.5) */ |
| 607 |
static int power_state_transitions(struct node *node, unsigned me, unsigned la, bool interactive) |
| 608 |
{ |
| 609 |
struct cec_msg msg = {}; |
| 610 |
|
| 611 |
mode_set_follower(node); |
| 612 |
msg.timeout = 1000; |
| 613 |
doioctl(node, CEC_RECEIVE, &msg); |
| 614 |
cec_msg_init(&msg, me, la); |
| 615 |
cec_msg_standby(&msg); |
| 616 |
fail_on_test(!transmit_timeout(node, &msg)); |
| 617 |
time_t start = time(nullptr); |
| 618 |
int res = util_receive(node, la, long_timeout * 1000, &msg, CEC_MSG_STANDBY, |
| 619 |
CEC_MSG_REPORT_POWER_STATUS); |
| 620 |
fail_on_test(!res); |
| 621 |
if (res < 0) { |
| 622 |
warn("No Report Power Status seen when going to standby.\n"); |
| 623 |
info("This might be due to the bug fix in commit cec935ce69fc\n"); |
| 624 |
info("However, this was fixed in 5.5 and has been backported to LTS kernels,\n"); |
| 625 |
info("so any kernel released after January 2020 should have this fix.\n"); |
| 626 |
return OK_PRESUMED; |
| 627 |
} |
| 628 |
if (time(nullptr) - start > 3) |
| 629 |
warn("The first Report Power Status broadcast arrived > 3s after sending <Standby>\n"); |
| 630 |
if (msg.msg[2] == CEC_OP_POWER_STATUS_STANDBY) |
| 631 |
return 0; |
| 632 |
fail_on_test(msg.msg[2] != CEC_OP_POWER_STATUS_TO_STANDBY); |
| 633 |
fail_on_test(util_receive(node, la, long_timeout * 1000, &msg, CEC_MSG_STANDBY, |
| 634 |
CEC_MSG_REPORT_POWER_STATUS) <= 0); |
| 635 |
fail_on_test(msg.msg[2] != CEC_OP_POWER_STATUS_STANDBY); |
| 636 |
|
| 637 |
cec_msg_init(&msg, me, la); |
| 638 |
__u8 opcode; |
| 639 |
if (is_tv(la, node->remote[la].prim_type)) { |
| 640 |
cec_msg_image_view_on(&msg); |
| 641 |
opcode = msg.msg[2]; |
| 642 |
|
| 643 |
int res = doioctl(node, CEC_TRANSMIT, &msg); |
| 644 |
|
| 645 |
if (res == ENONET && la == CEC_LOG_ADDR_TV) { |
| 646 |
msg.msg[0] = (CEC_LOG_ADDR_UNREGISTERED << 4) | la; |
| 647 |
fail_on_test(doioctl(node, CEC_TRANSMIT, &msg)); |
| 648 |
} |
| 649 |
} else { |
| 650 |
cec_msg_set_stream_path(&msg, node->remote[la].phys_addr); |
| 651 |
opcode = msg.msg[2]; |
| 652 |
fail_on_test(doioctl(node, CEC_TRANSMIT, &msg)); |
| 653 |
} |
| 654 |
fail_on_test(!(msg.tx_status & CEC_TX_STATUS_OK)); |
| 655 |
start = time(nullptr); |
| 656 |
fail_on_test(util_receive(node, la, long_timeout * 1000, &msg, opcode, |
| 657 |
CEC_MSG_REPORT_POWER_STATUS) <= 0); |
| 658 |
if (time(nullptr) - start > 3) |
| 659 |
warn("The first Report Power Status broadcast arrived > 3s after sending <%s>\n", |
| 660 |
opcode == CEC_MSG_IMAGE_VIEW_ON ? "Image View On" : "Set Stream Path"); |
| 661 |
if (msg.msg[2] == CEC_OP_POWER_STATUS_ON) |
| 662 |
return 0; |
| 663 |
fail_on_test(msg.msg[2] != CEC_OP_POWER_STATUS_TO_ON); |
| 664 |
fail_on_test(util_receive(node, la, long_timeout * 1000, &msg, opcode, |
| 665 |
CEC_MSG_REPORT_POWER_STATUS) <= 0); |
| 666 |
fail_on_test(msg.msg[2] != CEC_OP_POWER_STATUS_ON); |
| 667 |
|
| 668 |
return 0; |
| 669 |
} |
| 670 |
|
| 671 |
static int standby_resume_wakeup_deck(struct node *node, unsigned me, unsigned la, bool interactive, __u8 opcode) |
| 672 |
{ |
| 673 |
struct cec_msg msg; |
| 674 |
|
| 675 |
cec_msg_init(&msg, me, la); |
| 676 |
cec_msg_give_deck_status(&msg, true, CEC_OP_STATUS_REQ_ONCE); |
| 677 |
fail_on_test(!transmit_timeout(node, &msg)); |
| 678 |
if (timed_out_or_abort(&msg)) |
| 679 |
return OK_NOT_SUPPORTED; |
| 680 |
|
| 681 |
unsigned unresponsive_cnt = 0; |
| 682 |
|
| 683 |
fail_on_test(!poll_stable_power_status(node, me, la, CEC_OP_POWER_STATUS_ON, unresponsive_cnt)); |
| 684 |
|
| 685 |
int ret = standby_resume_standby(node, me, la, interactive); |
| 686 |
|
| 687 |
if (ret) |
| 688 |
return ret; |
| 689 |
|
| 690 |
cec_msg_init(&msg, me, la); |
| 691 |
if (opcode == CEC_OP_PLAY_MODE_PLAY_FWD) |
| 692 |
cec_msg_play(&msg, CEC_OP_PLAY_MODE_PLAY_FWD); |
| 693 |
else |
| 694 |
cec_msg_deck_control(&msg, CEC_OP_DECK_CTL_MODE_EJECT); |
| 695 |
fail_on_test(!transmit_timeout(node, &msg)); |
| 696 |
fail_on_test(cec_msg_status_is_abort(&msg)); |
| 697 |
|
| 698 |
unresponsive_cnt = 0; |
| 699 |
fail_on_test(!poll_stable_power_status(node, me, la, CEC_OP_POWER_STATUS_ON, unresponsive_cnt)); |
| 700 |
fail_on_test(interactive && !question("Is the device in On state?")); |
| 701 |
|
| 702 |
return OK; |
| 703 |
} |
| 704 |
|
| 705 |
static int standby_resume_wakeup_deck_eject(struct node *node, unsigned me, unsigned la, bool interactive) |
| 706 |
{ |
| 707 |
return standby_resume_wakeup_deck(node, me, la, interactive, CEC_OP_DECK_CTL_MODE_EJECT); |
| 708 |
} |
| 709 |
|
| 710 |
static int standby_resume_wakeup_deck_play(struct node *node, unsigned me, unsigned la, bool interactive) |
| 711 |
{ |
| 712 |
return standby_resume_wakeup_deck(node, me, la, interactive, CEC_OP_PLAY_MODE_PLAY_FWD); |
| 713 |
} |
| 714 |
|
| 715 |
static int standby_record(struct node *node, unsigned me, unsigned la, bool interactive, bool active_source) |
| 716 |
{ |
| 717 |
struct cec_msg msg; |
| 718 |
__u8 rec_status; |
| 719 |
unsigned unresponsive_cnt = 0; |
| 720 |
|
| 721 |
cec_msg_init(&msg, me, la); |
| 722 |
cec_msg_record_on_own(&msg); |
| 723 |
msg.reply = CEC_MSG_RECORD_STATUS; |
| 724 |
fail_on_test(!transmit_timeout(node, &msg, 10000)); |
| 725 |
if (timed_out_or_abort(&msg)) |
| 726 |
return OK_NOT_SUPPORTED; |
| 727 |
cec_ops_record_status(&msg, &rec_status); |
| 728 |
fail_on_test(rec_status != CEC_OP_RECORD_STATUS_CUR_SRC && |
| 729 |
rec_status != CEC_OP_RECORD_STATUS_ALREADY_RECORDING); |
| 730 |
|
| 731 |
cec_msg_init(&msg, me, la); |
| 732 |
if (active_source) |
| 733 |
cec_msg_active_source(&msg, node->remote[la].phys_addr); |
| 734 |
else |
| 735 |
cec_msg_active_source(&msg, me); |
| 736 |
fail_on_test(!transmit_timeout(node, &msg)); |
| 737 |
|
| 738 |
cec_msg_init(&msg, me, la); |
| 739 |
cec_msg_standby(&msg); |
| 740 |
fail_on_test(!transmit_timeout(node, &msg)); |
| 741 |
/* Standby should not interrupt the recording. */ |
| 742 |
fail_on_test(!poll_stable_power_status(node, me, la, CEC_OP_POWER_STATUS_ON, unresponsive_cnt)); |
| 743 |
|
| 744 |
cec_msg_init(&msg, me, la); |
| 745 |
cec_msg_record_off(&msg, false); |
| 746 |
fail_on_test(!transmit_timeout(node, &msg)); |
| 747 |
|
| 748 |
/* When the recording stops, recorder should standby unless it is the active source. */ |
| 749 |
if (active_source) { |
| 750 |
fail_on_test(!poll_stable_power_status(node, me, la, CEC_OP_POWER_STATUS_ON, unresponsive_cnt)); |
| 751 |
} else { |
| 752 |
fail_on_test(!poll_stable_power_status(node, me, la, CEC_OP_POWER_STATUS_STANDBY, unresponsive_cnt)); |
| 753 |
fail_on_test(interactive && !question("Is the device in standby?")); |
| 754 |
node->remote[la].in_standby = true; |
| 755 |
|
| 756 |
int ret = standby_resume_wakeup(node, me, la, interactive); |
| 757 |
if (ret) |
| 758 |
return ret; |
| 759 |
node->remote[la].in_standby = false; |
| 760 |
} |
| 761 |
|
| 762 |
return OK; |
| 763 |
} |
| 764 |
|
| 765 |
static int standby_record_active_source(struct node *node, unsigned me, unsigned la, bool interactive) |
| 766 |
{ |
| 767 |
return standby_record(node, me, la, interactive, true); |
| 768 |
} |
| 769 |
|
| 770 |
static int standby_record_inactive_source(struct node *node, unsigned me, unsigned la, bool interactive) |
| 771 |
{ |
| 772 |
return standby_record(node, me, la, interactive, false); |
| 773 |
} |
| 774 |
|
| 775 |
const vec_remote_subtests standby_resume_subtests{ |
| 776 |
{ "Standby", CEC_LOG_ADDR_MASK_ALL, standby_resume_standby }, |
| 777 |
{ "Repeated Standby message does not wake up", CEC_LOG_ADDR_MASK_ALL, standby_resume_standby_toggle }, |
| 778 |
{ "Standby: Feature aborts unknown messages", CEC_LOG_ADDR_MASK_ALL, core_unknown, true }, |
| 779 |
{ "Standby: Feature aborts Abort message", CEC_LOG_ADDR_MASK_ALL, core_abort, true }, |
| 780 |
{ "Standby: Polling Message", CEC_LOG_ADDR_MASK_ALL, system_info_polling, true }, |
| 781 |
{ "Standby: Give Device Power Status", CEC_LOG_ADDR_MASK_ALL, power_status_give, true }, |
| 782 |
{ "Standby: Give Physical Address", CEC_LOG_ADDR_MASK_ALL, system_info_phys_addr, true }, |
| 783 |
{ "Standby: Give CEC Version", CEC_LOG_ADDR_MASK_ALL, system_info_version, true }, |
| 784 |
{ "Standby: Give Device Vendor ID", CEC_LOG_ADDR_MASK_ALL, vendor_specific_commands_id, true }, |
| 785 |
{ "Standby: Give OSD Name", CEC_LOG_ADDR_MASK_ALL, device_osd_transfer_give, true }, |
| 786 |
{ "Standby: Get Menu Language", CEC_LOG_ADDR_MASK_ALL, system_info_get_menu_lang, true }, |
| 787 |
{ "Standby: Give Device Features", CEC_LOG_ADDR_MASK_ALL, system_info_give_features, true }, |
| 788 |
{ "No wakeup on Active Source", CEC_LOG_ADDR_MASK_ALL, standby_resume_active_source_nowake }, |
| 789 |
{ "Wake up", CEC_LOG_ADDR_MASK_ALL, standby_resume_wakeup }, |
| 790 |
{ "Wake up TV on Image View On", CEC_LOG_ADDR_MASK_TV, standby_resume_wakeup_image_view_on }, |
| 791 |
{ "Wake up TV on Text View On", CEC_LOG_ADDR_MASK_TV, standby_resume_wakeup_text_view_on }, |
| 792 |
{ "Wake up TV on Image View On from Unregistered", CEC_LOG_ADDR_MASK_TV, standby_resume_wakeup_unreg_image_view_on }, |
| 793 |
{ "Wake up TV on Text View On from Unregistered", CEC_LOG_ADDR_MASK_TV, standby_resume_wakeup_unreg_text_view_on }, |
| 794 |
{ "Power State Transitions", CEC_LOG_ADDR_MASK_TV, power_state_transitions, false, true }, |
| 795 |
{ "Deck Eject Standby Resume", CEC_LOG_ADDR_MASK_PLAYBACK | CEC_LOG_ADDR_MASK_RECORD, standby_resume_wakeup_deck_eject }, |
| 796 |
{ "Deck Play Standby Resume", CEC_LOG_ADDR_MASK_PLAYBACK | CEC_LOG_ADDR_MASK_RECORD, standby_resume_wakeup_deck_play }, |
| 797 |
{ "Record Standby Active Source", CEC_LOG_ADDR_MASK_RECORD | CEC_LOG_ADDR_MASK_BACKUP, standby_record_active_source }, |
| 798 |
{ "Record Standby Inactive Source", CEC_LOG_ADDR_MASK_RECORD | CEC_LOG_ADDR_MASK_BACKUP, standby_record_inactive_source }, |
| 799 |
}; |