Linux Audio

Check our new training course

Embedded Linux Audio

Check our new training course
with Creative Commons CC-BY-SA
lecture materials

Bootlin logo

Elixir Cross Referencer

Loading...
  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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
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
235
236
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
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
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
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
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
/*
 * Copyright 2018 Advanced Micro Devices, Inc.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 *
 * Authors: AMD
 *
 */

#include "hdcp.h"

enum mod_hdcp_status mod_hdcp_hdcp2_transition(struct mod_hdcp *hdcp,
		struct mod_hdcp_event_context *event_ctx,
		struct mod_hdcp_transition_input_hdcp2 *input,
		struct mod_hdcp_output *output)
{
	enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS;
	struct mod_hdcp_connection *conn = &hdcp->connection;
	struct mod_hdcp_link_adjustment *adjust = &hdcp->connection.link.adjust;

	switch (current_state(hdcp)) {
	case H2_A0_KNOWN_HDCP2_CAPABLE_RX:
		if (input->hdcp2version_read != PASS ||
				input->hdcp2_capable_check != PASS) {
			adjust->hdcp2.disable = 1;
			callback_in_ms(0, output);
			set_state_id(hdcp, output, HDCP_INITIALIZED);
		} else {
			callback_in_ms(0, output);
			set_state_id(hdcp, output, H2_A1_SEND_AKE_INIT);
		}
		break;
	case H2_A1_SEND_AKE_INIT:
		if (input->create_session != PASS ||
				input->ake_init_prepare != PASS) {
			/* out of sync with psp state */
			adjust->hdcp2.disable = 1;
			fail_and_restart_in_ms(0, &status, output);
			break;
		} else if (input->ake_init_write != PASS) {
			fail_and_restart_in_ms(0, &status, output);
			break;
		}
		set_watchdog_in_ms(hdcp, 100, output);
		callback_in_ms(0, output);
		set_state_id(hdcp, output, H2_A1_VALIDATE_AKE_CERT);
		break;
	case H2_A1_VALIDATE_AKE_CERT:
		if (input->ake_cert_available != PASS) {
			if (event_ctx->event ==
					MOD_HDCP_EVENT_WATCHDOG_TIMEOUT) {
				/* 1A-08: consider ake timeout a failure */
				/* some hdmi receivers are not ready for HDCP
				 * immediately after video becomes active,
				 * delay 1s before retry on first HDCP message
				 * timeout.
				 */
				fail_and_restart_in_ms(1000, &status, output);
			} else {
				/* continue ake cert polling*/
				callback_in_ms(10, output);
				increment_stay_counter(hdcp);
			}
			break;
		} else if (input->ake_cert_read != PASS ||
				input->ake_cert_validation != PASS) {
			/*
			 * 1A-09: consider invalid ake cert a failure
			 * 1A-10: consider receiver id listed in SRM a failure
			 */
			fail_and_restart_in_ms(0, &status, output);
			break;
		}
		if (conn->is_km_stored &&
				!adjust->hdcp2.force_no_stored_km) {
			callback_in_ms(0, output);
			set_state_id(hdcp, output, H2_A1_SEND_STORED_KM);
		} else {
			callback_in_ms(0, output);
			set_state_id(hdcp, output, H2_A1_SEND_NO_STORED_KM);
		}
		break;
	case H2_A1_SEND_NO_STORED_KM:
		if (input->no_stored_km_write != PASS) {
			fail_and_restart_in_ms(0, &status, output);
			break;
		}
		if (adjust->hdcp2.increase_h_prime_timeout)
			set_watchdog_in_ms(hdcp, 2000, output);
		else
			set_watchdog_in_ms(hdcp, 1000, output);
		callback_in_ms(0, output);
		set_state_id(hdcp, output, H2_A1_READ_H_PRIME);
		break;
	case H2_A1_READ_H_PRIME:
		if (input->h_prime_available != PASS) {
			if (event_ctx->event ==
					MOD_HDCP_EVENT_WATCHDOG_TIMEOUT) {
				/* 1A-11-3: consider h' timeout a failure */
				fail_and_restart_in_ms(1000, &status, output);
			} else {
				/* continue h' polling */
				callback_in_ms(100, output);
				increment_stay_counter(hdcp);
			}
			break;
		} else if (input->h_prime_read != PASS) {
			fail_and_restart_in_ms(0, &status, output);
			break;
		}
		set_watchdog_in_ms(hdcp, 200, output);
		callback_in_ms(0, output);
		set_state_id(hdcp, output, H2_A1_READ_PAIRING_INFO_AND_VALIDATE_H_PRIME);
		break;
	case H2_A1_READ_PAIRING_INFO_AND_VALIDATE_H_PRIME:
		if (input->pairing_available != PASS) {
			if (event_ctx->event ==
					MOD_HDCP_EVENT_WATCHDOG_TIMEOUT) {
				/* 1A-12: consider pairing info timeout
				 * a failure
				 */
				fail_and_restart_in_ms(0, &status, output);
			} else {
				/* continue pairing info polling */
				callback_in_ms(20, output);
				increment_stay_counter(hdcp);
			}
			break;
		} else if (input->pairing_info_read != PASS ||
				input->h_prime_validation != PASS) {
			/* 1A-11-1: consider invalid h' a failure */
			fail_and_restart_in_ms(0, &status, output);
			break;
		}
		callback_in_ms(0, output);
		set_state_id(hdcp, output, H2_A2_LOCALITY_CHECK);
		break;
	case H2_A1_SEND_STORED_KM:
		if (input->stored_km_write != PASS) {
			fail_and_restart_in_ms(0, &status, output);
			break;
		}
		set_watchdog_in_ms(hdcp, 200, output);
		callback_in_ms(0, output);
		set_state_id(hdcp, output, H2_A1_VALIDATE_H_PRIME);
		break;
	case H2_A1_VALIDATE_H_PRIME:
		if (input->h_prime_available != PASS) {
			if (event_ctx->event ==
					MOD_HDCP_EVENT_WATCHDOG_TIMEOUT) {
				/* 1A-11-2: consider h' timeout a failure */
				fail_and_restart_in_ms(1000, &status, output);
			} else {
				/* continue h' polling */
				callback_in_ms(20, output);
				increment_stay_counter(hdcp);
			}
			break;
		} else if (input->h_prime_read != PASS) {
			fail_and_restart_in_ms(0, &status, output);
			break;
		} else if (input->h_prime_validation != PASS) {
			/* 1A-11-1: consider invalid h' a failure */
			adjust->hdcp2.force_no_stored_km = 1;
			fail_and_restart_in_ms(0, &status, output);
			break;
		}
		callback_in_ms(0, output);
		set_state_id(hdcp, output, H2_A2_LOCALITY_CHECK);
		break;
	case H2_A2_LOCALITY_CHECK:
		if (hdcp->state.stay_count > 10 ||
				input->lc_init_prepare != PASS ||
				input->lc_init_write != PASS ||
				input->l_prime_available_poll != PASS ||
				input->l_prime_read != PASS) {
			/*
			 * 1A-05: consider disconnection after LC init a failure
			 * 1A-13-1: consider invalid l' a failure
			 * 1A-13-2: consider l' timeout a failure
			 */
			fail_and_restart_in_ms(0, &status, output);
			break;
		} else if (input->l_prime_validation != PASS) {
			callback_in_ms(0, output);
			increment_stay_counter(hdcp);
			break;
		}
		callback_in_ms(0, output);
		set_state_id(hdcp, output, H2_A3_EXCHANGE_KS_AND_TEST_FOR_REPEATER);
		break;
	case H2_A3_EXCHANGE_KS_AND_TEST_FOR_REPEATER:
		if (input->eks_prepare != PASS ||
				input->eks_write != PASS) {
			fail_and_restart_in_ms(0, &status, output);
			break;
		}
		if (conn->is_repeater) {
			set_watchdog_in_ms(hdcp, 3000, output);
			callback_in_ms(0, output);
			set_state_id(hdcp, output, H2_A6_WAIT_FOR_RX_ID_LIST);
		} else {
			/* some CTS equipment requires a delay GREATER than
			 * 200 ms, so delay 210 ms instead of 200 ms
			 */
			callback_in_ms(210, output);
			set_state_id(hdcp, output, H2_ENABLE_ENCRYPTION);
		}
		break;
	case H2_ENABLE_ENCRYPTION:
		if (input->rxstatus_read != PASS ||
				input->reauth_request_check != PASS) {
			/*
			 * 1A-07: restart hdcp on REAUTH_REQ
			 * 1B-08: restart hdcp on REAUTH_REQ
			 */
			fail_and_restart_in_ms(0, &status, output);
			break;
		} else if (event_ctx->rx_id_list_ready && conn->is_repeater) {
			callback_in_ms(0, output);
			set_state_id(hdcp, output, H2_A78_VERIFY_RX_ID_LIST_AND_SEND_ACK);
			break;
		} else if (input->enable_encryption != PASS) {
			fail_and_restart_in_ms(0, &status, output);
			break;
		}
		callback_in_ms(0, output);
		set_state_id(hdcp, output, H2_A5_AUTHENTICATED);
		set_auth_complete(hdcp, output);
		break;
	case H2_A5_AUTHENTICATED:
		if (input->rxstatus_read == FAIL ||
				input->reauth_request_check == FAIL) {
			fail_and_restart_in_ms(0, &status, output);
			break;
		} else if (event_ctx->rx_id_list_ready && conn->is_repeater) {
			callback_in_ms(0, output);
			set_state_id(hdcp, output, H2_A78_VERIFY_RX_ID_LIST_AND_SEND_ACK);
			break;
		}
		callback_in_ms(500, output);
		increment_stay_counter(hdcp);
		break;
	case H2_A6_WAIT_FOR_RX_ID_LIST:
		if (input->rxstatus_read != PASS ||
				input->reauth_request_check != PASS) {
			fail_and_restart_in_ms(0, &status, output);
			break;
		} else if (!event_ctx->rx_id_list_ready) {
			if (event_ctx->event == MOD_HDCP_EVENT_WATCHDOG_TIMEOUT) {
				/* 1B-02: consider rx id list timeout a failure */
				/* some CTS equipment's actual timeout
				 * measurement is slightly greater than 3000 ms.
				 * Delay 100 ms to ensure it is fully timeout
				 * before re-authentication.
				 */
				fail_and_restart_in_ms(100, &status, output);
			} else {
				callback_in_ms(300, output);
				increment_stay_counter(hdcp);
			}
			break;
		}
		callback_in_ms(0, output);
		set_state_id(hdcp, output, H2_A78_VERIFY_RX_ID_LIST_AND_SEND_ACK);
		break;
	case H2_A78_VERIFY_RX_ID_LIST_AND_SEND_ACK:
		if (input->rxstatus_read != PASS ||
				input->reauth_request_check != PASS ||
				input->rx_id_list_read != PASS ||
				input->device_count_check != PASS ||
				input->rx_id_list_validation != PASS ||
				input->repeater_auth_ack_write != PASS) {
			/* 1B-03: consider invalid v' a failure
			 * 1B-04: consider MAX_DEVS_EXCEEDED a failure
			 * 1B-05: consider MAX_CASCADE_EXCEEDED a failure
			 * 1B-06: consider invalid seq_num_V a failure
			 * 1B-09: consider seq_num_V rollover a failure
			 */
			fail_and_restart_in_ms(0, &status, output);
			break;
		}
		callback_in_ms(0, output);
		set_state_id(hdcp, output, H2_A9_SEND_STREAM_MANAGEMENT);
		break;
	case H2_A9_SEND_STREAM_MANAGEMENT:
		if (input->rxstatus_read != PASS ||
				input->reauth_request_check != PASS) {
			fail_and_restart_in_ms(0, &status, output);
			break;
		} else if (event_ctx->rx_id_list_ready && conn->is_repeater) {
			callback_in_ms(0, output);
			set_state_id(hdcp, output, H2_A78_VERIFY_RX_ID_LIST_AND_SEND_ACK);
			break;
		} else if (input->prepare_stream_manage != PASS ||
				input->stream_manage_write != PASS) {
			fail_and_restart_in_ms(0, &status, output);
			break;
		}
		set_watchdog_in_ms(hdcp, 100, output);
		callback_in_ms(0, output);
		set_state_id(hdcp, output, H2_A9_VALIDATE_STREAM_READY);
		break;
	case H2_A9_VALIDATE_STREAM_READY:
		if (input->rxstatus_read != PASS ||
				input->reauth_request_check != PASS) {
			fail_and_restart_in_ms(0, &status, output);
			break;
		} else if (event_ctx->rx_id_list_ready && conn->is_repeater) {
			callback_in_ms(0, output);
			set_state_id(hdcp, output, H2_A78_VERIFY_RX_ID_LIST_AND_SEND_ACK);
			break;
		} else if (input->stream_ready_available != PASS) {
			if (event_ctx->event == MOD_HDCP_EVENT_WATCHDOG_TIMEOUT) {
				/* 1B-10-2: restart content stream management on
				 * stream ready timeout
				 */
				hdcp->auth.count.stream_management_retry_count++;
				callback_in_ms(0, output);
				set_state_id(hdcp, output, H2_A9_SEND_STREAM_MANAGEMENT);
			} else {
				callback_in_ms(10, output);
				increment_stay_counter(hdcp);
			}
			break;
		} else if (input->stream_ready_read != PASS ||
				input->stream_ready_validation != PASS) {
			/*
			 * 1B-10-1: restart content stream management
			 * on invalid M'
			 */
			if (hdcp->auth.count.stream_management_retry_count > 10) {
				fail_and_restart_in_ms(0, &status, output);
			} else {
				hdcp->auth.count.stream_management_retry_count++;
				callback_in_ms(0, output);
				set_state_id(hdcp, output, H2_A9_SEND_STREAM_MANAGEMENT);
			}
			break;
		}
		callback_in_ms(200, output);
		set_state_id(hdcp, output, H2_ENABLE_ENCRYPTION);
		break;
	default:
		status = MOD_HDCP_STATUS_INVALID_STATE;
		fail_and_restart_in_ms(0, &status, output);
		break;
	}

