I am trying to add a new protocol with scapy, and I am having difficulty creating packages that store other BitEnumField โpacketsโ that are under one byte of length. I was wondering if there is a workaround for the solution (without combining packets into full byte fields). Here is an example:
from scapy.packet import Packet from scapy.fields import * class Status(Packet): name = '4 bit status' fields_desc = [ BitEnumField('a', 0, 1, {0:'Disabled', 1:'Enabled'}), BitEnumField('b', 0, 1, {0:'Disabled', 1:'Active'}), BitEnumField('c', 0, 1, {0:'Disabled', 1:'Active'}), BitEnumField('d', 0, 1, {0:'Disabled', 1:'Active'}), ]
Now I understand why Status().show2()
fails with pkt
only 4 bits long. but this one also dies (I think, because each packet is formed independently):
class TotalStatus(Packet): name = "8 bit status" fields_desc = [ PacketField('axis0', Status(), Status), PacketField('axis1', Status(), Status), ]
TotalStatus().show2()
gives you a long trace that ends with self.post_build()
failed cat pkt
tuple, and the rest of the payload is empty. I.e:. >>> TypeError: can only concatenate tuple (not "str") to tuple
Is there a way to avoid combining bit fields into full bytes?