Coverage for src / bluetooth_sig / advertising / __init__.py: 100%

14 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-03-18 11:17 +0000

1"""BLE Advertising data parsing and interpretation framework. 

2 

3Two-layer architecture: 

4- AdvertisingPDUParser: Low-level BLE PDU parsing (raw bytes → AD structures) 

5- PayloadInterpreter[T]: Base class for payload interpretation (service data + manufacturer data) 

6- AdvertisingServiceResolver: Map service UUIDs → GATT service classes 

7- SIGCharacteristicInterpreter: Built-in interpreter for SIG characteristic service data 

8- EAD: Encrypted advertising data support (Core Spec 1.23) 

9 

10State Management: 

11 Interpreters do NOT manage state. The caller (connection manager, device tracker) 

12 owns the DeviceAdvertisingState and passes it to interpreters. 

13 Interpreters update state directly and raise exceptions for errors. 

14 

15Error Handling: 

16 Interpreters raise exceptions (EncryptionRequiredError, DecryptionFailedError, etc.) 

17 instead of returning status codes. This is consistent with GATT characteristic parsing. 

18""" 

19 

20from __future__ import annotations 

21 

22from bluetooth_sig.advertising.base import ( 

23 AdvertisingData, 

24 DataSource, 

25 InterpreterInfo, 

26 PayloadInterpreter, 

27) 

28from bluetooth_sig.advertising.ead_decryptor import ( 

29 EADDecryptor, 

30 build_ead_nonce, 

31 decrypt_ead, 

32 decrypt_ead_from_raw, 

33) 

34from bluetooth_sig.advertising.encryption import ( 

35 DictKeyProvider, 

36 EADKeyProvider, 

37 EncryptionKeyProvider, 

38) 

39from bluetooth_sig.advertising.exceptions import ( 

40 AdvertisingError, 

41 AdvertisingParseError, 

42 DecryptionFailedError, 

43 DuplicatePacketError, 

44 EncryptionRequiredError, 

45 ReplayDetectedError, 

46 UnsupportedVersionError, 

47) 

48from bluetooth_sig.advertising.pdu_parser import AdvertisingPDUParser 

49from bluetooth_sig.advertising.registry import ( 

50 PayloadContext, 

51 PayloadInterpreterRegistry, 

52 parse_advertising_payloads, 

53 payload_interpreter_registry, 

54) 

55from bluetooth_sig.advertising.service_data_parser import ServiceDataParser 

56from bluetooth_sig.advertising.service_resolver import ( 

57 AdvertisingServiceResolver, 

58 ResolvedService, 

59) 

60from bluetooth_sig.advertising.sig_characteristic_interpreter import ( 

61 SIGCharacteristicData, 

62 SIGCharacteristicInterpreter, 

63) 

64from bluetooth_sig.advertising.state import ( 

65 DeviceAdvertisingState, 

66 EncryptionState, 

67 PacketState, 

68) 

69from bluetooth_sig.types.address import bytes_to_mac_address, mac_address_to_bytes 

70from bluetooth_sig.types.company import CompanyIdentifier, ManufacturerData 

71 

72__all__ = [ 

73 "AdvertisingData", 

74 "AdvertisingError", 

75 "AdvertisingPDUParser", 

76 "AdvertisingParseError", 

77 "AdvertisingServiceResolver", 

78 "CompanyIdentifier", 

79 "DataSource", 

80 "DecryptionFailedError", 

81 "DeviceAdvertisingState", 

82 "DictKeyProvider", 

83 "DuplicatePacketError", 

84 "EADDecryptor", 

85 "EADKeyProvider", 

86 "EncryptionKeyProvider", 

87 "EncryptionRequiredError", 

88 "EncryptionState", 

89 "InterpreterInfo", 

90 "ManufacturerData", 

91 "PacketState", 

92 "PayloadContext", 

93 "PayloadInterpreter", 

94 "PayloadInterpreterRegistry", 

95 "ReplayDetectedError", 

96 "ResolvedService", 

97 "SIGCharacteristicData", 

98 "SIGCharacteristicInterpreter", 

99 "ServiceDataParser", 

100 "UnsupportedVersionError", 

101 "build_ead_nonce", 

102 "bytes_to_mac_address", 

103 "decrypt_ead", 

104 "decrypt_ead_from_raw", 

105 "mac_address_to_bytes", 

106 "parse_advertising_payloads", 

107 "payload_interpreter_registry", 

108]