# Buggy code
def m2i(self, pkt, m):
    """
    Try to parse one of the TLS subprotocols (ccs, alert, handshake or
    application_data). This is used inside a loop managed by .getfield().
    """
    cls = Raw
    if pkt.type == 22:
        if len(m) >= 1:
            msgtype = orb(m[0])
            if (pkt.tls_session.advertised_tls_version == 0x0304) or (
                pkt.tls_session.tls_version and pkt.tls_session.tls_version == 0x0304
            ):
                cls = _tls13_handshake_cls.get(msgtype, Raw)
            else:
                cls = _tls_handshake_cls.get(msgtype, Raw)

    elif pkt.type == 20:
        cls = TLSChangeCipherSpec
    elif pkt.type == 21:
        cls = TLSAlert
    elif pkt.type == 23:
        cls = TLSApplicationData

    if cls is Raw:
        return Raw(m)
    else:
        try:
            return cls(m, tls_session=pkt.tls_session)
        except Exception:
            if conf.debug_dissector:
                raise
            return Raw(m)


# Traceback (TypeError)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-5-4c9f13dcdcd8> in <module>
----> 1 r2 = TLS(pcap[1].load, tls_session=r1.tls_session.mirror())

~/scapy_venv/lib/python3.7/site-packages/scapy/base_classes.py in __call__(cls, *args, **kargs)
264                 cls = config.conf.raw_layer
265         i = cls.__new__(cls, cls.__name__, cls.__bases__, cls.__dict__)
--> 266         i.__init__(*args, **kargs)
267         return i
268

~/scapy_venv/lib/python3.7/site-packages/scapy/layers/tls/record.py in __init__(self, *args, **kargs)
302     def __init__(self, *args, **kargs):
303         self.deciphered_len = kargs.get("deciphered_len", None)
--> 304         super(TLS, self).__init__(*args, **kargs)
305
306     @classmethod

~/scapy_venv/lib/python3.7/site-packages/scapy/layers/tls/session.py in __init__(self, _pkt, post_transform, _internal, _underlayer, tls_session, **fields)
902         Packet.__init__(self, _pkt=_pkt, post_transform=post_transform,
903                         _internal=_internal, _underlayer=_underlayer,
--> 904                         **fields)
905
906     def __getattr__(self, attr):

~/scapy_venv/lib/python3.7/site-packages/scapy/packet.py in __init__(self, _pkt, post_transform, _internal, _underlayer, **fields)
156         self.sniffed_on = None
157         if _pkt:
--> 158             self.dissect(_pkt)
159             if not _internal:
160                 self.dissection_done(self)

~/scapy_venv/lib/python3.7/site-packages/scapy/packet.py in dissect(self, s)
873         s = self.pre_dissect(s)
874
--> 875         s = self.do_dissect(s)
876
877         s = self.post_dissect(s)

~/scapy_venv/lib/python3.7/site-packages/scapy/packet.py in do_dissect(self, s)
837             if not s:
838                 break
--> 839             s, fval = f.getfield(self, s)
840             # We need to track fields with mutable values to discard
841             # .raw_packet_cache when needed.

~/scapy_venv/lib/python3.7/site-packages/scapy/layers/tls/record.py in getfield(self, pkt, s)
166                 if isinstance(p, _GenericTLSSessionInheritance):
167                     if not p.tls_session.frozen:
--> 168                         p.post_dissection_tls_session_update(raw_msg)
169
170                 lst.append(p)

~/scapy_venv/lib/python3.7/site-packages/scapy/layers/tls/session.py in post_dissection_tls_session_update(self, msg_str)
924
925     def post_dissection_tls_session_update(self, msg_str):
--> 926         self.tls_session_update(msg_str)
927
928     def copy(self):

~/scapy_venv/lib/python3.7/site-packages/scapy/layers/tls/handshake.py in tls_session_update(self, msg_str)
648             s.prcs = readConnState(ciphersuite=cs_cls,
649                                    connection_end=connection_end,
--> 650                                    tls_version=s.tls_version)
651             if not s.middlebox_compatibility:
652                 s.triggered_prcs_commit = True

~/scapy_venv/lib/python3.7/site-packages/scapy/layers/tls/session.py in __init__(self, **kargs)
279 class readConnState(connState):
280     def __init__(self, **kargs):
--> 281         connState.__init__(self, read_or_write="read", **kargs)
282
283

~/scapy_venv/lib/python3.7/site-packages/scapy/layers/tls/session.py in __init__(self, connection_end, read_or_write, seq_num, compression_alg, ciphersuite, tls_version)
89             from scapy.layers.tls.crypto.suites import TLS_NULL_WITH_NULL_NULL
90             ciphersuite = TLS_NULL_WITH_NULL_NULL
---> 91         self.ciphersuite = ciphersuite(tls_version=tls_version)
92
93         if not self.ciphersuite.usable:

~/scapy_venv/lib/python3.7/site-packages/scapy/layers/tls/crypto/suites.py in __init__(self, tls_version)
140         """
141         super(_GenericCipherSuite, self).__init__()
--> 142         if tls_version <= 0x301:
143             self.key_block_len = self._key_block_len_v1_0
144

TypeError: '<=' not supported between instances of 'NoneType' and 'int'

# Fixed code
def m2i(self, pkt, m):
    """
    Try to parse one of the TLS subprotocols (ccs, alert, handshake or
    application_data). This is used inside a loop managed by .getfield().
    """
    cls = Raw
    if pkt.type == 22:
        if len(m) >= 1:
            msgtype = orb(m[0])
            # If a version was agreed on by both client and server,
            # we use it (tls_session.tls_version)
            # Otherwise, if the client advertised for TLS 1.3, we try to
            # dissect the following packets (most likely, server hello)
            # using TLS 1.3. The serverhello is able to fallback on
            # TLS 1.2 if necessary. In any case, this will set the agreed
            # version so that all future packets are correct.
            if (
                pkt.tls_session.advertised_tls_version == 0x0304
                and pkt.tls_session.tls_version is None
            ) or pkt.tls_session.tls_version == 0x0304:
                cls = _tls13_handshake_cls.get(msgtype, Raw)
            else:
                cls = _tls_handshake_cls.get(msgtype, Raw)

    elif pkt.type == 20:
        cls = TLSChangeCipherSpec
    elif pkt.type == 21:
        cls = TLSAlert
    elif pkt.type == 23:
        cls = TLSApplicationData

    if cls is Raw:
        return Raw(m)
    else:
        try:
            return cls(m, tls_session=pkt.tls_session)
        except Exception:
            if conf.debug_dissector:
                raise
            return Raw(m)