bscontroller 0.1.0__tar.gz

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 (179) hide show
  1. bscontroller-0.1.0/LICENSE +221 -0
  2. bscontroller-0.1.0/MANIFEST.in +5 -0
  3. bscontroller-0.1.0/NOTICE +14 -0
  4. bscontroller-0.1.0/PKG-INFO +260 -0
  5. bscontroller-0.1.0/README.md +240 -0
  6. bscontroller-0.1.0/README.zh-CN.md +240 -0
  7. bscontroller-0.1.0/docs/images/radio_controller_arch.svg +116 -0
  8. bscontroller-0.1.0/docs/images/radio_controller_internal_arch.svg +315 -0
  9. bscontroller-0.1.0/examples/README.md +7 -0
  10. bscontroller-0.1.0/examples/README.zh-CN.md +7 -0
  11. bscontroller-0.1.0/examples/advertise_scan.py +204 -0
  12. bscontroller-0.1.0/pyproject.toml +45 -0
  13. bscontroller-0.1.0/setup.cfg +4 -0
  14. bscontroller-0.1.0/src/bscontroller/__init__.py +57 -0
  15. bscontroller-0.1.0/src/bscontroller/__main__.py +6 -0
  16. bscontroller-0.1.0/src/bscontroller/address.py +204 -0
  17. bscontroller-0.1.0/src/bscontroller/capabilities.py +16 -0
  18. bscontroller-0.1.0/src/bscontroller/cli.py +123 -0
  19. bscontroller-0.1.0/src/bscontroller/colors.py +82 -0
  20. bscontroller-0.1.0/src/bscontroller/config.py +180 -0
  21. bscontroller-0.1.0/src/bscontroller/crypto/__init__.py +23 -0
  22. bscontroller-0.1.0/src/bscontroller/errors.py +131 -0
  23. bscontroller-0.1.0/src/bscontroller/hci/__init__.py +9 -0
  24. bscontroller-0.1.0/src/bscontroller/hci/advertising.py +703 -0
  25. bscontroller-0.1.0/src/bscontroller/hci/backend.py +153 -0
  26. bscontroller-0.1.0/src/bscontroller/hci/capabilities.py +12 -0
  27. bscontroller-0.1.0/src/bscontroller/hci/connection.py +516 -0
  28. bscontroller-0.1.0/src/bscontroller/hci/context.py +76 -0
  29. bscontroller-0.1.0/src/bscontroller/hci/controller.py +385 -0
  30. bscontroller-0.1.0/src/bscontroller/hci/events.py +559 -0
  31. bscontroller-0.1.0/src/bscontroller/hci/le.py +108 -0
  32. bscontroller-0.1.0/src/bscontroller/hci/packets.py +5838 -0
  33. bscontroller-0.1.0/src/bscontroller/hci/privacy.py +130 -0
  34. bscontroller-0.1.0/src/bscontroller/hci/records.py +216 -0
  35. bscontroller-0.1.0/src/bscontroller/hci/scanning.py +427 -0
  36. bscontroller-0.1.0/src/bscontroller/hci/snoop.py +60 -0
  37. bscontroller-0.1.0/src/bscontroller/hci/transport.py +153 -0
  38. bscontroller-0.1.0/src/bscontroller/linklayer/__init__.py +6 -0
  39. bscontroller-0.1.0/src/bscontroller/linklayer/advertising.py +486 -0
  40. bscontroller-0.1.0/src/bscontroller/linklayer/api.py +243 -0
  41. bscontroller-0.1.0/src/bscontroller/linklayer/bitstream.py +63 -0
  42. bscontroller-0.1.0/src/bscontroller/linklayer/channel_selection.py +52 -0
  43. bscontroller-0.1.0/src/bscontroller/linklayer/connection.py +289 -0
  44. bscontroller-0.1.0/src/bscontroller/linklayer/connection_event.py +452 -0
  45. bscontroller-0.1.0/src/bscontroller/linklayer/connection_parameters.py +441 -0
  46. bscontroller-0.1.0/src/bscontroller/linklayer/control.py +656 -0
  47. bscontroller-0.1.0/src/bscontroller/linklayer/data_length.py +308 -0
  48. bscontroller-0.1.0/src/bscontroller/linklayer/data_path.py +150 -0
  49. bscontroller-0.1.0/src/bscontroller/linklayer/decision.py +174 -0
  50. bscontroller-0.1.0/src/bscontroller/linklayer/discovery.py +262 -0
  51. bscontroller-0.1.0/src/bscontroller/linklayer/encryption.py +444 -0
  52. bscontroller-0.1.0/src/bscontroller/linklayer/extended.py +842 -0
  53. bscontroller-0.1.0/src/bscontroller/linklayer/features.py +174 -0
  54. bscontroller-0.1.0/src/bscontroller/linklayer/filtering.py +120 -0
  55. bscontroller-0.1.0/src/bscontroller/linklayer/instant.py +24 -0
  56. bscontroller-0.1.0/src/bscontroller/linklayer/link.py +225 -0
  57. bscontroller-0.1.0/src/bscontroller/linklayer/listener.py +124 -0
  58. bscontroller-0.1.0/src/bscontroller/linklayer/llcp.py +473 -0
  59. bscontroller-0.1.0/src/bscontroller/linklayer/notifications.py +239 -0
  60. bscontroller-0.1.0/src/bscontroller/linklayer/parameters.py +126 -0
  61. bscontroller-0.1.0/src/bscontroller/linklayer/pdu.py +437 -0
  62. bscontroller-0.1.0/src/bscontroller/linklayer/periodic.py +121 -0
  63. bscontroller-0.1.0/src/bscontroller/linklayer/phy.py +234 -0
  64. bscontroller-0.1.0/src/bscontroller/linklayer/primary.py +475 -0
  65. bscontroller-0.1.0/src/bscontroller/linklayer/privacy.py +314 -0
  66. bscontroller-0.1.0/src/bscontroller/linklayer/procedure.py +77 -0
  67. bscontroller-0.1.0/src/bscontroller/linklayer/resource.py +102 -0
  68. bscontroller-0.1.0/src/bscontroller/linklayer/results.py +65 -0
  69. bscontroller-0.1.0/src/bscontroller/linklayer/roles.py +637 -0
  70. bscontroller-0.1.0/src/bscontroller/linklayer/scheduler.py +75 -0
  71. bscontroller-0.1.0/src/bscontroller/linklayer/service.py +824 -0
  72. bscontroller-0.1.0/src/bscontroller/linklayer/state.py +39 -0
  73. bscontroller-0.1.0/src/bscontroller/linklayer/timing.py +48 -0
  74. bscontroller-0.1.0/src/bscontroller/py.typed +0 -0
  75. bscontroller-0.1.0/src/bscontroller/radio/__init__.py +8 -0
  76. bscontroller-0.1.0/src/bscontroller/radio/babblesim.py +691 -0
  77. bscontroller-0.1.0/src/bscontroller/radio/base.py +168 -0
  78. bscontroller-0.1.0/src/bscontroller/radio/packet.py +41 -0
  79. bscontroller-0.1.0/src/bscontroller/runtime/__init__.py +8 -0
  80. bscontroller-0.1.0/src/bscontroller/runtime/event_loop.py +203 -0
  81. bscontroller-0.1.0/src/bscontroller/runtime/phy.py +94 -0
  82. bscontroller-0.1.0/src/bscontroller/runtime/session.py +99 -0
  83. bscontroller-0.1.0/src/bscontroller/runtime/worker.py +249 -0
  84. bscontroller-0.1.0/src/bscontroller/serialization.py +134 -0
  85. bscontroller-0.1.0/src/bscontroller.egg-info/PKG-INFO +260 -0
  86. bscontroller-0.1.0/src/bscontroller.egg-info/SOURCES.txt +177 -0
  87. bscontroller-0.1.0/src/bscontroller.egg-info/dependency_links.txt +1 -0
  88. bscontroller-0.1.0/src/bscontroller.egg-info/entry_points.txt +2 -0
  89. bscontroller-0.1.0/src/bscontroller.egg-info/requires.txt +8 -0
  90. bscontroller-0.1.0/src/bscontroller.egg-info/top_level.txt +1 -0
  91. bscontroller-0.1.0/tests/README.md +51 -0
  92. bscontroller-0.1.0/tests/README.zh-CN.md +51 -0
  93. bscontroller-0.1.0/tests/__init__.py +2 -0
  94. bscontroller-0.1.0/tests/qualification/PROTOCOL.md +80 -0
  95. bscontroller-0.1.0/tests/qualification/PROTOCOL.zh-CN.md +80 -0
  96. bscontroller-0.1.0/tests/qualification/__init__.py +4 -0
  97. bscontroller-0.1.0/tests/qualification/cases.py +88 -0
  98. bscontroller-0.1.0/tests/qualification/conftest.py +160 -0
  99. bscontroller-0.1.0/tests/qualification/decision.py +117 -0
  100. bscontroller-0.1.0/tests/qualification/hci/__init__.py +35 -0
  101. bscontroller-0.1.0/tests/qualification/hci/connection_management_test.py +414 -0
  102. bscontroller-0.1.0/tests/qualification/hci/controller_configuration_test.py +1137 -0
  103. bscontroller-0.1.0/tests/qualification/hci/controller_flow_control_test.py +98 -0
  104. bscontroller-0.1.0/tests/qualification/hci/controller_information_test.py +399 -0
  105. bscontroller-0.1.0/tests/qualification/hci/device_discovery_test.py +2426 -0
  106. bscontroller-0.1.0/tests/qualification/hci/device_setup_test.py +341 -0
  107. bscontroller-0.1.0/tests/qualification/hci/event_versioning_test.py +433 -0
  108. bscontroller-0.1.0/tests/qualification/hci/generic_events_test.py +426 -0
  109. bscontroller-0.1.0/tests/qualification/hci/host_flow_control_test.py +111 -0
  110. bscontroller-0.1.0/tests/qualification/link.py +524 -0
  111. bscontroller-0.1.0/tests/qualification/ll/__init__.py +33 -0
  112. bscontroller-0.1.0/tests/qualification/ll/connection_test.py +19133 -0
  113. bscontroller-0.1.0/tests/qualification/ll/data_flow_test.py +307 -0
  114. bscontroller-0.1.0/tests/qualification/ll/device_discovery_test.py +11787 -0
  115. bscontroller-0.1.0/tests/qualification/ll/encoding_test.py +964 -0
  116. bscontroller-0.1.0/tests/qualification/ll/frequency_hopping_test.py +510 -0
  117. bscontroller-0.1.0/tests/qualification/ll/packet_handling_test.py +905 -0
  118. bscontroller-0.1.0/tests/qualification/ll/security_test.py +4630 -0
  119. bscontroller-0.1.0/tests/qualification/ll/timing_test.py +1502 -0
  120. bscontroller-0.1.0/tests/qualification/peer.py +637 -0
  121. bscontroller-0.1.0/tests/qualification/periodic.py +304 -0
  122. bscontroller-0.1.0/tests/qualification/privacy.py +209 -0
  123. bscontroller-0.1.0/tests/qualification/tester.py +786 -0
  124. bscontroller-0.1.0/tests/support.py +19 -0
  125. bscontroller-0.1.0/tests/unit/__init__.py +2 -0
  126. bscontroller-0.1.0/tests/unit/config_test.py +248 -0
  127. bscontroller-0.1.0/tests/unit/conftest.py +62 -0
  128. bscontroller-0.1.0/tests/unit/hci/__init__.py +2 -0
  129. bscontroller-0.1.0/tests/unit/hci/config_scenario_test.py +298 -0
  130. bscontroller-0.1.0/tests/unit/hci/conftest.py +39 -0
  131. bscontroller-0.1.0/tests/unit/hci/connection_scenario_test.py +1105 -0
  132. bscontroller-0.1.0/tests/unit/hci/controller_scenario_test.py +740 -0
  133. bscontroller-0.1.0/tests/unit/hci/discovery_scenario_test.py +1823 -0
  134. bscontroller-0.1.0/tests/unit/hci/harness.py +203 -0
  135. bscontroller-0.1.0/tests/unit/hci/snoop_test.py +175 -0
  136. bscontroller-0.1.0/tests/unit/hci/transport_test.py +158 -0
  137. bscontroller-0.1.0/tests/unit/helpers.py +198 -0
  138. bscontroller-0.1.0/tests/unit/linklayer/__init__.py +2 -0
  139. bscontroller-0.1.0/tests/unit/linklayer/advertising_test.py +477 -0
  140. bscontroller-0.1.0/tests/unit/linklayer/air/__init__.py +2 -0
  141. bscontroller-0.1.0/tests/unit/linklayer/air/conftest.py +15 -0
  142. bscontroller-0.1.0/tests/unit/linklayer/air/extended_advertising_test.py +1000 -0
  143. bscontroller-0.1.0/tests/unit/linklayer/air/extended_codec_test.py +205 -0
  144. bscontroller-0.1.0/tests/unit/linklayer/air/extended_scanning_test.py +1232 -0
  145. bscontroller-0.1.0/tests/unit/linklayer/air/harness.py +417 -0
  146. bscontroller-0.1.0/tests/unit/linklayer/air/legacy_advertising_test.py +951 -0
  147. bscontroller-0.1.0/tests/unit/linklayer/air/legacy_scanning_test.py +1002 -0
  148. bscontroller-0.1.0/tests/unit/linklayer/air/lifetime_test.py +1186 -0
  149. bscontroller-0.1.0/tests/unit/linklayer/air/periodic_test.py +1220 -0
  150. bscontroller-0.1.0/tests/unit/linklayer/air/privacy_test.py +271 -0
  151. bscontroller-0.1.0/tests/unit/linklayer/bitstream_test.py +89 -0
  152. bscontroller-0.1.0/tests/unit/linklayer/channel_selection_test.py +84 -0
  153. bscontroller-0.1.0/tests/unit/linklayer/decision_test.py +257 -0
  154. bscontroller-0.1.0/tests/unit/linklayer/llcp/__init__.py +2 -0
  155. bscontroller-0.1.0/tests/unit/linklayer/llcp/channel_map_test.py +729 -0
  156. bscontroller-0.1.0/tests/unit/linklayer/llcp/cipher_test.py +222 -0
  157. bscontroller-0.1.0/tests/unit/linklayer/llcp/collision_test.py +717 -0
  158. bscontroller-0.1.0/tests/unit/linklayer/llcp/conftest.py +33 -0
  159. bscontroller-0.1.0/tests/unit/linklayer/llcp/conn_update_test.py +1401 -0
  160. bscontroller-0.1.0/tests/unit/linklayer/llcp/connection_event_test.py +914 -0
  161. bscontroller-0.1.0/tests/unit/linklayer/llcp/data_length_test.py +839 -0
  162. bscontroller-0.1.0/tests/unit/linklayer/llcp/encryption_test.py +1437 -0
  163. bscontroller-0.1.0/tests/unit/linklayer/llcp/feature_version_test.py +724 -0
  164. bscontroller-0.1.0/tests/unit/linklayer/llcp/harness.py +495 -0
  165. bscontroller-0.1.0/tests/unit/linklayer/llcp/invalid_terminate_test.py +535 -0
  166. bscontroller-0.1.0/tests/unit/linklayer/llcp/phy_update_test.py +962 -0
  167. bscontroller-0.1.0/tests/unit/linklayer/llcp/tx_queue_test.py +665 -0
  168. bscontroller-0.1.0/tests/unit/linklayer/ownership_test.py +558 -0
  169. bscontroller-0.1.0/tests/unit/linklayer/parameters_test.py +191 -0
  170. bscontroller-0.1.0/tests/unit/linklayer/privacy_test.py +337 -0
  171. bscontroller-0.1.0/tests/unit/linklayer/scheduler_test.py +187 -0
  172. bscontroller-0.1.0/tests/unit/radio/__init__.py +2 -0
  173. bscontroller-0.1.0/tests/unit/radio/babblesim_test.py +990 -0
  174. bscontroller-0.1.0/tests/unit/radio/base_test.py +143 -0
  175. bscontroller-0.1.0/tests/unit/runtime/__init__.py +2 -0
  176. bscontroller-0.1.0/tests/unit/runtime/event_loop_test.py +698 -0
  177. bscontroller-0.1.0/tests/unit/runtime/phy_test.py +117 -0
  178. bscontroller-0.1.0/tests/unit/runtime/session_test.py +266 -0
  179. bscontroller-0.1.0/tests/unit/runtime/worker_test.py +723 -0
