2 ## This file is part of the libsigrokdecode project.
4 ## Copyright (C) 2018 Dave Craig<dcraig@brightsign.biz>
6 ## This program is free software; you can redistribute it and/or modify
7 ## it under the terms of the GNU General Public License as published by
8 ## the Free Software Foundation; either version 2 of the License, or
9 ## (at your option) any later version.
11 ## This program is distributed in the hope that it will be useful,
12 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ## GNU General Public License for more details.
16 ## You should have received a copy of the GNU General Public License
17 ## along with this program; if not, see <http://www.gnu.org/licenses/>.
20 import sigrokdecode as srd
25 4: 'AKE_No_stored_km',
28 7: 'AKE_Send_H_prime',
29 8: 'AKE_Send_Pairing_Info',
32 10: 'LC_Send_L_prime',
35 12: 'RepeaterAuth_Send_ReceiverID_List',
37 15: 'RepeaterAuth_Send_Ack',
38 16: 'RepeaterAuth_Stream_Manage',
39 17: 'RepeaterAuth_Stream_Ready',
42 class Decoder(srd.Decoder):
46 longname = 'HDCP over HDMI'
47 desc = 'HDCP protocol over HDMI.'
52 tuple(('message-0x%02X' % i, 'Message 0x%02X' % i) for i in range(18)) + (
53 ('summary', 'Summary'),
54 ('warnings', 'Warnings'),
57 ('messages', 'Messages', tuple(range(18))),
58 ('summary', 'Summary', (18,)),
59 ('warnings', 'Warnings', (19,)),
69 self.ss = self.es = self.ss_block = self.es_block = 0
75 self.out_ann = self.register(srd.OUTPUT_ANN)
78 self.put(self.ss_block, self.es_block, self.out_ann, data)
80 def decode(self, ss, es, data):
83 # Collect the 'BITS' packet, then return. The next packet is
84 # guaranteed to belong to these bits we just stored.
89 self.ss, self.es = ss, es
92 if self.state == 'IDLE':
93 # Wait for an I2C START condition.
97 elif cmd != 'START REPEAT':
99 self.state = 'GET SLAVE ADDR'
101 elif self.state == 'GET SLAVE ADDR':
102 if cmd == 'ADDRESS READ':
103 self.state = 'BUFFER DATA'
106 elif cmd == 'ADDRESS WRITE':
107 self.state = 'WRITE OFFSET'
111 elif self.state == 'WRITE OFFSET':
112 if cmd == 'DATA WRITE':
114 self.type = '1.4 Bksv - Receiver KSV'
115 elif databyte == 0x08:
116 self.type = '1.4 Ri\' - Link Verification'
117 elif databyte == 0x0a:
118 self.type = '1.4 Pj\' - Enhanced Link Verification'
119 elif databyte == 0x10:
120 self.type = '1.4 Aksv - Transmitter KSV'
121 self.state = 'BUFFER DATA'
122 elif databyte == 0x15:
123 self.type = '1.4 Ainfo- Transmitter KSV'
124 self.state = 'BUFFER DATA'
125 elif databyte == 0x18:
126 self.type = '1.4 An- Session random number'
127 self.state = 'BUFFER DATA'
128 elif databyte == 0x20:
129 self.type = '1.4 V\'H0'
130 elif databyte == 0x24:
131 self.type = '1.4 V\'H1'
132 elif databyte == 0x28:
133 self.type = '1.4 V\'H2'
134 elif databyte == 0x2c:
135 self.type = '1.4 V\'H3'
136 elif databyte == 0x30:
137 self.type = '1.4 V\'H4'
138 elif databyte == 0x40:
139 self.type = '1.4 Bcaps'
140 elif databyte == 0x41:
141 self.type = '1.4 Bstatus'
142 elif databyte == 0x43:
143 self.type = '1.4 KSV FIFO'
144 elif databyte == 0x50:
145 self.type = 'HDCP2Version'
146 elif databyte == 0x60:
147 self.type = 'Write_Message'
148 self.state = 'BUFFER DATA'
149 elif databyte == 0x70:
150 self.type = 'RxStatus'
151 elif databyte == 0x80:
152 self.type = 'Read_Message'
154 # If we are reading, then jump back to IDLE for a start repeat.
155 # If we are writing, then just continue onwards.
156 if self.state == 'BUFFER DATA':
157 self.state = 'BUFFER DATA'
158 elif self.type != '':
161 elif self.state == 'BUFFER DATA':
162 if (cmd == 'STOP') or (cmd == 'NACK'):
167 if self.type == 'RxStatus':
168 rxstatus = (self.stack.pop() << 8) | self.stack.pop()
169 reauth_req = (rxstatus & 0x800) != 0
170 ready = (rxstatus & 0x400) != 0
171 length = rxstatus & 0x3ff
172 text = '%s, reauth %s, ready %s, length %s' % (self.type, reauth_req, ready, length)
173 self.putb([18, [text]])
174 elif self.type == '1.4 Bstatus':
175 bstatus = (self.stack.pop() << 8) | self.stack.pop()
176 device_count = bstatus & 0x7f
177 max_devs_exceeded = (bstatus & 0x80) != 0
178 depth = ((bstatus & 0x700) >> 8)
179 max_cascase_exceeded = bstatus & 0x800
180 hdmi_mode = (bstatus & 0x1000) != 0
181 text = '%s, %s devices, depth %s, hdmi mode %s' % (self.type, device_count, depth, hdmi_mode)
182 self.putb([18, [text]])
183 elif self.type == 'Read_Message':
184 msg = self.stack.pop(0)
185 self.putb([msg, ['%s, %s' % (self.type, msg_ids.get(msg, 'Invalid'))]])
186 elif self.type == 'Write_Message':
187 msg = self.stack.pop(0)
188 self.putb([msg, ['%s, %s' % (self.type, msg_ids.get(msg, 'Invalid'))]])
189 elif self.type == 'HDCP2Version':
190 version = self.stack.pop(0)
192 self.putb([18, ['HDCP2']])
194 self.putb([18, ['NOT HDCP2']])
196 self.putb([18, ['%s' % (self.type)]])
198 self.putb([18, ['%s' % (self.type)]])
199 elif cmd == 'DATA READ':
200 # Stack up our data bytes.
201 self.stack.append(databyte)
202 elif cmd == 'DATA WRITE':
203 # Stack up our data bytes.
204 self.stack.append(databyte)