]> sigrok.org Git - libsigrokdecode.git/blobdiff - decoders/hdcp/pd.py
All PDs: Consistently use singular/plural for annotation classes/rows.
[libsigrokdecode.git] / decoders / hdcp / pd.py
index 861cd5c7f7b2a89236562608664795ab11c4f210..157b23a3dba44d9a52d3befd75639f2b9ab2a37e 100644 (file)
@@ -1,7 +1,7 @@
 ##
 ## This file is part of the libsigrokdecode project.
 ##
-## Copyright (C) 2018 Dave Craig<dcraig@brightsign.biz>
+## Copyright (C) 2018 Dave Craig <dcraig@brightsign.biz>
 ##
 ## This program is free software; you can redistribute it and/or modify
 ## it under the terms of the GNU General Public License as published by
@@ -39,6 +39,27 @@ msg_ids = {
     17: 'RepeaterAuth_Stream_Ready',
 }
 
+write_items = {
+    0x00: '1.4 Bksv - Receiver KSV',
+    0x08: '1.4 Ri\' - Link Verification',
+    0x0a: '1.4 Pj\' - Enhanced Link Verification',
+    0x10: '1.4 Aksv - Transmitter KSV',
+    0x15: '1.4 Ainfo - Transmitter KSV',
+    0x18: '1.4 An - Session random number',
+    0x20: '1.4 V\'H0',
+    0x24: '1.4 V\'H1',
+    0x28: '1.4 V\'H2',
+    0x2c: '1.4 V\'H3',
+    0x30: '1.4 V\'H4',
+    0x40: '1.4 Bcaps',
+    0x41: '1.4 Bstatus',
+    0x43: '1.4 KSV FIFO',
+    0x50: 'HDCP2Version',
+    0x60: 'Write_Message',
+    0x70: 'RxStatus',
+    0x80: 'Read_Message',
+}
+
 class Decoder(srd.Decoder):
     api_version = 3
     id = 'hdcp'
@@ -48,14 +69,15 @@ class Decoder(srd.Decoder):
     license = 'gplv2+'
     inputs = ['i2c']
     outputs = ['hdcp']
+    tags = ['PC', 'Security/crypto']
     annotations = \
         tuple(('message-0x%02X' % i, 'Message 0x%02X' % i) for i in range(18)) + (
         ('summary', 'Summary'),
-        ('warnings', 'Warnings'),
+        ('warning', 'Warning'),
     )
     annotation_rows = (
         ('messages', 'Messages', tuple(range(18))),
-        ('summary', 'Summary', (18,)),
+        ('summaries', 'Summaries', (18,)),
         ('warnings', 'Warnings', (19,)),
     )
 
@@ -97,7 +119,6 @@ class Decoder(srd.Decoder):
             elif cmd != 'START REPEAT':
                 return
             self.state = 'GET SLAVE ADDR'
-
         elif self.state == 'GET SLAVE ADDR':
             if cmd == 'ADDRESS READ':
                 self.state = 'BUFFER DATA'
@@ -107,95 +128,61 @@ class Decoder(srd.Decoder):
                 self.state = 'WRITE OFFSET'
                 if databyte != 0x3a:
                     self.state = 'IDLE'
-
         elif self.state == 'WRITE OFFSET':
             if cmd == 'DATA WRITE':
-                if databyte == 0x00:
-                    self.type = '1.4 Bksv - Receiver KSV'
-                elif databyte == 0x08:
-                    self.type = '1.4 Ri\' - Link Verification'
-                elif databyte == 0x0a:
-                    self.type = '1.4 Pj\' - Enhanced Link Verification'
-                elif databyte == 0x10:
-                    self.type = '1.4 Aksv - Transmitter KSV'
-                    self.state = 'BUFFER DATA'
-                elif databyte == 0x15:
-                    self.type = '1.4 Ainfo- Transmitter KSV'
+                if databyte in write_items:
+                    self.type = write_items[databyte]
+                if databyte in (0x10, 0x15, 0x18, 0x60):
                     self.state = 'BUFFER DATA'
-                elif databyte == 0x18:
-                    self.type = '1.4 An- Session random number'
-                    self.state = 'BUFFER DATA'
-                elif databyte == 0x20:
-                    self.type = '1.4 V\'H0'
-                elif databyte == 0x24:
-                    self.type = '1.4 V\'H1'
-                elif databyte == 0x28:
-                    self.type = '1.4 V\'H2'
-                elif databyte == 0x2c:
-                    self.type = '1.4 V\'H3'
-                elif databyte == 0x30:
-                    self.type = '1.4 V\'H4'
-                elif databyte == 0x40:
-                    self.type = '1.4 Bcaps'
-                elif databyte == 0x41:
-                    self.type = '1.4 Bstatus'
-                elif databyte == 0x43:
-                    self.type = '1.4 KSV FIFO'
-                elif databyte == 0x50:
-                    self.type = 'HDCP2Version'
-                elif databyte == 0x60:
-                    self.type = 'Write_Message'
-                    self.state = 'BUFFER DATA'
-                elif databyte == 0x70:
-                    self.type = 'RxStatus'
-                elif databyte == 0x80:
-                    self.type = 'Read_Message'
-
                 # If we are reading, then jump back to IDLE for a start repeat.
                 # If we are writing, then just continue onwards.
                 if self.state == 'BUFFER DATA':
