bumble 0.0.203__py3-none-any.whl → 0.0.207__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. bumble/_version.py +2 -2
  2. bumble/apps/auracast.py +626 -87
  3. bumble/apps/bench.py +227 -148
  4. bumble/apps/controller_info.py +23 -7
  5. bumble/apps/device_info.py +50 -4
  6. bumble/apps/lea_unicast/app.py +61 -201
  7. bumble/apps/pair.py +13 -8
  8. bumble/apps/show.py +6 -6
  9. bumble/att.py +10 -11
  10. bumble/audio/__init__.py +17 -0
  11. bumble/audio/io.py +553 -0
  12. bumble/controller.py +24 -9
  13. bumble/core.py +4 -1
  14. bumble/device.py +993 -48
  15. bumble/drivers/common.py +2 -0
  16. bumble/drivers/intel.py +593 -24
  17. bumble/gatt.py +67 -12
  18. bumble/gatt_client.py +14 -2
  19. bumble/gatt_server.py +12 -1
  20. bumble/hci.py +854 -33
  21. bumble/host.py +363 -64
  22. bumble/l2cap.py +3 -16
  23. bumble/pairing.py +3 -0
  24. bumble/profiles/aics.py +45 -80
  25. bumble/profiles/ascs.py +6 -18
  26. bumble/profiles/asha.py +5 -5
  27. bumble/profiles/bass.py +9 -21
  28. bumble/profiles/device_information_service.py +4 -1
  29. bumble/profiles/gatt_service.py +166 -0
  30. bumble/profiles/gmap.py +193 -0
  31. bumble/profiles/heart_rate_service.py +5 -6
  32. bumble/profiles/le_audio.py +87 -4
  33. bumble/profiles/pacs.py +48 -16
  34. bumble/profiles/tmap.py +3 -9
  35. bumble/profiles/{vcp.py → vcs.py} +33 -28
  36. bumble/profiles/vocs.py +299 -0
  37. bumble/sdp.py +223 -93
  38. bumble/smp.py +8 -3
  39. bumble/tools/intel_fw_download.py +130 -0
  40. bumble/tools/intel_util.py +154 -0
  41. bumble/transport/usb.py +8 -2
  42. bumble/utils.py +22 -7
  43. bumble/vendor/android/hci.py +29 -4
  44. {bumble-0.0.203.dist-info → bumble-0.0.207.dist-info}/METADATA +12 -10
  45. {bumble-0.0.203.dist-info → bumble-0.0.207.dist-info}/RECORD +49 -43
  46. {bumble-0.0.203.dist-info → bumble-0.0.207.dist-info}/WHEEL +1 -1
  47. {bumble-0.0.203.dist-info → bumble-0.0.207.dist-info}/entry_points.txt +3 -0
  48. bumble/apps/lea_unicast/liblc3.wasm +0 -0
  49. {bumble-0.0.203.dist-info → bumble-0.0.207.dist-info}/LICENSE +0 -0
  50. {bumble-0.0.203.dist-info → bumble-0.0.207.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,299 @@
1
+ # Copyright 2024 Google LLC
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # https://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+
16
+ # -----------------------------------------------------------------------------
17
+ # Imports
18
+ # -----------------------------------------------------------------------------
19
+ import struct
20
+ from dataclasses import dataclass
21
+ from typing import Optional
22
+
23
+ from bumble.device import Connection
24
+ from bumble.att import ATT_Error
25
+ from bumble.gatt import (
26
+ Characteristic,
27
+ DelegatedCharacteristicAdapter,
28
+ TemplateService,
29
+ CharacteristicValue,
30
+ SerializableCharacteristicAdapter,
31
+ UTF8CharacteristicAdapter,
32
+ GATT_VOLUME_OFFSET_CONTROL_SERVICE,
33
+ GATT_VOLUME_OFFSET_STATE_CHARACTERISTIC,
34
+ GATT_AUDIO_LOCATION_CHARACTERISTIC,
35
+ GATT_VOLUME_OFFSET_CONTROL_POINT_CHARACTERISTIC,
36
+ GATT_AUDIO_OUTPUT_DESCRIPTION_CHARACTERISTIC,
37
+ )
38
+ from bumble.gatt_client import ProfileServiceProxy, ServiceProxy
39
+ from bumble.utils import OpenIntEnum
40
+ from bumble.profiles.bap import AudioLocation
41
+
42
+ # -----------------------------------------------------------------------------
43
+ # Constants
44
+ # -----------------------------------------------------------------------------
45
+
46
+ MIN_VOLUME_OFFSET = -255
47
+ MAX_VOLUME_OFFSET = 255
48
+ CHANGE_COUNTER_MAX_VALUE = 0xFF
49
+
50
+
51
+ class SetVolumeOffsetOpCode(OpenIntEnum):
52
+ SET_VOLUME_OFFSET = 0x01
53
+
54
+
55
+ class ErrorCode(OpenIntEnum):
56
+ """
57
+ See Volume Offset Control Service 1.6. Application error codes.
58
+ """
59
+
60
+ INVALID_CHANGE_COUNTER = 0x80
61
+ OPCODE_NOT_SUPPORTED = 0x81
62
+ VALUE_OUT_OF_RANGE = 0x82
63
+
64
+
65
+ # -----------------------------------------------------------------------------
66
+ @dataclass
67
+ class VolumeOffsetState:
68
+ volume_offset: int = 0
69
+ change_counter: int = 0
70
+ attribute_value: Optional[CharacteristicValue] = None
71
+
72
+ def __bytes__(self) -> bytes:
73
+ return struct.pack('<hB', self.volume_offset, self.change_counter)
74
+
75
+ @classmethod
76
+ def from_bytes(cls, data: bytes):
77
+ volume_offset, change_counter = struct.unpack('<hB', data)
78
+ return cls(volume_offset, change_counter)
79
+
80
+ def increment_change_counter(self) -> None:
81
+ self.change_counter = (self.change_counter + 1) % (CHANGE_COUNTER_MAX_VALUE + 1)
82
+
83
+ async def notify_subscribers_via_connection(self, connection: Connection) -> None:
84
+ assert self.attribute_value is not None
85
+ await connection.device.notify_subscribers(attribute=self.attribute_value)
86
+
87
+ def on_read(self, _connection: Optional[Connection]) -> bytes:
88
+ return bytes(self)
89
+
90
+
91
+ @dataclass
92
+ class VocsAudioLocation:
93
+ audio_location: AudioLocation = AudioLocation.NOT_ALLOWED
94
+ attribute_value: Optional[CharacteristicValue] = None
95
+
96
+ def __bytes__(self) -> bytes:
97
+ return struct.pack('<I', self.audio_location)
98
+
99
+ @classmethod
100
+ def from_bytes(cls, data: bytes):
101
+ audio_location = AudioLocation(struct.unpack('<I', data)[0])
102
+ return cls(audio_location)
103
+
104
+ def on_read(self, _connection: Optional[Connection]) -> bytes:
105
+ return bytes(self)
106
+
107
+ async def on_write(self, connection: Optional[Connection], value: bytes) -> None:
108
+ assert connection
109
+ assert self.attribute_value
110
+
111
+ self.audio_location = AudioLocation(int.from_bytes(value, 'little'))
112
+ await connection.device.notify_subscribers(attribute=self.attribute_value)
113
+
114
+
115
+ @dataclass
116
+ class VolumeOffsetControlPoint:
117
+ volume_offset_state: VolumeOffsetState
118
+
119
+ async def on_write(self, connection: Optional[Connection], value: bytes) -> None:
120
+ assert connection
121
+
122
+ opcode = value[0]
123
+ if opcode != SetVolumeOffsetOpCode.SET_VOLUME_OFFSET:
124
+ raise ATT_Error(ErrorCode.OPCODE_NOT_SUPPORTED)
125
+
126
+ change_counter, volume_offset = struct.unpack('<Bh', value[1:])
127
+ await self._set_volume_offset(connection, change_counter, volume_offset)
128
+
129
+ async def _set_volume_offset(
130
+ self,
131
+ connection: Connection,
132
+ change_counter_operand: int,
133
+ volume_offset_operand: int,
134
+ ) -> None:
135
+ change_counter = self.volume_offset_state.change_counter
136
+
137
+ if change_counter != change_counter_operand:
138
+ raise ATT_Error(ErrorCode.INVALID_CHANGE_COUNTER)
139
+
140
+ if not MIN_VOLUME_OFFSET <= volume_offset_operand <= MAX_VOLUME_OFFSET:
141
+ raise ATT_Error(ErrorCode.VALUE_OUT_OF_RANGE)
142
+
143
+ self.volume_offset_state.volume_offset = volume_offset_operand
144
+ self.volume_offset_state.increment_change_counter()
145
+ await self.volume_offset_state.notify_subscribers_via_connection(connection)
146
+
147
+
148
+ @dataclass
149
+ class AudioOutputDescription:
150
+ audio_output_description: str = ''
151
+ attribute_value: Optional[CharacteristicValue] = None
152
+
153
+ @classmethod
154
+ def from_bytes(cls, data: bytes):
155
+ return cls(audio_output_description=data.decode('utf-8'))
156
+
157
+ def __bytes__(self) -> bytes:
158
+ return self.audio_output_description.encode('utf-8')
159
+
160
+ def on_read(self, _connection: Optional[Connection]) -> bytes:
161
+ return bytes(self)
162
+
163
+ async def on_write(self, connection: Optional[Connection], value: bytes) -> None:
164
+ assert connection
165
+ assert self.attribute_value
166
+
167
+ self.audio_output_description = value.decode('utf-8')
168
+ await connection.device.notify_subscribers(attribute=self.attribute_value)
169
+
170
+
171
+ # -----------------------------------------------------------------------------
172
+ class VolumeOffsetControlService(TemplateService):
173
+ UUID = GATT_VOLUME_OFFSET_CONTROL_SERVICE
174
+
175
+ def __init__(
176
+ self,
177
+ volume_offset_state: Optional[VolumeOffsetState] = None,
178
+ audio_location: Optional[VocsAudioLocation] = None,
179
+ audio_output_description: Optional[AudioOutputDescription] = None,
180
+ ) -> None:
181
+
182
+ self.volume_offset_state = (
183
+ VolumeOffsetState() if volume_offset_state is None else volume_offset_state
184
+ )
185
+
186
+ self.audio_location = (
187
+ VocsAudioLocation() if audio_location is None else audio_location
188
+ )
189
+
190
+ self.audio_output_description = (
191
+ AudioOutputDescription()
192
+ if audio_output_description is None
193
+ else audio_output_description
194
+ )
195
+
196
+ self.volume_offset_control_point: VolumeOffsetControlPoint = (
197
+ VolumeOffsetControlPoint(self.volume_offset_state)
198
+ )
199
+
200
+ self.volume_offset_state_characteristic = Characteristic(
201
+ uuid=GATT_VOLUME_OFFSET_STATE_CHARACTERISTIC,
202
+ properties=(
203
+ Characteristic.Properties.READ | Characteristic.Properties.NOTIFY
204
+ ),
205
+ permissions=Characteristic.Permissions.READ_REQUIRES_ENCRYPTION,
206
+ value=CharacteristicValue(read=self.volume_offset_state.on_read),
207
+ )
208
+
209
+ self.audio_location_characteristic = Characteristic(
210
+ uuid=GATT_AUDIO_LOCATION_CHARACTERISTIC,
211
+ properties=(
212
+ Characteristic.Properties.READ
213
+ | Characteristic.Properties.NOTIFY
214
+ | Characteristic.Properties.WRITE_WITHOUT_RESPONSE
215
+ ),
216
+ permissions=(
217
+ Characteristic.Permissions.READ_REQUIRES_ENCRYPTION
218
+ | Characteristic.Permissions.WRITE_REQUIRES_ENCRYPTION
219
+ ),
220
+ value=CharacteristicValue(
221
+ read=self.audio_location.on_read,
222
+ write=self.audio_location.on_write,
223
+ ),
224
+ )
225
+ self.audio_location.attribute_value = self.audio_location_characteristic.value
226
+
227
+ self.volume_offset_control_point_characteristic = Characteristic(
228
+ uuid=GATT_VOLUME_OFFSET_CONTROL_POINT_CHARACTERISTIC,
229
+ properties=Characteristic.Properties.WRITE,
230
+ permissions=Characteristic.Permissions.WRITE_REQUIRES_ENCRYPTION,
231
+ value=CharacteristicValue(write=self.volume_offset_control_point.on_write),
232
+ )
233
+
234
+ self.audio_output_description_characteristic = Characteristic(
235
+ uuid=GATT_AUDIO_OUTPUT_DESCRIPTION_CHARACTERISTIC,
236
+ properties=(
237
+ Characteristic.Properties.READ
238
+ | Characteristic.Properties.NOTIFY
239
+ | Characteristic.Properties.WRITE_WITHOUT_RESPONSE
240
+ ),
241
+ permissions=(
242
+ Characteristic.Permissions.READ_REQUIRES_ENCRYPTION
243
+ | Characteristic.Permissions.WRITE_REQUIRES_ENCRYPTION
244
+ ),
245
+ value=CharacteristicValue(
246
+ read=self.audio_output_description.on_read,
247
+ write=self.audio_output_description.on_write,
248
+ ),
249
+ )
250
+ self.audio_output_description.attribute_value = (
251
+ self.audio_output_description_characteristic.value
252
+ )
253
+
254
+ super().__init__(
255
+ characteristics=[
256
+ self.volume_offset_state_characteristic, # type: ignore
257
+ self.audio_location_characteristic, # type: ignore
258
+ self.volume_offset_control_point_characteristic, # type: ignore
259
+ self.audio_output_description_characteristic, # type: ignore
260
+ ],
261
+ primary=False,
262
+ )
263
+
264
+
265
+ # -----------------------------------------------------------------------------
266
+ # Client
267
+ # -----------------------------------------------------------------------------
268
+ class VolumeOffsetControlServiceProxy(ProfileServiceProxy):
269
+ SERVICE_CLASS = VolumeOffsetControlService
270
+
271
+ def __init__(self, service_proxy: ServiceProxy) -> None:
272
+ self.service_proxy = service_proxy
273
+
274
+ self.volume_offset_state = SerializableCharacteristicAdapter(
275
+ service_proxy.get_required_characteristic_by_uuid(
276
+ GATT_VOLUME_OFFSET_STATE_CHARACTERISTIC
277
+ ),
278
+ VolumeOffsetState,
279
+ )
280
+
281
+ self.audio_location = DelegatedCharacteristicAdapter(
282
+ service_proxy.get_required_characteristic_by_uuid(
283
+ GATT_AUDIO_LOCATION_CHARACTERISTIC
284
+ ),
285
+ encode=lambda value: bytes([int(value)]),
286
+ decode=lambda data: AudioLocation(data[0]),
287
+ )
288
+
289
+ self.volume_offset_control_point = (
290
+ service_proxy.get_required_characteristic_by_uuid(
291
+ GATT_VOLUME_OFFSET_CONTROL_POINT_CHARACTERISTIC
292
+ )
293
+ )
294
+
295
+ self.audio_output_description = UTF8CharacteristicAdapter(
296
+ service_proxy.get_required_characteristic_by_uuid(
297
+ GATT_AUDIO_OUTPUT_DESCRIPTION_CHARACTERISTIC
298
+ )
299
+ )