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',
43 0x00: '1.4 Bksv - Receiver KSV',
44 0x08: '1.4 Ri\' - Link Verification',
45 0x0a: '1.4 Pj\' - Enhanced Link Verification',
46 0x10: '1.4 Aksv - Transmitter KSV',
47 0x15: '1.4 Ainfo - Transmitter KSV',
48 0x18: '1.4 An - Session random number',
58 0x60: 'Write_Message',
63 class Decoder(srd.Decoder):
67 longname = 'HDCP over HDMI'
68 desc = 'HDCP protocol over HDMI.'
72 tags = ['PC', 'Security/crypto']
74 tuple(('message-0x%02X' % i, 'Message 0x%02X' % i) for i in range(18)) + (
75 ('summary', 'Summary'),
76 ('warnings', 'Warnings'),
79 ('messages', 'Messages', tuple(range(18))),
80 ('summary', 'Summary', (18,)),
81 ('warnings', 'Warnings', (19,)),
91 self.ss = self.es = self.ss_block = self.es_block = 0
97 self.out_ann = self.register(srd.OUTPUT_ANN)
100 self.put(self.ss_block, self.es_block, self.out_ann, data)
102 def decode(self, ss, es, data):
105 # Collect the 'BITS' packet, then return. The next packet is
106 # guaranteed to belong to these bits we just stored.
111 self.ss, self.es = ss, es
114 if self.state == 'IDLE':
115 # Wait for an I2C START condition.
119 elif cmd != 'START REPEAT':
121 self.state = 'GET SLAVE ADDR'
122 elif self.state == 'GET SLAVE ADDR':
123 if cmd == 'ADDRESS READ':
124 self.state = 'BUFFER DATA'
127 elif cmd == 'ADDRESS WRITE':
128 self.state = 'WRITE OFFSET'
131 elif self.state == 'WRITE OFFSET':
132 if cmd == 'DATA WRITE':
133 if databyte in write_items:
134 self.type = write_items[databyte]
135 if databyte in (0x10, 0x15, 0x18, 0x60):
136 self.state = 'BUFFER DATA'
137 # If we are reading, then jump back to IDLE for a start repeat.
138 # If we are writing, then just continue onwards.
139 if self.state == 'BUFFER DATA':
141 elif self.type != '':
143 elif self.state == 'BUFFER DATA':
144 if cmd in ('STOP', 'NACK'):
150 self.putb([18, ['%s' % (self.type)]])
152 if self.type == 'RxStatus':
153 rxstatus = (self.stack.pop() << 8) | self.stack.pop()
154 reauth_req = (rxstatus & 0x800) != 0
155 ready = (rxstatus & 0x400) != 0
156 length = rxstatus & 0x3ff
157 text = '%s, reauth %s, ready %s, length %s' % \
158 (self.type, reauth_req, ready, length)
159 self.putb([18, [text]])
160 elif self.type == '1.4 Bstatus':
161 bstatus = (self.stack.pop() << 8) | self.stack.pop()
162 device_count = bstatus & 0x7f
163 max_devs_exceeded = (bstatus & 0x80) != 0
164 depth = ((bstatus & 0x700) >> 8)
165 max_cascase_exceeded = bstatus & 0x800
166 hdmi_mode = (bstatus & 0x1000) != 0
167 text = '%s, %s devices, depth %s, hdmi mode %s' % \
168 (self.type, device_count, depth, hdmi_mode)
169 self.putb([18, [text]])
170 elif self.type == 'Read_Message':
171 msg = self.stack.pop(0)
172 self.putb([msg, ['%s, %s' % (self.type,
173 msg_ids.get(msg, 'Invalid'))]])
174 elif self.type == 'Write_Message':
175 msg = self.stack.pop(0)
176 self.putb([msg, ['%s, %s' % (self.type,
177 msg_ids.get(msg, 'Invalid'))]])
178 elif self.type == 'HDCP2Version':
179 version = self.stack.pop(0)
181 self.putb([18, ['HDCP2']])
183 self.putb([18, ['NOT HDCP2']])
185 self.putb([18, ['%s' % (self.type)]])
186 elif cmd == 'DATA READ':
187 # Stack up our data bytes.
188 self.stack.append(databyte)
189 elif cmd == 'DATA WRITE':
190 # Stack up our data bytes.
191 self.stack.append(databyte)