42
42
#define PREFER_S8_CODING 1
43
43
#define PREFER_S2_CODING 0
44
44
45
+ #define HOST_INITIATED 1U
46
+
45
47
static struct ll_conn conn ;
46
48
47
49
static void setup (void )
@@ -130,7 +132,7 @@ void test_phy_update_central_loc(void)
130
132
ull_cp_state_set (& conn , ULL_CP_CONNECTED );
131
133
132
134
/* Initiate an PHY Update Procedure */
133
- err = ull_cp_phy_update (& conn , PHY_2M , PREFER_S8_CODING , PHY_2M , 1 );
135
+ err = ull_cp_phy_update (& conn , PHY_2M , PREFER_S8_CODING , PHY_2M , HOST_INITIATED );
134
136
zassert_equal (err , BT_HCI_ERR_SUCCESS , NULL );
135
137
136
138
/* Prepare */
@@ -234,7 +236,7 @@ void test_phy_update_central_loc_invalid(void)
234
236
ull_cp_state_set (& conn , ULL_CP_CONNECTED );
235
237
236
238
/* Initiate an PHY Update Procedure */
237
- err = ull_cp_phy_update (& conn , PHY_2M , PREFER_S8_CODING , PHY_2M , 1 );
239
+ err = ull_cp_phy_update (& conn , PHY_2M , PREFER_S8_CODING , PHY_2M , HOST_INITIATED );
238
240
zassert_equal (err , BT_HCI_ERR_SUCCESS , NULL );
239
241
240
242
/* Prepare */
@@ -285,7 +287,7 @@ void test_phy_update_central_loc_unsupp_feat(void)
285
287
ull_cp_state_set (& conn , ULL_CP_CONNECTED );
286
288
287
289
/* Initiate an PHY Update Procedure */
288
- err = ull_cp_phy_update (& conn , PHY_2M , PREFER_S8_CODING , PHY_2M , 1 );
290
+ err = ull_cp_phy_update (& conn , PHY_2M , PREFER_S8_CODING , PHY_2M , HOST_INITIATED );
289
291
zassert_equal (err , BT_HCI_ERR_SUCCESS , NULL );
290
292
291
293
/* Prepare */
@@ -441,7 +443,7 @@ void test_phy_update_periph_loc(void)
441
443
ull_cp_state_set (& conn , ULL_CP_CONNECTED );
442
444
443
445
/* Initiate an PHY Update Procedure */
444
- err = ull_cp_phy_update (& conn , PHY_2M , PREFER_S8_CODING , PHY_2M , 1 );
446
+ err = ull_cp_phy_update (& conn , PHY_2M , PREFER_S8_CODING , PHY_2M , HOST_INITIATED );
445
447
zassert_equal (err , BT_HCI_ERR_SUCCESS , NULL );
446
448
447
449
/* Prepare */
@@ -706,7 +708,7 @@ void test_phy_update_central_loc_collision(void)
706
708
ull_cp_state_set (& conn , ULL_CP_CONNECTED );
707
709
708
710
/* Initiate an PHY Update Procedure */
709
- err = ull_cp_phy_update (& conn , PHY_2M , PREFER_S8_CODING , PHY_2M , 1 );
711
+ err = ull_cp_phy_update (& conn , PHY_2M , PREFER_S8_CODING , PHY_2M , HOST_INITIATED );
710
712
zassert_equal (err , BT_HCI_ERR_SUCCESS , NULL );
711
713
712
714
/*** ***/
@@ -893,7 +895,7 @@ void test_phy_update_central_rem_collision(void)
893
895
/*** ***/
894
896
895
897
/* Initiate an PHY Update Procedure */
896
- err = ull_cp_phy_update (& conn , PHY_2M , PREFER_S8_CODING , PHY_2M , 1 );
898
+ err = ull_cp_phy_update (& conn , PHY_2M , PREFER_S8_CODING , PHY_2M , HOST_INITIATED );
897
899
zassert_equal (err , BT_HCI_ERR_SUCCESS , NULL );
898
900
899
901
/*** ***/
@@ -1051,7 +1053,7 @@ void test_phy_update_periph_loc_collision(void)
1051
1053
/*** ***/
1052
1054
1053
1055
/* Initiate an PHY Update Procedure */
1054
- err = ull_cp_phy_update (& conn , PHY_2M , PREFER_S8_CODING , PHY_2M , 1 );
1056
+ err = ull_cp_phy_update (& conn , PHY_2M , PREFER_S8_CODING , PHY_2M , HOST_INITIATED );
1055
1057
zassert_equal (err , BT_HCI_ERR_SUCCESS , NULL );
1056
1058
1057
1059
/* Prepare */
@@ -1147,6 +1149,284 @@ void test_phy_update_periph_loc_collision(void)
1147
1149
"Free CTX buffers %d" , ctx_buffers_free ());
1148
1150
}
1149
1151
1152
+ void test_phy_update_central_loc_no_act_change (void )
1153
+ {
1154
+ uint8_t err ;
1155
+ struct node_tx * tx ;
1156
+ struct node_rx_pdu * ntf ;
1157
+ struct pdu_data * pdu ;
1158
+ struct pdu_data_llctrl_phy_req req = { .rx_phys = PHY_1M , .tx_phys = PHY_1M };
1159
+ struct pdu_data_llctrl_phy_req rsp = { .rx_phys = PHY_1M | PHY_2M ,
1160
+ .tx_phys = PHY_1M | PHY_2M };
1161
+ struct pdu_data_llctrl_phy_upd_ind ind = { .instant = 0 , .c_to_p_phy = 0 , .p_to_c_phy = 0 };
1162
+ uint16_t instant ;
1163
+
1164
+ struct node_rx_pu pu = { .status = BT_HCI_ERR_SUCCESS };
1165
+
1166
+ /* Role */
1167
+ test_set_role (& conn , BT_HCI_ROLE_CENTRAL );
1168
+
1169
+ /* Connect */
1170
+ ull_cp_state_set (& conn , ULL_CP_CONNECTED );
1171
+
1172
+ /* Initiate an PHY Update Procedure */
1173
+ err = ull_cp_phy_update (& conn , PHY_1M , PREFER_S8_CODING , PHY_1M , HOST_INITIATED );
1174
+ zassert_equal (err , BT_HCI_ERR_SUCCESS , NULL );
1175
+
1176
+ /* Prepare */
1177
+ event_prepare (& conn );
1178
+
1179
+ /* Tx Queue should have one LL Control PDU */
1180
+ lt_rx (LL_PHY_REQ , & conn , & tx , & req );
1181
+ lt_rx_q_is_empty (& conn );
1182
+
1183
+ /* Rx */
1184
+ lt_tx (LL_PHY_RSP , & conn , & rsp );
1185
+
1186
+ /* TX Ack */
1187
+ event_tx_ack (& conn , tx );
1188
+
1189
+ /* Done */
1190
+ event_done (& conn );
1191
+
1192
+ /* Check that data tx was paused */
1193
+ zassert_equal (conn .tx_q .pause_data , 1U , "Data tx is not paused" );
1194
+
1195
+ /* Release Tx */
1196
+ ull_cp_release_tx (& conn , tx );
1197
+
1198
+ /* Prepare */
1199
+ event_prepare (& conn );
1200
+
1201
+ /* Tx Queue should have one LL Control PDU */
1202
+ lt_rx (LL_PHY_UPDATE_IND , & conn , & tx , & ind );
1203
+ lt_rx_q_is_empty (& conn );
1204
+
1205
+ /* TX Ack */
1206
+ event_tx_ack (& conn , tx );
1207
+
1208
+ /* Check that data tx is no longer paused */
1209
+ zassert_equal (conn .tx_q .pause_data , 0U , "Data tx is paused" );
1210
+
1211
+ /* Done */
1212
+ event_done (& conn );
1213
+
1214
+ /* Save Instant */
1215
+ pdu = (struct pdu_data * )tx -> pdu ;
1216
+ instant = sys_le16_to_cpu (pdu -> llctrl .phy_upd_ind .instant );
1217
+
1218
+ /* Check if instant is zero, due to no actual PHY change */
1219
+ zassert_equal (instant , 0 , "Unexpected instant %d" , instant );
1220
+
1221
+ /* Release Tx */
1222
+ ull_cp_release_tx (& conn , tx );
1223
+
1224
+ /* There should be one host notifications, due to host initiated PHY upd */
1225
+ ut_rx_node (NODE_PHY_UPDATE , & ntf , & pu );
1226
+ ut_rx_q_is_empty ();
1227
+
1228
+ /* Release Ntf */
1229
+ ull_cp_release_ntf (ntf );
1230
+
1231
+ CHECK_CURRENT_PHY_STATE (conn , PHY_1M , PREFER_S8_CODING , PHY_1M );
1232
+ CHECK_PREF_PHY_STATE (conn , PHY_1M , PHY_1M );
1233
+
1234
+ zassert_equal (ctx_buffers_free (), test_ctx_buffers_cnt (), "Free CTX buffers %d" ,
1235
+ ctx_buffers_free ());
1236
+ }
1237
+
1238
+ void test_phy_update_central_rem_no_actual_change (void )
1239
+ {
1240
+ struct node_tx * tx ;
1241
+ struct pdu_data * pdu ;
1242
+ struct pdu_data_llctrl_phy_req req = { .rx_phys = PHY_1M , .tx_phys = PHY_1M };
1243
+ struct pdu_data_llctrl_phy_upd_ind ind = { .instant = 0 , .c_to_p_phy = 0 , .p_to_c_phy = 0 };
1244
+ uint16_t instant ;
1245
+
1246
+ /* Role */
1247
+ test_set_role (& conn , BT_HCI_ROLE_CENTRAL );
1248
+
1249
+ /* Connect */
1250
+ ull_cp_state_set (& conn , ULL_CP_CONNECTED );
1251
+
1252
+ /* Prepare */
1253
+ event_prepare (& conn );
1254
+
1255
+ /* Rx */
1256
+ lt_tx (LL_PHY_REQ , & conn , & req );
1257
+
1258
+ /* TX Ack */
1259
+ event_tx_ack (& conn , tx );
1260
+
1261
+ /* Done */
1262
+ event_done (& conn );
1263
+
1264
+ /* Check that data tx was paused */
1265
+ zassert_equal (conn .tx_q .pause_data , 1U , "Data tx is not paused" );
1266
+
1267
+ /* Prepare */
1268
+ event_prepare (& conn );
1269
+
1270
+ /* Tx Queue should have one LL Control PDU */
1271
+ lt_rx (LL_PHY_UPDATE_IND , & conn , & tx , & ind );
1272
+ lt_rx_q_is_empty (& conn );
1273
+
1274
+ /* TX Ack */
1275
+ event_tx_ack (& conn , tx );
1276
+
1277
+ /* Done */
1278
+ event_done (& conn );
1279
+
1280
+ /* Check that data tx is no longer paused */
1281
+ zassert_equal (conn .tx_q .pause_data , 0U , "Data tx is paused" );
1282
+
1283
+ /* Save Instant */
1284
+ pdu = (struct pdu_data * )tx -> pdu ;
1285
+ instant = sys_le16_to_cpu (pdu -> llctrl .phy_upd_ind .instant );
1286
+
1287
+ /* Check if instant is zero, due to no actual PHY change */
1288
+ zassert_equal (instant , 0 , "Unexpected instant %d" , instant );
1289
+
1290
+ /* Release Tx */
1291
+ ull_cp_release_tx (& conn , tx );
1292
+
1293
+ /* There is not actual PHY change, so there shouldn't be host notification */
1294
+ ut_rx_q_is_empty ();
1295
+
1296
+ CHECK_CURRENT_PHY_STATE (conn , PHY_1M , PREFER_S8_CODING , PHY_1M );
1297
+ CHECK_PREF_PHY_STATE (conn , PHY_1M | PHY_2M | PHY_CODED , PHY_1M | PHY_2M | PHY_CODED );
1298
+
1299
+ zassert_equal (ctx_buffers_free (), test_ctx_buffers_cnt (), "Free CTX buffers %d" ,
1300
+ ctx_buffers_free ());
1301
+ }
1302
+
1303
+ void test_phy_update_periph_loc_no_actual_change (void )
1304
+ {
1305
+ uint8_t err ;
1306
+ struct node_tx * tx ;
1307
+ struct node_rx_pdu * ntf ;
1308
+ struct pdu_data_llctrl_phy_req req = { .rx_phys = PHY_1M , .tx_phys = PHY_1M };
1309
+ struct node_rx_pu pu = { .status = BT_HCI_ERR_SUCCESS };
1310
+ struct pdu_data_llctrl_phy_upd_ind phy_update_ind = { .instant = 0 ,
1311
+ .c_to_p_phy = 0 ,
1312
+ .p_to_c_phy = 0 };
1313
+
1314
+ /* Role */
1315
+ test_set_role (& conn , BT_HCI_ROLE_PERIPHERAL );
1316
+
1317
+ /* Connect */
1318
+ ull_cp_state_set (& conn , ULL_CP_CONNECTED );
1319
+
1320
+ /* Initiate an PHY Update Procedure */
1321
+ err = ull_cp_phy_update (& conn , PHY_1M , PREFER_S8_CODING , PHY_1M , HOST_INITIATED );
1322
+ zassert_equal (err , BT_HCI_ERR_SUCCESS , NULL );
1323
+
1324
+ /* Prepare */
1325
+ event_prepare (& conn );
1326
+
1327
+ /* Tx Queue should have one LL Control PDU */
1328
+ lt_rx (LL_PHY_REQ , & conn , & tx , & req );
1329
+ lt_rx_q_is_empty (& conn );
1330
+
1331
+ /* TX Ack */
1332
+ event_tx_ack (& conn , tx );
1333
+
1334
+ /* Done */
1335
+ event_done (& conn );
1336
+
1337
+ /* Release Tx */
1338
+ ull_cp_release_tx (& conn , tx );
1339
+
1340
+ /* Prepare */
1341
+ event_prepare (& conn );
1342
+
1343
+ /* Tx Queue should NOT have a LL Control PDU */
1344
+ lt_rx_q_is_empty (& conn );
1345
+
1346
+ /* Rx */
1347
+ lt_tx (LL_PHY_UPDATE_IND , & conn , & phy_update_ind );
1348
+
1349
+ /* Done */
1350
+ event_done (& conn );
1351
+
1352
+ /* There should be one notification due to Host initiated PHY UPD */
1353
+ ut_rx_node (NODE_PHY_UPDATE , & ntf , & pu );
1354
+ ut_rx_q_is_empty ();
1355
+
1356
+ /* Release Ntf */
1357
+ ull_cp_release_ntf (ntf );
1358
+
1359
+ CHECK_CURRENT_PHY_STATE (conn , PHY_1M , PREFER_S8_CODING , PHY_1M );
1360
+ CHECK_PREF_PHY_STATE (conn , PHY_1M , PHY_1M );
1361
+
1362
+ zassert_equal (ctx_buffers_free (), test_ctx_buffers_cnt (), "Free CTX buffers %d" ,
1363
+ ctx_buffers_free ());
1364
+ }
1365
+
1366
+ void test_phy_update_periph_rem_no_actual_change (void )
1367
+ {
1368
+ struct node_tx * tx ;
1369
+ struct pdu_data_llctrl_phy_req req = { .rx_phys = PHY_1M , .tx_phys = PHY_1M };
1370
+ struct pdu_data_llctrl_phy_req rsp = { .rx_phys = PHY_1M | PHY_2M | PHY_CODED ,
1371
+ .tx_phys = PHY_1M | PHY_2M | PHY_CODED };
1372
+ struct pdu_data_llctrl_phy_upd_ind ind = { .instant = 0 , .c_to_p_phy = 0 , .p_to_c_phy = 0 };
1373
+
1374
+ /* Role */
1375
+ test_set_role (& conn , BT_HCI_ROLE_PERIPHERAL );
1376
+
1377
+ /* Connect */
1378
+ ull_cp_state_set (& conn , ULL_CP_CONNECTED );
1379
+
1380
+ /* Prepare */
1381
+ event_prepare (& conn );
1382
+
1383
+ /* Tx Queue should NOT have a LL Control PDU */
1384
+ lt_rx_q_is_empty (& conn );
1385
+
1386
+ /* Rx */
1387
+ lt_tx (LL_PHY_REQ , & conn , & req );
1388
+
1389
+ /* Done */
1390
+ event_done (& conn );
1391
+
1392
+ /* We received a REQ, so data tx should be paused */
1393
+ zassert_equal (conn .tx_q .pause_data , 1U , "Data tx is not paused" );
1394
+
1395
+ /* Prepare */
1396
+ event_prepare (& conn );
1397
+
1398
+ /* Tx Queue should have one LL Control PDU */
1399
+ lt_rx (LL_PHY_RSP , & conn , & tx , & rsp );
1400
+ lt_rx_q_is_empty (& conn );
1401
+
1402
+ /* Rx */
1403
+ lt_tx (LL_PHY_UPDATE_IND , & conn , & ind );
1404
+
1405
+ /* We are sending RSP, so data tx should be paused until after tx ack */
1406
+ zassert_equal (conn .tx_q .pause_data , 1U , "Data tx is not paused" );
1407
+
1408
+ /* TX Ack */
1409
+ event_tx_ack (& conn , tx );
1410
+
1411
+ /* Check that data tx is no longer paused */
1412
+ zassert_equal (conn .tx_q .pause_data , 0U , "Data tx is paused" );
1413
+
1414
+ /* Done */
1415
+ event_done (& conn );
1416
+
1417
+ /* Release Tx */
1418
+ ull_cp_release_tx (& conn , tx );
1419
+
1420
+ /* There should be no host notification */
1421
+ ut_rx_q_is_empty ();
1422
+
1423
+ CHECK_CURRENT_PHY_STATE (conn , PHY_1M , PREFER_S8_CODING , PHY_1M );
1424
+ CHECK_PREF_PHY_STATE (conn , PHY_1M | PHY_2M | PHY_CODED , PHY_1M | PHY_2M | PHY_CODED );
1425
+
1426
+ zassert_equal (ctx_buffers_free (), test_ctx_buffers_cnt (), "Free CTX buffers %d" ,
1427
+ ctx_buffers_free ());
1428
+ }
1429
+
1150
1430
void test_main (void )
1151
1431
{
1152
1432
ztest_test_suite (
@@ -1166,6 +1446,14 @@ void test_main(void)
1166
1446
ztest_unit_test_setup_teardown (test_phy_update_central_rem_collision , setup ,
1167
1447
unit_test_noop ),
1168
1448
ztest_unit_test_setup_teardown (test_phy_update_periph_loc_collision , setup ,
1449
+ unit_test_noop ),
1450
+ ztest_unit_test_setup_teardown (test_phy_update_central_loc_no_act_change , setup ,
1451
+ unit_test_noop ),
1452
+ ztest_unit_test_setup_teardown (test_phy_update_central_rem_no_actual_change , setup ,
1453
+ unit_test_noop ),
1454
+ ztest_unit_test_setup_teardown (test_phy_update_periph_rem_no_actual_change , setup ,
1455
+ unit_test_noop ),
1456
+ ztest_unit_test_setup_teardown (test_phy_update_periph_loc_no_actual_change , setup ,
1169
1457
unit_test_noop ));
1170
1458
1171
1459
ztest_run_test_suite (phy );
0 commit comments