-                    self.state = 'BUFFER DATA'
+                    pass
                 elif self.type != '':
                     self.state = 'IDLE'
-
         elif self.state == 'BUFFER DATA':
-            if (cmd == 'STOP') or (cmd == 'NACK'):
+            if cmd in ('STOP', 'NACK'):
                 self.es_block = es
                 self.state = 'IDLE'
-                if self.type != '':
-                    if self.stack:
-                        if self.type == 'RxStatus':
-                            rxstatus = (self.stack.pop() << 8) | self.stack.pop()
-                            reauth_req = (rxstatus & 0x800) != 0
-                            ready = (rxstatus & 0x400) != 0
-                            length = rxstatus & 0x3ff
-                            text = '%s, reauth %s, ready %s, length %s' % (self.type, reauth_req, ready, length)
-                            self.putb([18, [text]])
-                        elif self.type == '1.4 Bstatus':
-                            bstatus = (self.stack.pop() << 8) | self.stack.pop()
-                            device_count = bstatus & 0x7f
-                            max_devs_exceeded = (bstatus & 0x80) != 0
-                            depth = ((bstatus & 0x700) >> 8)
-                            max_cascase_exceeded = bstatus & 0x800
-                            hdmi_mode = (bstatus & 0x1000) != 0
-                            text = '%s, %s devices, depth %s, hdmi mode %s' % (self.type, device_count, depth, hdmi_mode)
-                            self.putb([18, [text]])
-                        elif self.type == 'Read_Message':
-                            msg = self.stack.pop(0)
-                            self.putb([msg, ['%s, %s' % (self.type, msg_ids.get(msg, 'Invalid'))]])
-                        elif self.type == 'Write_Message':
-                            msg = self.stack.pop(0)
-                            self.putb([msg, ['%s, %s' % (self.type, msg_ids.get(msg, 'Invalid'))]])
-                        elif self.type == 'HDCP2Version':
-                            version = self.stack.pop(0)
-                            if (version & 0x4):
-                                self.putb([18, ['HDCP2']])
-                            else:
-                                self.putb([18, ['NOT HDCP2']])
-                        else:
-                            self.putb([18, ['%s' % (self.type)]])
+                if self.type == '':
+                    return
+                if not self.stack:
+                    self.putb([18, ['%s' % (self.type)]])
+                    return
+                if self.type == 'RxStatus':
+                    rxstatus = (self.stack.pop() << 8) | self.stack.pop()
+                    reauth_req = (rxstatus & 0x800) != 0
+                    ready = (rxstatus & 0x400) != 0
+                    length = rxstatus & 0x3ff
+                    text = '%s, reauth %s, ready %s, length %s' % \
+                        (self.type, reauth_req, ready, length)
+                    self.putb([18, [text]])
+                elif self.type == '1.4 Bstatus':
+                    bstatus = (self.stack.pop() << 8) | self.stack.pop()
+                    device_count = bstatus & 0x7f
+                    max_devs_exceeded = (bstatus & 0x80) != 0
+                    depth = ((bstatus & 0x700) >> 8)
+                    max_cascase_exceeded = bstatus & 0x800
+                    hdmi_mode = (bstatus & 0x1000) != 0
+                    text = '%s, %s devices, depth %s, hdmi mode %s' % \
+                        (self.type, device_count, depth, hdmi_mode)
+                    self.putb([18, [text]])
+                elif self.type == 'Read_Message':
+                    msg = self.stack.pop(0)
+                    self.putb([msg, ['%s, %s' % (self.type,
+                        msg_ids.get(msg, 'Invalid'))]])
+                elif self.type == 'Write_Message':
+                    msg = self.stack.pop(0)
+                    self.putb([msg, ['%s, %s' % (self.type,
+                        msg_ids.get(msg, 'Invalid'))]])
+                elif self.type == 'HDCP2Version':
+                    version = self.stack.pop(0)
+                    if (version & 0x4):
+                        self.putb([18, ['HDCP2']])
                     else:
-                        self.putb([18, ['%s' % (self.type)]])
+                        self.putb([18, ['NOT HDCP2']])
+                else:
+                    self.putb([18, ['%s' % (self.type)]])
             elif cmd == 'DATA READ':
                 # Stack up our data bytes.
                 self.stack.append(databyte)