Skip to content

Commit f4dd2f3

Browse files
committed
nimble/ll: Set LE supported states based on enabled roles
This also fix claiming support for concurrent scanning and initiating which is not supported by LL yet.
1 parent d3a1acd commit f4dd2f3

File tree

1 file changed

+165
-42
lines changed

1 file changed

+165
-42
lines changed

nimble/controller/src/ble_ll.c

Lines changed: 165 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -65,48 +65,171 @@
6565
*/
6666

6767
/* Supported states */
68-
#define BLE_LL_S_NCA (0x00000000001)
69-
#define BLE_LL_S_SA (0x00000000002)
70-
#define BLE_LL_S_CA (0x00000000004)
71-
#define BLE_LL_S_HDCA (0x00000000008)
72-
#define BLE_LL_S_PS (0x00000000010)
73-
#define BLE_LL_S_AS (0x00000000020)
74-
#define BLE_LL_S_INIT (0x00000000040)
75-
#define BLE_LL_S_SLAVE (0x00000000080)
76-
#define BLE_LL_S_NCA_PS (0x00000000100)
77-
#define BLE_LL_S_SA_PS (0x00000000200)
78-
#define BLE_LL_S_CA_PS (0x00000000400)
79-
#define BLE_LL_S_HDCA_PS (0x00000000800)
80-
#define BLE_LL_S_NCA_AS (0x00000001000)
81-
#define BLE_LL_S_SA_AS (0x00000002000)
82-
#define BLE_LL_S_CA_AS (0x00000004000)
83-
#define BLE_LL_S_HDCA_AS (0x00000008000)
84-
#define BLE_LL_S_NCA_INIT (0x00000010000)
85-
#define BLE_LL_S_SA_INIT (0x00000020000)
86-
#define BLE_LL_S_NCA_MASTER (0x00000040000)
87-
#define BLE_LL_S_SA_MASTER (0x00000080000)
88-
#define BLE_LL_S_NCA_SLAVE (0x00000100000)
89-
#define BLE_LL_S_SA_SLAVE (0x00000200000)
90-
#define BLE_LL_S_PS_INIT (0x00000400000)
91-
#define BLE_LL_S_AS_INIT (0x00000800000)
92-
#define BLE_LL_S_PS_MASTER (0x00001000000)
93-
#define BLE_LL_S_AS_MASTER (0x00002000000)
94-
#define BLE_LL_S_PS_SLAVE (0x00004000000)
95-
#define BLE_LL_S_AS_SLAVE (0x00008000000)
96-
#define BLE_LL_S_INIT_MASTER (0x00010000000)
97-
#define BLE_LL_S_LDCA (0x00020000000)
98-
#define BLE_LL_S_LDCA_PS (0x00040000000)
99-
#define BLE_LL_S_LDCA_AS (0x00080000000)
100-
#define BLE_LL_S_CA_INIT (0x00100000000)
101-
#define BLE_LL_S_HDCA_INIT (0x00200000000)
102-
#define BLE_LL_S_LDCA_INIT (0x00400000000)
103-
#define BLE_LL_S_CA_MASTER (0x00800000000)
104-
#define BLE_LL_S_HDCA_MASTER (0x01000000000)
105-
#define BLE_LL_S_LDCA_MASTER (0x02000000000)
106-
#define BLE_LL_S_CA_SLAVE (0x04000000000)
107-
#define BLE_LL_S_HDCA_SLAVE (0x08000000000)
108-
#define BLE_LL_S_LDCA_SLAVE (0x10000000000)
109-
#define BLE_LL_S_INIT_SLAVE (0x20000000000)
68+
#if MYNEWT_VAL(BLE_LL_ROLE_BROADCASTER)
69+
#define BLE_LL_S_NCA ((uint64_t)1 << 0)
70+
#define BLE_LL_S_SA ((uint64_t)1 << 1)
71+
#else
72+
#define BLE_LL_S_NCA ((uint64_t)0 << 0)
73+
#define BLE_LL_S_SA ((uint64_t)0 << 1)
74+
#endif
75+
76+
#if MYNEWT_VAL(BLE_LL_ROLE_PERIPHERAL)
77+
#define BLE_LL_S_CA ((uint64_t)1 << 2)
78+
#define BLE_LL_S_HDCA ((uint64_t)1 << 3)
79+
#else
80+
#define BLE_LL_S_CA ((uint64_t)0 << 2)
81+
#define BLE_LL_S_HDCA ((uint64_t)0 << 3)
82+
#endif
83+
84+
#if MYNEWT_VAL(BLE_LL_ROLE_OBSERVER)
85+
#define BLE_LL_S_PS ((uint64_t)1 << 4)
86+
#define BLE_LL_S_AS ((uint64_t)1 << 5)
87+
#else
88+
#define BLE_LL_S_PS ((uint64_t)0 << 4)
89+
#define BLE_LL_S_AS ((uint64_t)0 << 5)
90+
#endif
91+
92+
#if MYNEWT_VAL(BLE_LL_ROLE_CENTRAL)
93+
#define BLE_LL_S_INIT ((uint64_t)1 << 6)
94+
#else
95+
#define BLE_LL_S_INIT ((uint64_t)0 << 6)
96+
#endif
97+
98+
#if MYNEWT_VAL(BLE_LL_ROLE_PERIPHERAL)
99+
#define BLE_LL_S_SLAVE ((uint64_t)1 << 7)
100+
#else
101+
#define BLE_LL_S_SLAVE ((uint64_t)0 << 7)
102+
#endif
103+
104+
#if MYNEWT_VAL(BLE_LL_ROLE_BROADCASTER) && MYNEWT_VAL(BLE_LL_ROLE_OBSERVER)
105+
#define BLE_LL_S_NCA_PS ((uint64_t)1 << 8)
106+
#define BLE_LL_S_SA_PS ((uint64_t)1 << 9)
107+
#else
108+
#define BLE_LL_S_NCA_PS ((uint64_t)0 << 8)
109+
#define BLE_LL_S_SA_PS ((uint64_t)0 << 9)
110+
#endif
111+
112+
#if MYNEWT_VAL(BLE_LL_ROLE_PERIPHERAL) && MYNEWT_VAL(BLE_LL_ROLE_OBSERVER)
113+
#define BLE_LL_S_CA_PS ((uint64_t)1 << 10)
114+
#define BLE_LL_S_HDCA_PS ((uint64_t)1 << 11)
115+
#else
116+
#define BLE_LL_S_CA_PS ((uint64_t)0 << 10)
117+
#define BLE_LL_S_HDCA_PS ((uint64_t)0 << 11)
118+
#endif
119+
120+
#if MYNEWT_VAL(BLE_LL_ROLE_BROADCASTER) && MYNEWT_VAL(BLE_LL_ROLE_OBSERVER)
121+
#define BLE_LL_S_NCA_AS ((uint64_t)1 << 12)
122+
#define BLE_LL_S_SA_AS ((uint64_t)1 << 13)
123+
#else
124+
#define BLE_LL_S_NCA_AS ((uint64_t)0 << 12)
125+
#define BLE_LL_S_SA_AS ((uint64_t)0 << 13)
126+
#endif
127+
128+
#if MYNEWT_VAL(BLE_LL_ROLE_PERIPHERAL) && MYNEWT_VAL(BLE_LL_ROLE_OBSERVER)
129+
#define BLE_LL_S_CA_AS ((uint64_t)1 << 14)
130+
#define BLE_LL_S_HDCA_AS ((uint64_t)1 << 15)
131+
#else
132+
#define BLE_LL_S_CA_AS ((uint64_t)0 << 14)
133+
#define BLE_LL_S_HDCA_AS ((uint64_t)0 << 15)
134+
#endif
135+
136+
#if MYNEWT_VAL(BLE_LL_ROLE_BROADCASTER) && MYNEWT_VAL(BLE_LL_ROLE_CENTRAL)
137+
#define BLE_LL_S_NCA_INIT ((uint64_t)1 << 16)
138+
#define BLE_LL_S_SA_INIT ((uint64_t)1 << 17)
139+
#define BLE_LL_S_NCA_MASTER ((uint64_t)1 << 18)
140+
#define BLE_LL_S_SA_MASTER ((uint64_t)1 << 19)
141+
#else
142+
#define BLE_LL_S_NCA_INIT ((uint64_t)0 << 16)
143+
#define BLE_LL_S_SA_INIT ((uint64_t)0 << 17)
144+
#define BLE_LL_S_NCA_MASTER ((uint64_t)0 << 18)
145+
#define BLE_LL_S_SA_MASTER ((uint64_t)0 << 19)
146+
#endif
147+
148+
#if MYNEWT_VAL(BLE_LL_ROLE_BROADCASTER) && MYNEWT_VAL(BLE_LL_ROLE_PERIPHERAL)
149+
#define BLE_LL_S_NCA_SLAVE ((uint64_t)1 << 20)
150+
#define BLE_LL_S_SA_SLAVE ((uint64_t)1 << 21)
151+
#else
152+
#define BLE_LL_S_NCA_SLAVE ((uint64_t)0 << 20)
153+
#define BLE_LL_S_SA_SLAVE ((uint64_t)0 << 21)
154+
#endif
155+
156+
#if MYNEWT_VAL(BLE_LL_ROLE_OBSERVER) && MYNEWT_VAL(BLE_LL_ROLE_CENTRAL)
157+
/* We do not support passive scanning while initiating yet */
158+
#define BLE_LL_S_PS_INIT ((uint64_t)0 << 22)
159+
/* We do not support active scanning while initiating yet */
160+
#define BLE_LL_S_AS_INIT ((uint64_t)0 << 23)
161+
#define BLE_LL_S_PS_MASTER ((uint64_t)1 << 24)
162+
#define BLE_LL_S_AS_MASTER ((uint64_t)1 << 25)
163+
#else
164+
#define BLE_LL_S_PS_INIT ((uint64_t)0 << 22)
165+
#define BLE_LL_S_AS_INIT ((uint64_t)0 << 23)
166+
#define BLE_LL_S_PS_MASTER ((uint64_t)0 << 24)
167+
#define BLE_LL_S_AS_MASTER ((uint64_t)0 << 25)
168+
#endif
169+
170+
#if MYNEWT_VAL(BLE_LL_ROLE_OBSERVER) && MYNEWT_VAL(BLE_LL_ROLE_PERIPHERAL)
171+
#define BLE_LL_S_PS_SLAVE ((uint64_t)1 << 26)
172+
#define BLE_LL_S_AS_SLAVE ((uint64_t)1 << 27)
173+
#else
174+
#define BLE_LL_S_PS_SLAVE ((uint64_t)0 << 26)
175+
#define BLE_LL_S_AS_SLAVE ((uint64_t)0 << 27)
176+
#endif
177+
178+
#if MYNEWT_VAL(BLE_LL_ROLE_CENTRAL)
179+
#define BLE_LL_S_INIT_MASTER ((uint64_t)1 << 28)
180+
#else
181+
#define BLE_LL_S_INIT_MASTER ((uint64_t)0 << 28)
182+
#endif
183+
184+
#if MYNEWT_VAL(BLE_LL_ROLE_PERIPHERAL)
185+
#define BLE_LL_S_LDCA ((uint64_t)1 << 29)
186+
#else
187+
#define BLE_LL_S_LDCA ((uint64_t)0 << 29)
188+
#endif
189+
190+
#if MYNEWT_VAL(BLE_LL_ROLE_PERIPHERAL) && MYNEWT_VAL(BLE_LL_ROLE_OBSERVER)
191+
#define BLE_LL_S_LDCA_PS ((uint64_t)1 << 30)
192+
#define BLE_LL_S_LDCA_AS ((uint64_t)1 << 31)
193+
#else
194+
#define BLE_LL_S_LDCA_PS ((uint64_t)0 << 30)
195+
#define BLE_LL_S_LDCA_AS ((uint64_t)0 << 31)
196+
#endif
197+
198+
#if MYNEWT_VAL(BLE_LL_ROLE_PERIPHERAL) && MYNEWT_VAL(BLE_LL_ROLE_CENTRAL)
199+
#define BLE_LL_S_CA_INIT ((uint64_t)1 << 32)
200+
#define BLE_LL_S_HDCA_INIT ((uint64_t)1 << 33)
201+
#define BLE_LL_S_LDCA_INIT ((uint64_t)1 << 34)
202+
#else
203+
#define BLE_LL_S_CA_INIT ((uint64_t)0 << 32)
204+
#define BLE_LL_S_HDCA_INIT ((uint64_t)0 << 33)
205+
#define BLE_LL_S_LDCA_INIT ((uint64_t)0 << 34)
206+
#endif
207+
208+
#if MYNEWT_VAL(BLE_LL_ROLE_CENTRAL)
209+
#define BLE_LL_S_CA_MASTER ((uint64_t)1 << 35)
210+
#define BLE_LL_S_HDCA_MASTER ((uint64_t)1 << 36)
211+
#define BLE_LL_S_LDCA_MASTER ((uint64_t)1 << 37)
212+
#else
213+
#define BLE_LL_S_CA_MASTER ((uint64_t)0 << 35)
214+
#define BLE_LL_S_HDCA_MASTER ((uint64_t)0 << 36)
215+
#define BLE_LL_S_LDCA_MASTER ((uint64_t)0 << 37)
216+
#endif
217+
218+
#if MYNEWT_VAL(BLE_LL_ROLE_PERIPHERAL)
219+
#define BLE_LL_S_CA_SLAVE ((uint64_t)1 << 38)
220+
#define BLE_LL_S_HDCA_SLAVE ((uint64_t)1 << 39)
221+
#define BLE_LL_S_LDCA_SLAVE ((uint64_t)1 << 40)
222+
#else
223+
#define BLE_LL_S_CA_SLAVE ((uint64_t)0 << 38)
224+
#define BLE_LL_S_HDCA_SLAVE ((uint64_t)0 << 39)
225+
#define BLE_LL_S_LDCA_SLAVE ((uint64_t)0 << 40)
226+
#endif
227+
228+
#if MYNEWT_VAL(BLE_LL_ROLE_PERIPHERAL) && MYNEWT_VAL(BLE_LL_ROLE_CENTRAL)
229+
#define BLE_LL_S_INIT_SLAVE ((uint64_t)1 << 41)
230+
#else
231+
#define BLE_LL_S_INIT_SLAVE ((uint64_t)0 << 41)
232+
#endif
110233

111234
#define BLE_LL_SUPPORTED_STATES \
112235
( \

0 commit comments

Comments
 (0)