	return status;
}

enum mod_hdcp_status mod_hdcp_hdcp2_dp_transition(struct mod_hdcp *hdcp,
		struct mod_hdcp_event_context *event_ctx,
		struct mod_hdcp_transition_input_hdcp2 *input,
		struct mod_hdcp_output *output)
{
	enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS;
	struct mod_hdcp_connection *conn = &hdcp->connection;
	struct mod_hdcp_link_adjustment *adjust = &hdcp->connection.link.adjust;

	switch (current_state(hdcp)) {
	case D2_A0_DETERMINE_RX_HDCP_CAPABLE:
		if (input->rx_caps_read_dp != PASS ||
				input->hdcp2_capable_check != PASS) {
			adjust->hdcp2.disable = 1;
			callback_in_ms(0, output);
			set_state_id(hdcp, output, HDCP_INITIALIZED);
		} else {
			callback_in_ms(0, output);
			set_state_id(hdcp, output, D2_A1_SEND_AKE_INIT);
		}
		break;
	case D2_A1_SEND_AKE_INIT:
		if (input->create_session != PASS ||
				input->ake_init_prepare != PASS) {
			/* out of sync with psp state */
			adjust->hdcp2.disable = 1;
			fail_and_restart_in_ms(0, &status, output);
			break;
		} else if (input->ake_init_write != PASS) {
			/* possibly display not ready */
			fail_and_restart_in_ms(0, &status, output);
			break;
		}
		callback_in_ms(100, output);
		set_state_id(hdcp, output, D2_A1_VALIDATE_AKE_CERT);
		break;
	case D2_A1_VALIDATE_AKE_CERT:
		if (input->ake_cert_read != PASS ||
				input->ake_cert_validation != PASS) {
			/*
			 * 1A-08: consider invalid ake cert a failure
			 * 1A-09: consider receiver id listed in SRM a failure
			 */
			fail_and_restart_in_ms(0, &status, output);
			break;
		}
		if (conn->is_km_stored &&
				!adjust->hdcp2.force_no_stored_km) {
			callback_in_ms(0, output);
			set_state_id(hdcp, output, D2_A1_SEND_STORED_KM);
		} else {
			callback_in_ms(0, output);
			set_state_id(hdcp, output, D2_A1_SEND_NO_STORED_KM);
		}
		break;
	case D2_A1_SEND_NO_STORED_KM:
		if (input->no_stored_km_write != PASS) {
			fail_and_restart_in_ms(0, &status, output);
			break;
		}
		if (adjust->hdcp2.increase_h_prime_timeout)
			set_watchdog_in_ms(hdcp, 2000, output);
		else
			set_watchdog_in_ms(hdcp, 1000, output);
		set_state_id(hdcp, output, D2_A1_READ_H_PRIME);
		break;
	case D2_A1_READ_H_PRIME:
		if (input->h_prime_available != PASS) {
			if (event_ctx->event ==
					MOD_HDCP_EVENT_WATCHDOG_TIMEOUT)
				/* 1A-10-3: consider h' timeout a failure */
				fail_and_restart_in_ms(1000, &status, output);
			else
				increment_stay_counter(hdcp);
			break;
		} else if (input->h_prime_read != PASS) {
			fail_and_restart_in_ms(0, &status, output);
			break;
		}
		set_watchdog_in_ms(hdcp, 200, output);
		set_state_id(hdcp, output, D2_A1_READ_PAIRING_INFO_AND_VALIDATE_H_PRIME);
		break;
	case D2_A1_READ_PAIRING_INFO_AND_VALIDATE_H_PRIME:
		if (input->pairing_available != PASS) {
			if (event_ctx->event ==
					MOD_HDCP_EVENT_WATCHDOG_TIMEOUT)
				/*
				 * 1A-11: consider pairing info timeout
				 * a failure
				 */
				fail_and_restart_in_ms(0, &status, output);
			else
				increment_stay_counter(hdcp);
			break;
		} else if (input->pairing_info_read != PASS ||
				input->h_prime_validation != PASS) {
			/* 1A-10-1: consider invalid h' a failure */
			fail_and_restart_in_ms(0, &status, output);
			break;
		}
		callback_in_ms(0, output);
		set_state_id(hdcp, output, D2_A2_LOCALITY_CHECK);
		break;
	case D2_A1_SEND_STORED_KM:
		if (input->stored_km_write != PASS) {
			fail_and_restart_in_ms(0, &status, output);
			break;
		}
		set_watchdog_in_ms(hdcp, 200, output);
		set_state_id(hdcp, output, D2_A1_VALIDATE_H_PRIME);
		break;
	case D2_A1_VALIDATE_H_PRIME:
		if (input->h_prime_available != PASS) {
			if (event_ctx->event ==
					MOD_HDCP_EVENT_WATCHDOG_TIMEOUT)
				/* 1A-10-2: consider h' timeout a failure */
				fail_and_restart_in_ms(1000, &status, output);
			else
				increment_stay_counter(hdcp);
			break;
		} else if (input->h_prime_read != PASS) {
			fail_and_restart_in_ms(0, &status, output);
			break;
		} else if (input->h_prime_validation != PASS) {
			/* 1A-10-1: consider invalid h' a failure */
			adjust->hdcp2.force_no_stored_km = 1;
			fail_and_restart_in_ms(0, &status, output);
			break;
		}
		callback_in_ms(0, output);
		set_state_id(hdcp, output, D2_A2_LOCALITY_CHECK);
		break;
	case D2_A2_LOCALITY_CHECK:
		if (hdcp->state.stay_count > 10 ||
				input->lc_init_prepare != PASS ||
				input->lc_init_write != PASS ||
				input->l_prime_read != PASS) {
			/* 1A-12: consider invalid l' a failure */
			fail_and_restart_in_ms(0, &status, output);
			break;
		} else if (input->l_prime_validation != PASS) {
			callback_in_ms(0, output);
			increment_stay_counter(hdcp);
			break;
		}
		callback_in_ms(0, output);
		set_state_id(hdcp, output, D2_A34_EXCHANGE_KS_AND_TEST_FOR_REPEATER);
		break;
	case D2_A34_EXCHANGE_KS_AND_TEST_FOR_REPEATER:
		if (input->eks_prepare != PASS ||
				input->eks_write != PASS) {
			fail_and_restart_in_ms(0, &status, output);
			break;
		}
		if (conn->is_repeater) {
			set_watchdog_in_ms(hdcp, 3000, output);
			set_state_id(hdcp, output, D2_A6_WAIT_FOR_RX_ID_LIST);
		} else {
			callback_in_ms(1, output);
			set_state_id(hdcp, output, D2_SEND_CONTENT_STREAM_TYPE);
		}
		break;
	case D2_SEND_CONTENT_STREAM_TYPE:
		if (input->rxstatus_read != PASS ||
				input->reauth_request_check != PASS ||
				input->link_integrity_check_dp != PASS ||
				input->content_stream_type_write != PASS) {
			fail_and_restart_in_ms(0, &status, output);
			break;
		}
		callback_in_ms(210, output);
		set_state_id(hdcp, output, D2_ENABLE_ENCRYPTION);
		break;
	case D2_ENABLE_ENCRYPTION:
		if (input->rxstatus_read != PASS ||
				input->reauth_request_check != PASS ||
				input->link_integrity_check_dp != PASS) {
			/*
			 * 1A-07: restart hdcp on REAUTH_REQ
			 * 1B-08: restart hdcp on REAUTH_REQ
			 */
			fail_and_restart_in_ms(0, &status, output);
			break;
		} else if (event_ctx->rx_id_list_ready && conn->is_repeater) {
			callback_in_ms(0, output);
			set_state_id(hdcp, output, D2_A78_VERIFY_RX_ID_LIST_AND_SEND_ACK);
			break;
		} else if (input->enable_encryption != PASS ||
				(is_dp_mst_hdcp(hdcp) && input->stream_encryption_dp != PASS)) {
			fail_and_restart_in_ms(0, &status, output);
			break;
		}
		set_state_id(hdcp, output, D2_A5_AUTHENTICATED);
		set_auth_complete(hdcp, output);
		break;
	case D2_A5_AUTHENTICATED:
		if (input->rxstatus_read == FAIL ||
				input->reauth_request_check == FAIL) {
			fail_and_restart_in_ms(100, &status, output);
			break;
		} else if (input->link_integrity_check_dp == FAIL) {
			if (hdcp->connection.hdcp2_retry_count >= 1)
				adjust->hdcp2.force_type = MOD_HDCP_FORCE_TYPE_0;
			fail_and_restart_in_ms(0, &status, output);
			break;
		} else if (event_ctx->rx_id_list_ready && conn->is_repeater) {
			callback_in_ms(0, output);
			set_state_id(hdcp, output, D2_A78_VERIFY_RX_ID_LIST_AND_SEND_ACK);
			break;
		}
		increment_stay_counter(hdcp);
		break;
	case D2_A6_WAIT_FOR_RX_ID_LIST:
		if (input->rxstatus_read != PASS ||
				input->reauth_request_check != PASS ||
				input->link_integrity_check_dp != PASS) {
			fail_and_restart_in_ms(0, &status, output);
			break;
		} else if (!event_ctx->rx_id_list_ready) {
			if (event_ctx->event == MOD_HDCP_EVENT_WATCHDOG_TIMEOUT)
				/* 1B-02: consider rx id list timeout a failure */
				fail_and_restart_in_ms(0, &status, output);
			else
				increment_stay_counter(hdcp);
			break;
		}
		callback_in_ms(0, output);
		set_state_id(hdcp, output, D2_A78_VERIFY_RX_ID_LIST_AND_SEND_ACK);
		break;
	case D2_A78_VERIFY_RX_ID_LIST_AND_SEND_ACK:
		if (input->rxstatus_read != PASS ||
				input->reauth_request_check != PASS ||
				input->link_integrity_check_dp != PASS ||
				input->rx_id_list_read != PASS ||
				input->device_count_check != PASS ||
				input->rx_id_list_validation != PASS ||
				input->repeater_auth_ack_write != PASS) {
			/*
			 * 1B-03: consider invalid v' a failure
			 * 1B-04: consider MAX_DEVS_EXCEEDED a failure
			 * 1B-05: consider MAX_CASCADE_EXCEEDED a failure
			 * 1B-06: consider invalid seq_num_V a failure
			 * 1B-09: consider seq_num_V rollover a failure
			 */
			fail_and_restart_in_ms(0, &status, output);
			break;
		}
		callback_in_ms(0, output);
		set_state_id(hdcp, output, D2_A9_SEND_STREAM_MANAGEMENT);
		break;
	case D2_A9_SEND_STREAM_MANAGEMENT:
		if (input->rxstatus_read != PASS ||
				input->reauth_request_check != PASS ||
				input->link_integrity_check_dp != PASS) {
			fail_and_restart_in_ms(0, &status, output);
			break;
		} else if (event_ctx->rx_id_list_ready) {
			callback_in_ms(0, output);
			set_state_id(hdcp, output, D2_A78_VERIFY_RX_ID_LIST_AND_SEND_ACK);
			break;
		} else if (input->prepare_stream_manage != PASS ||
				input->stream_manage_write != PASS) {
			if (event_ctx->event == MOD_HDCP_EVENT_CALLBACK)
				fail_and_restart_in_ms(0, &status, output);
			else
				increment_stay_counter(hdcp);
			break;
		}
		callback_in_ms(100, output);
		set_state_id(hdcp, output, D2_A9_VALIDATE_STREAM_READY);
		break;
	case D2_A9_VALIDATE_STREAM_READY:
		if (input->rxstatus_read != PASS ||
				input->reauth_request_check != PASS ||
				input->link_integrity_check_dp != PASS) {
			fail_and_restart_in_ms(0, &status, output);
			break;
		} else if (event_ctx->rx_id_list_ready) {
			callback_in_ms(0, output);
			set_state_id(hdcp, output, D2_A78_VERIFY_RX_ID_LIST_AND_SEND_ACK);
			break;
		} else if (input->stream_ready_read != PASS ||
				input->stream_ready_validation != PASS) {
			/*
			 * 1B-10-1: restart content stream management
			 * on invalid M'
			 * 1B-10-2: consider stream ready timeout a failure
			 */
			if (hdcp->auth.count.stream_management_retry_count > 10) {
				fail_and_restart_in_ms(0, &status, output);
			} else if (event_ctx->event == MOD_HDCP_EVENT_CALLBACK) {
				hdcp->auth.count.stream_management_retry_count++;
				callback_in_ms(0, output);
				set_state_id(hdcp, output, D2_A9_SEND_STREAM_MANAGEMENT);
			} else {
				increment_stay_counter(hdcp);
			}
			break;
		}
		callback_in_ms(200, output);
		set_state_id(hdcp, output, D2_ENABLE_ENCRYPTION);
		break;
	default:
		status = MOD_HDCP_STATUS_INVALID_STATE;
		fail_and_restart_in_ms(0, &status, output);
		break;
	}
	return status;
}