MCPcopy Index your code
hub / github.com/secdev/scapy / BTLE

Class BTLE

scapy/layers/bluetooth4LE.py:210–267  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

208##########
209
210class BTLE(Packet):
211 name = "BT4LE"
212 fields_desc = [
213 XLEIntField("access_addr", 0x8E89BED6),
214 X3BytesField("crc", None)
215 ]
216
217 @staticmethod
218 def compute_crc(pdu, init=0x555555):
219 def swapbits(a):
220 v = 0
221 if a & 0x80 != 0:
222 v |= 0x01
223 if a & 0x40 != 0:
224 v |= 0x02
225 if a & 0x20 != 0:
226 v |= 0x04
227 if a & 0x10 != 0:
228 v |= 0x08
229 if a & 0x08 != 0:
230 v |= 0x10
231 if a & 0x04 != 0:
232 v |= 0x20
233 if a & 0x02 != 0:
234 v |= 0x40
235 if a & 0x01 != 0:
236 v |= 0x80
237 return v
238
239 state = swapbits(init & 0xff) + (swapbits((init >> 8) & 0xff) << 8) + (swapbits((init >> 16) & 0xff) << 16) # noqa: E501
240 lfsr_mask = 0x5a6000
241 for i in (orb(x) for x in pdu):
242 for j in range(8):
243 next_bit = (state ^ i) & 1
244 i >>= 1
245 state >>= 1
246 if next_bit:
247 state |= 1 << 23
248 state ^= lfsr_mask
249 return struct.pack("<L", state)[:-1]
250
251 def post_build(self, p, pay):
252 # Switch payload and CRC
253 crc = p[-3:]
254 p = p[:-3] + pay
255 p += crc if self.crc is not None else self.compute_crc(p[4:])
256 return p
257
258 def post_dissect(self, s):
259 self.raw_packet_cache = None # Reset packet to allow post_build
260 return s
261
262 def pre_dissect(self, s):
263 # move crc
264 return s[:4] + s[-3:] + s[4:-3]
265
266 def hashret(self):
267 return struct.pack("!L", self.access_addr)

Callers

nothing calls this directly

Calls 2

XLEIntFieldClass · 0.90
X3BytesFieldClass · 0.90

Tested by

no test coverage detected