@@ -0,0 +1,221 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
203
+
204
+
205
+ ---
206
+
207
+
208
+ Files: src/bscontroller/colors.py
209
+ Copyright (c) 2012 Giorgos Verigakis <verigak@gmail.com>
210
+
211
+ Permission to use, copy, modify, and distribute this software for any
212
+ purpose with or without fee is hereby granted, provided that the above
213
+ copyright notice and this permission notice appear in all copies.
214
+
215
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
216
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
217
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
218
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
219
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
220
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
221
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
@@ -0,0 +1,5 @@
1
+ include LICENSE NOTICE README.md README.zh-CN.md
2
+ recursive-include docs *.svg *.md
3
+ recursive-include src *.py py.typed
4
+ recursive-include tests *.py *.md
5
+ recursive-include examples *.py *.md
@@ -0,0 +1,14 @@
1
+ BSController
2
+ Copyright 2026 Xiaomi Corporation
3
+
4
+ Protocol codecs and supporting utilities include code:
5
+ Copyright 2021-2025 Google LLC
6
+
7
+ The source files retain their individual copyright and license notices.
8
+ The package namespace and runtime entry points have been adapted for this
9
+ independent distribution. The LE radio execution path retains adapted HCI codecs and supporting
10
+ utilities; the former LocalLink, BR/EDR/LMP, and pairing execution paths
11
+ have been removed.
12
+
13
+ The terminal color utility carries the ISC permission notice reproduced in
14
+ LICENSE and src/bscontroller/colors.py.
@@ -0,0 +1,260 @@
1
+ Metadata-Version: 2.4
2
+ Name: bscontroller
3
+ Version: 0.1.0
4
+ Summary: Standalone Bluetooth LE controller with discrete simulation time
5
+ License-Expression: Apache-2.0 AND ISC
6
+ Project-URL: Homepage, https://github.com/XiaoMi/bsworld/tree/main/components/bscontroller
7
+ Project-URL: Issues, https://github.com/XiaoMi/bsworld/issues
8
+ Requires-Python: >=3.11
9
+ Description-Content-Type: text/markdown
10
+ License-File: LICENSE
11
+ License-File: NOTICE
12
+ Requires-Dist: cryptography>=44.0.3
13
+ Provides-Extra: test
14
+ Requires-Dist: pytest>=8.4; extra == "test"
15
+ Requires-Dist: pytest-asyncio>=1.4; extra == "test"
16
+ Requires-Dist: pytest-xdist>=3; extra == "test"
17
+ Requires-Dist: ruff==0.14.10; extra == "test"
18
+ Requires-Dist: build>=1; extra == "test"
19
+ Dynamic: license-file
20
+
21
+ # BSController
22
+
23
+ English | [简体中文](README.zh-CN.md)
24
+
25
+ BSController is a Bluetooth LE Controller written in Python. Your Host stack talks to it over standard H4 HCI, and it transmits and receives over a simulated radio ([BabbleSim](https://babblesim.github.io/)). Controllers on the same simulated radio communicate with each other. Simulation time is discrete, so runs are reproducible.
26
+
27
+ ## Quick start
28
+
29
+ BSController needs Linux, Python 3.11 or newer, and a BabbleSim build. On Ubuntu 24.04 x86_64, install the build tools:
30
+
31
+ ```sh
32
+ sudo apt-get update
33
+ sudo apt-get install -y git repo build-essential gcc-multilib g++-multilib python3-venv
34
+ ```
35
+
36
+ Fetch BabbleSim and build its PHY, modem and channel models:
37
+
38
+ ```sh
39
+ mkdir -p "$HOME/bsim" && cd "$HOME/bsim"
40
+ repo init -u https://github.com/BabbleSim/manifest.git -m everything.xml -b master
41
+ repo sync
42
+ export BSIM_OUT_PATH="$PWD/build"
43
+ export BSIM_COMPONENTS_PATH="$PWD/components"
44
+ make -j"$(nproc)" ext_2G4_phy_v1 ext_2G4_modem_BLE_simple ext_2G4_channel_multiatt
45
+ ```
46
+
47
+ Keep `BSIM_OUT_PATH` exported whenever you run BSController. See the BabbleSim [fetching](https://babblesim.github.io/fetching.html) and [building](https://babblesim.github.io/building.html) guides for other options.
48
+
49
+ Then install BSController from this directory:
50
+
51
+ ```sh
52
+ python3 -m venv .venv
53
+ source .venv/bin/activate
54
+ python -m pip install .
55
+ ```
56
+
57
+ ## Standalone Controller
58
+
59
+ Start a Controller and connect your Host to its socket:
60
+
61
+ ```sh
62
+ bscontroller serve --hci-socket /tmp/radio.sock --btsnoop-file /tmp/hci.snoop
63
+ ```
64
+
65
+ `serve` starts a BabbleSim PHY and serves H4 HCI on the Unix socket. It accepts one Host and exits when that Host disconnects; the socket path must not exist. `--btsnoop-file` saves the HCI traffic for Wireshark. See `bscontroller serve --help`.
66
+
67
+ The Controller runs on simulation time, which advances as fast as the machine allows. A Host that uses wall-clock time sees the Controller run ahead, so timers and timeouts on the two sides disagree.
68
+
69
+ For reproducible results, the Host must join the same discrete-time schedule. For a quick manual test, add BabbleSim's handbrake device instead, which holds simulation time close to wall-clock time. Start the PHY with one extra device, then join it:
70
+
71
+ ```sh
72
+ cd "$BSIM_OUT_PATH/bin"
73
+ ./bs_2G4_phy_v1 -s=demo -D=3 & # 0: Controller, 1: serve clock, 2: handbrake
74
+ ./bs_device_handbrake -s=demo -d=2 -r=1 & # -r: simulation/wall-clock ratio
75
+ bscontroller serve --join --sim-id demo --dev-id 0 --clock-id 1 \
76
+ --hci-socket /tmp/radio.sock --btsnoop-file /tmp/hci.snoop
77
+ ```
78
+
79
+ Timing then still depends on host load, so use this only for exploration.
80
+
81
+ ## Using BSController from Python
82
+
83
+ `RadioController` runs one Controller in its own worker thread. Create it inside a running asyncio event loop. `RadioSession` joins it to a PHY that is already running. The example below expects a PHY started with the same `sim_id` (`example`) and two devices: device `0` for the Controller and device `1` for the Host clock.
84
+
85
+ ```python
86
+ import asyncio
87
+ from pathlib import Path
88
+
89
+ from bscontroller import RadioController, RadioEventLoop, RadioSession
90
+
91
+
92
+ async def main():
93
+ controller = RadioController(
94
+ "controller", "F0:F1:F2:F3:F4:01", hci_socket=Path("/tmp/radio.sock")
95
+ )
96
+ async with RadioSession("example", [(0, controller)], clock_dev_id=1):
97
+ await controller.terminated
98
+
99
+
100
+ with asyncio.Runner(loop_factory=RadioEventLoop) as runner:
101
+ runner.run(main())
102
+ ```
103
+
104
+ [examples/advertise_scan.py](examples/advertise_scan.py) is a complete program built on these APIs: it starts the PHY with `PhyProcess`, runs an advertising and a scanning Controller in one `RadioSession`, and a mock Host scans over the scanner's socket. Run it with `python examples/advertise_scan.py`; see [examples/README.md](examples/README.md).
105
+
106
+ There are two ways to connect a Host:
107
+
108
+ - **Socket.** Pass `hci_socket`, as above. Any Host that speaks H4 over a Unix socket can connect. Startup returns once the socket is listening. HCI commands are processed after the Controller has synchronized with the PHY.
109
+ - **In process.** Omit `hci_socket`. Register an object with an `on_packet(packet: bytes)` method through `controller.set_packet_sink(sink)` before starting, then send complete H4 packets with `controller.on_packet(packet)`.
110
+
111
+ Pass `hci_snoop_file=Path(...)` to record a BTSnoop capture, timestamped with simulation time.
112
+
113
+ Other public names are `ControllerConfig` (see [Configuration](#configuration)), `RadioEventLoop`, `Radio`, `Phy`, `Received` and `hci` (HCI packet classes).
114
+
115
+ When managing the runtime yourself:
116
+
117
+ - `RadioSession` does not start the PHY; use `bscontroller.runtime.PhyProcess`.
118
+ - With `clock_dev_id`, the Host event loop must be a `RadioEventLoop`. Without it, you provide the clock and a distinct PHY device ID for every participant.
119
+ - Stop the Controllers before closing the Host clock and the PHY; `async with RadioSession(...)` does this.
120
+
121
+ ## Configuration
122
+
123
+ Values the Bluetooth specification leaves to the Controller form a `ControllerConfig`. Unset fields keep their defaults.
124
+
125
+ | JSON key | Default | Range | Spec (Vol 4, Part E) |
126
+ |---|---|---|---|
127
+ | `hciVersion` | `0x0F` (6.1) | `0x06`–`0x10` | 7.4.1 |
128
+ | `hciRevision` | `0` | `0`–`0xFFFF` | 7.4.1 |
129
+ | `lmpVersion` | `0x0F` (6.1) | `0x06`–`0x10` | 7.4.1 |
130
+ | `lmpSubversion` | `0` | `0`–`0xFFFF` | 7.4.1 |
131
+ | `manufacturer` | `0xFFFF` | `0`–`0xFFFF` | 7.4.1 |
132
+ | `aclPacketCount` | `8` | `1`–`255` | 7.8.2 |
133
+ | `aclPacketLength` | `251` | `27`–`65535` | 7.8.2 |
134
+ | `maxTxOctets` | `251` | `27`–`251` | 7.8.46 |
135
+ | `maxTxTime` | `17040` | `328`–`17040` | 7.8.46 |
136
+ | `maxRxOctets` | `251` | `27`–`251` | 7.8.46 |
137
+ | `maxRxTime` | `17040` | `328`–`17040` | 7.8.46 |
138
+ | `advertisingSetCount` | `16` | `1`–`240` | 7.8.58 |
139
+ | `maxAdvertisingDataLength` | `1650` | `31`–`1650` | 7.8.57 |
140
+ | `filterAcceptListSize` | `16` | `1`–`255` | 7.8.14 |
141
+ | `resolvingListSize` | `16` | `1`–`255` | 7.8.41 |
142
+ | `periodicAdvertiserListSize` | `8` | `1`–`255` | 7.8.73 |
143
+ | `maxConnections` | `64` | `1`–`3839` | 5.3.1 |
144
+ | `maxPeriodicSyncs` | `16` | `1`–`3839` | 5.3.1 |
145
+
146
+ A configuration file has a `defaults` object for every Controller, and a `controllers` object with one entry per Controller name:
147
+
148
+ ```json
149
+ {
150
+ "defaults": {"aclPacketCount": 16},
151
+ "controllers": {"hci0": {"maxConnections": 2}, "hci1": {"maxTxOctets": 27}}
152
+ }
153
+ ```
154
+
155
+ Keys are camelCase; snake_case also works. For each value, the most specific source wins: built-in default, then `defaults`, then `controllers.<name>`, then Python keyword arguments. An unknown key, or a value outside its range, is skipped with a warning; that field keeps its previous value and the rest of the file still applies.
156
+
157
+ On the command line:
158
+
159
+ ```sh
160
+ bscontroller config > bsc.json # every default, ready to edit
161
+ bscontroller serve --hci-socket /tmp/radio.sock --config bsc.json --name hci0
162
+ ```
163
+
164
+ In Python, pass the file (or an equivalent dict) to `RadioController`. Each Controller picks the `controllers` entry with its own name:
165
+
166
+ ```python
167
+ from bscontroller import ControllerConfig, RadioController
168
+
169
+ central = RadioController("hci0", "F0:F1:F2:F3:F4:01", config="bsc.json")
170
+ peripheral = RadioController("hci1", "F0:F1:F2:F3:F4:02", config="bsc.json")
171
+ other = RadioController("x", "F0:F1:F2:F3:F4:03", config=ControllerConfig(max_connections=2))
172
+ ```
173
+
174
+ `ControllerConfig(...)` raises `ValueError` for an invalid value.
175
+
176
+ ## Supported features
177
+
178
+ These are the Link Layer features of the Bluetooth Core specification, listed by the version that introduced them. `*` marks implemented features. Assigned Link Layer feature bits are reported in the LE FeatureSet ([Vol 6, Part B, 4.6](https://www.bluetooth.com/wp-content/uploads/Files/Specification/HTML/Core_v6.3/out/en/low-energy-controller/link-layer-specification.html#UUID-56ada5ed-4ae3-acee-198f-27ead57d86f1)). Bluetooth Classic (BR/EDR) is not.
179
+
180
+ | Core spec version | Link Layer feature | Supported |
181
+ |---|---|:---:|
182
+ | 4.0 | LE Encryption | * |
183
+ | 4.1 | Connection Parameters Request Procedure | * |
184
+ | 4.1 | Extended Reject Indication | * |
185
+ | 4.1 | Peripheral-initiated Features Exchange | * |
186
+ | 4.1 | LE Ping Procedure | * |
187
+ | 4.2 | LE Data Packet Length Extension | * |
188
+ | 4.2 | LL Privacy | * |
189
+ | 4.2 | Extended Scanner Filter Policies | * |
190
+ | 5.0 | LE 2M PHY | * |
191
+ | 5.0 | LE Coded PHY | * |
192
+ | 5.0 | Channel Selection Algorithm #2 | * |
193
+ | 5.0 | Minimum Number of Used Channels Procedure | * |
194
+ | 5.0 | Extended Advertising | * |
195
+ | 5.0 | Periodic Advertising | * |
196
+ | 5.1 | Connection CTE Request | |
197
+ | 5.1 | Connection CTE Response | |
198
+ | 5.1 | Connectionless CTE Transmitter | |
199
+ | 5.1 | Connectionless CTE Receiver | |
200
+ | 5.1 | Periodic Advertising Sync Transfer | |
201
+ | 5.1 | Initiating Periodic Advertising Sync Transfer for Local Periodic Advertising | |
202
+ | 5.1 | Initiating Periodic Advertising Sync Transfer for Remote Periodic Advertising | |
203
+ | 5.2 | Isochronous Broadcaster | |
204
+ | 5.2 | Synchronized Receiver | |
205
+ | 5.2 | Connected Isochronous Stream (CIS) | |
206
+ | 5.3 | Periodic Advertising ADI Support | |
207
+ | 5.3 | LE Channel Classification | |
208
+ | 5.3 | Connection Subrating | |
209
+ | 5.4 | Periodic Advertising with Responses | |
210
+ | 6.0 | Channel Sounding | |
211
+ | 6.0 | Decision-Based Advertising Filtering | * |
212
+ | 6.0 | Monitoring Advertisers | |
213
+ | 6.0 | Frame Space Update | |
214
+ | 6.1 | Randomized RPA Updates | * |
215
+ | 6.2 | Shorter Connection Intervals | |
216
+ | 6.2 | Channel Sounding Amplitude-based Attack Resilience | |
217
+ | 6.3 | Channel Sounding Inline Phase Correction Term Transfer | |
218
+
219
+ ## How it works
220
+
221
+ Each Controller contains an HCI layer, a Link Layer and a radio adapter. All Controllers connect to one BabbleSim PHY, which carries their packets on shared channels and advances one common simulation clock. Protocol behaviour follows [Bluetooth Core 6.3](https://www.bluetooth.com/wp-content/uploads/Files/Specification/HTML/Core_v6.3/out/en/architecture,-change-history,-and-conventions/architecture.html#UUID-37039e1f-e0cd-37ce-2cf0-15dd6e6cff2e).
222
+
223
+ <div align="center"><img src="docs/images/radio_controller_arch.svg" alt="Multiple Controllers sharing a BabbleSim PHY" width="80%"><br><em>Figure 1: Controllers on a shared PHY</em></div>
224
+
225
+ Inside one Controller, the Link Layer keeps a manager for each role (advertising, scanning, initiating, synchronizing, connections). Every ACL connection has its own control-procedure state, encryption state and connection-event executor. All roles share one radio scheduler, which decides what the single radio does next.
226
+
227
+ ![Internal modules, state ownership and interaction paths of one Controller](docs/images/radio_controller_internal_arch.svg)
228
+
229
+ *Figure 2: Inside one Controller. Nested boxes show ownership. Black arrows are calls, dashed green arrows are callbacks, orange marks scheduling, blue marks PDUs and radio results, and dotted gray marks runtime wiring.*
230
+
231
+ **Threads and time.** Each `RadioController` runs in a dedicated thread with its own event loop and PHY connection. The Host thread and the Controller thread share no state; they only pass immutable H4 packets. Radio time is in integer microseconds. Every Controller, and an optional Host clock, synchronizes with the PHY before simulation time advances, so timing does not depend on how fast the machine is.
232
+
233
+ | Object | Owns |
234
+ | --- | --- |
235
+ | `RadioController` | Worker thread, Controller event loop, radio connection |
236
+ | `RadioSession` | Starting and stopping workers, optional Host clock |
237
+ | `H4Server` | Unix socket, the Host connection, H4 framing |
238
+ | `PhyProcess` | BabbleSim PHY process, its logs and simulation directory |
239
+
240
+ ## Development
241
+
242
+ ```text
243
+ .
244
+ ├── src/bscontroller/ # Package: HCI, Link Layer, radio, runtime, config
245
+ ├── examples/ # Runnable two-Controller example with a mock Host
246
+ └── tests/
247
+ ├── unit/ # Fast tests, no PHY needed
248
+ └── qualification/ # HCI/LL protocol cases; radio cases need BabbleSim
249
+ ```
250
+
251
+ ```sh
252
+ python -m pip install -e '.[test]'
253
+ python -m pytest tests/unit -n auto -q # about 3 s
254
+ python -m pytest tests/qualification -n auto -v -rs # a few minutes, needs BSIM_OUT_PATH
255
+ python -m build # sdist and wheel in dist/
256
+ ```
257
+
258
+ The qualification suite runs 612 selected HCI and Link Layer test cases from the Bluetooth test specifications against independent lower testers. Passing them does not make BSController Bluetooth-qualified. See [tests/README.md](tests/README.md) for the test scope.
259
+
260
+ Licensing and third-party notices are in [LICENSE](LICENSE) and [NOTICE](NOTICE).