Skip to content

Commit dfc57ca

Browse files
authored
Merge pull request aws#1225 from bcukuro/ble_test_zshijing
Ble test manufacturer data
2 parents fb5be59 + be88cf5 commit dfc57ca

File tree

7 files changed

+135
-19
lines changed

7 files changed

+135
-19
lines changed

libraries/abstractions/ble_hal/test/include/iot_test_ble_hal_afqp.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ void prvSetAdvertisement( BTGattAdvertismentParams_t * pxParams,
4343
uint16_t usServiceDataLen,
4444
char * pcServiceData,
4545
BTUuid_t * pxServiceUuid,
46-
size_t xNbServices );
46+
size_t xNbServices,
47+
uint16_t usManufacturerLen,
48+
char * pcManufacturerData );
4749

4850
#endif /* _IOT_TEST_BLE_HAL_AFQP_H_ */

libraries/abstractions/ble_hal/test/include/iot_test_ble_hal_common.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,9 @@ void IotTestBleHal_BTUnregister( void );
486486
void IotTestBleHal_BLEGAPInit( void );
487487
void IotTestBleHal_BLEGATTInit( void );
488488
void IotTestBleHal_SetAdvProperty( void );
489-
void IotTestBleHal_SetAdvData( BTuuidType_t Type );
489+
void IotTestBleHal_SetAdvData( BTuuidType_t Type,
490+
uint16_t usManufacturerLen,
491+
char * pcManufacturerData );
490492

491493
void prvSendNotification( bletestAttSrvB_t xAttribute,
492494
bool bConfirm );

libraries/abstractions/ble_hal/test/src/iot_test_ble_hal_afqp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ TEST( Full_BLE, BLE_Advertising_StartAdvertisement )
595595

596596
TEST( Full_BLE, BLE_Advertising_SetAvertisementData )
597597
{
598-
IotTestBleHal_SetAdvData( eBTuuidType128 );
598+
IotTestBleHal_SetAdvData( eBTuuidType128, 0, NULL );
599599
}
600600

601601
TEST( Full_BLE, BLE_Advertising_SetProperties )

libraries/abstractions/ble_hal/test/src/iot_test_ble_hal_common.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -602,15 +602,17 @@ static void prvSetAdvertisement( BTGattAdvertismentParams_t * pxParams,
602602
uint16_t usServiceDataLen,
603603
char * pcServiceData,
604604
BTUuid_t * pxServiceUuid,
605-
size_t xNbServices )
605+
size_t xNbServices,
606+
uint16_t usManufacturerLen,
607+
char * pcManufacturerData )
606608
{
607609
BTStatus_t xStatus = eBTStatusSuccess;
608610
BLETESTAdvParamCallback_t xAdvParamCallback;
609611

610612
xStatus = _pxBTLeAdapterInterface->pxSetAdvData( _ucBLEAdapterIf,
611613
pxParams,
612-
0,
613-
NULL,
614+
usManufacturerLen,
615+
pcManufacturerData,
614616
usServiceDataLen,
615617
pcServiceData,
616618
pxServiceUuid,
@@ -623,14 +625,17 @@ static void prvSetAdvertisement( BTGattAdvertismentParams_t * pxParams,
623625
}
624626

625627

626-
void IotTestBleHal_SetAdvData( BTuuidType_t type )
628+
void IotTestBleHal_SetAdvData( BTuuidType_t type,
629+
uint16_t usManufacturerLen,
630+
char * pcManufacturerData )
627631
{
628632
uint16_t usServiceDataLen;
629633
char * pcServiceData;
630634
uint8_t serviceUUID_128[ bt128BIT_UUID_LEN ] = bletestsFREERTOS_SVC_UUID_128;
631635
/* To make sure stack creates their own pointers, use local variables */
632636
BTGattAdvertismentParams_t l_xAdvertisementConfigA;
633637
BTGattAdvertismentParams_t l_xAdvertisementConfigB;
638+
size_t xNbServices;
634639

635640
BTUuid_t xServiceUuid =
636641
{
@@ -652,8 +657,6 @@ void IotTestBleHal_SetAdvData( BTuuidType_t type )
652657
break;
653658
}
654659

655-
size_t xNbServices;
656-
657660
usServiceDataLen = 0;
658661
pcServiceData = NULL;
659662
xNbServices = 1;
@@ -665,13 +668,17 @@ void IotTestBleHal_SetAdvData( BTuuidType_t type )
665668
usServiceDataLen,
666669
pcServiceData,
667670
&xServiceUuid,
668-
xNbServices );
671+
xNbServices,
672+
usManufacturerLen,
673+
pcManufacturerData );
669674

670675
prvSetAdvertisement( &l_xAdvertisementConfigB,
671676
usServiceDataLen,
672677
pcServiceData,
673678
NULL,
674-
0 );
679+
0,
680+
usManufacturerLen,
681+
pcManufacturerData );
675682
}
676683

677684
void IotTestBleHal_CheckIndicationNotification( bool IsIndication,

libraries/abstractions/ble_hal/test/src/iot_test_ble_hal_integration.c

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ TEST_SETUP( Full_BLE_Integration_Test_Connection )
106106

107107
/* Advertise and Connect */
108108
IotTestBleHal_SetAdvProperty();
109-
IotTestBleHal_SetAdvData( eBTuuidType128 );
109+
IotTestBleHal_SetAdvData( eBTuuidType128, 0, NULL );
110110
IotTestBleHal_StartAdvertisement();
111111
IotTestBleHal_WaitConnection( true );
112112
}
@@ -141,6 +141,8 @@ TEST_GROUP_RUNNER( Full_BLE_Integration_Test )
141141
RUN_TEST_CASE( Full_BLE_Integration_Test, BLE_Integration_Teardown );
142142

143143
RUN_TEST_CASE( Full_BLE_Integration_Test_Advertisement, BLE_Advertise_With_16bit_ServiceUUID );
144+
RUN_TEST_CASE( Full_BLE_Integration_Test_Advertisement, BLE_Advertise_With_ManufactureData );
145+
144146
RUN_TEST_CASE( Full_BLE_Integration_Test_Connection, BLE_Send_Data_After_Disconected );
145147
RUN_TEST_CASE( Full_BLE, BLE_Free );
146148
}
@@ -150,7 +152,7 @@ TEST( Full_BLE_Integration_Test, BLE_Advertise_Without_Properties )
150152
{
151153
IotTestBleHal_BLEGAPInit();
152154
IotTestBleHal_BLEGATTInit();
153-
IotTestBleHal_SetAdvData( eBTuuidType128 );
155+
IotTestBleHal_SetAdvData( eBTuuidType128, 0, NULL );
154156
IotTestBleHal_StartAdvertisement();
155157
/* Connect for evaluate KPI for next test case. */
156158
IotTestBleHal_WaitConnection( true );
@@ -160,19 +162,48 @@ TEST( Full_BLE_Integration_Test, BLE_Advertise_Without_Properties )
160162
TEST( Full_BLE_Integration_Test_Advertisement, BLE_Advertise_With_16bit_ServiceUUID )
161163
{
162164
IotTestBleHal_SetAdvProperty();
163-
IotTestBleHal_SetAdvData( eBTuuidType16 );
165+
IotTestBleHal_SetAdvData( eBTuuidType16, 0, NULL );
164166
IotTestBleHal_StartAdvertisement();
165167
/* Simple Connect */
166168
IotTestBleHal_WaitConnection( true );
167169
/* Disconnect */
168170
IotTestBleHal_WaitConnection( false );
169171
}
170172

173+
TEST( Full_BLE_Integration_Test_Advertisement, BLE_Advertise_With_ManufactureData )
174+
{
175+
/* Manufacturer-specific Data
176+
* First two bytes are company ID (randomly select Espressif(0x02E5) for test purpose)
177+
* Next bytes are defined by the company (randomly select unit8_t 5 for test purpose)*/
178+
uint16_t usManufacturerLen = 3;
179+
uint8_t pusManufacturerData[] = { 0xE5, 0x02, 0x05 };
180+
181+
IotTestBleHal_SetAdvProperty();
182+
183+
/* Check when manufacture data length is 0, but pointer is valid */
184+
IotTestBleHal_SetAdvData( eBTuuidType128, 0, ( char * ) pusManufacturerData );
185+
IotTestBleHal_StartAdvertisement();
186+
IotTestBleHal_WaitConnection( true );
187+
IotTestBleHal_WaitConnection( false );
188+
189+
/* Check when manufacture data pointer is NULL, but length is not 0 */
190+
IotTestBleHal_SetAdvData( eBTuuidType128, usManufacturerLen, NULL );
191+
IotTestBleHal_StartAdvertisement();
192+
IotTestBleHal_WaitConnection( true );
193+
IotTestBleHal_WaitConnection( false );
194+
195+
/* Check when manufacture data length is not 0, and pointer is valid */
196+
IotTestBleHal_SetAdvData( eBTuuidType128, usManufacturerLen, ( char * ) pusManufacturerData );
197+
IotTestBleHal_StartAdvertisement();
198+
IotTestBleHal_WaitConnection( true );
199+
IotTestBleHal_WaitConnection( false );
200+
}
201+
171202
/* The sequence of set advertisement data and start advertisement can change. */
172203
TEST( Full_BLE_Integration_Test, BLE_Advertise_Before_Set_Data )
173204
{
174205
IotTestBleHal_StartAdvertisement();
175-
IotTestBleHal_SetAdvData( eBTuuidType128 );
206+
IotTestBleHal_SetAdvData( eBTuuidType128, 0, NULL );
176207
BTStatus_t xStatus = _pxBTLeAdapterInterface->pxStopAdv( _ucBLEAdapterIf );
177208
TEST_ASSERT_EQUAL( eBTStatusSuccess, xStatus );
178209
}
@@ -240,7 +271,7 @@ TEST( Full_BLE_Integration_Test, BLE_Advertise_Interval_Consistent_After_BT_Rese
240271
IotTestBleHal_BLEGATTInit();
241272
prvCreateAndStartServiceB();
242273
IotTestBleHal_SetAdvProperty();
243-
IotTestBleHal_SetAdvData( eBTuuidType128 );
274+
IotTestBleHal_SetAdvData( eBTuuidType128, 0, NULL );
244275

245276
/* Third time connection begins. Got third KPI. */
246277
IotTestBleHal_StartAdvertisement();
@@ -325,7 +356,7 @@ TEST( Full_BLE_Integration_Test_Connection, BLE_Send_Data_After_Disconected )
325356

326357
/* Advertise and Reconnect */
327358
IotTestBleHal_SetAdvProperty();
328-
IotTestBleHal_SetAdvData( eBTuuidType128 );
359+
IotTestBleHal_SetAdvData( eBTuuidType128, 0, NULL );
329360
IotTestBleHal_StartAdvertisement();
330361
IotTestBleHal_WaitConnection( true );
331362

@@ -500,7 +531,7 @@ void Advertisement_setup()
500531
GATT_setup();
501532
prvCreateAndStartServiceB();
502533
IotTestBleHal_SetAdvProperty();
503-
IotTestBleHal_SetAdvData( eBTuuidType128 );
534+
IotTestBleHal_SetAdvData( eBTuuidType128, 0, NULL );
504535

505536
/* Second time connection begins. Got second KPI. */
506537
IotTestBleHal_StartAdvertisement();

tests/bleTestsScripts/startTests_integration.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ def main():
119119
isTestSuccessFull = runTest.Advertise_With_16bit_ServiceUUID(scan_filter=scan_filter, bleAdapter=bleAdapter)
120120
runTest.submitTestResult(isTestSuccessFull, runTest.Advertise_With_16bit_ServiceUUID)
121121

122+
isTestSuccessFull = runTest.Advertise_With_Manufacture_Data(scan_filter=scan_filter, bleAdapter=bleAdapter)
123+
runTest.submitTestResult(isTestSuccessFull, runTest.Advertise_With_Manufacture_Data)
124+
122125
scan_filter.update({ "UUIDs": [runTest.DUT_UUID_128]})
123126
# default DUT_name: nimble(without set_property)
124127
bleAdapter.setDiscoveryFilter(scan_filter)

tests/bleTestsScripts/testClass.py

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ class runTest:
8080
numberOfTests = 0
8181
numberOfFailedTests = 0
8282

83+
# Manufacturer-specific Data
84+
# First two bytes are company ID (randomly select Espressif(741) for test purpose)
85+
# Next bytes are defined by the company (randomly select unit8_t 5 for test purpose)
86+
COMPANY_ID = 741
87+
MANU_DATA = 5
88+
8389
testDevice = []
8490

8591
DUT_MTU_2_STRING = "a" * (MTU_SIZE - 3)
@@ -274,7 +280,7 @@ def notification(uuid, value, flag):
274280
@staticmethod
275281
def notificationMTU2(uuid, value, flag):
276282
if (uuid == runTest.DUT_NOTIFY_CHAR_UUID) and (flag == "notify"):
277-
return value;
283+
return value
278284

279285
@staticmethod
280286
def notificationOnCharE(uuid, value, flag):
@@ -438,6 +444,23 @@ def advertisement(testDevice, DUT_UUID=None):
438444

439445
return True
440446

447+
@staticmethod
448+
def get_manufacture_data(testDevice, DUT_UUID=None):
449+
manufacture_data_dict = bleAdapter.getPropertie(testDevice, "ManufacturerData")
450+
451+
# If manufacture data doesn't exist, return None
452+
if( manufacture_data_dict == None ):
453+
print("No Manufacture Data")
454+
sys.stdout.flush()
455+
return None
456+
457+
# If manufacture data exists, return manufacture data
458+
else:
459+
print( "Manufacturer Specific Data: " + str(manufacture_data_dict.items()) )
460+
sys.stdout.flush()
461+
manufacture_data = manufacture_data_dict[runTest.COMPANY_ID]
462+
return manufacture_data
463+
441464
@staticmethod
442465
def _advertisement_start(scan_filter, UUID, discoveryEvent_Cb, bleAdapter):
443466
scan_filter.update({ "UUIDs": [UUID]})
@@ -483,6 +506,53 @@ def Advertise_Without_Properties(scan_filter,
483506
runTest.DUT_NAME = DUT_NAME_ORIGINAL
484507
return True
485508

509+
@staticmethod
510+
def Advertise_With_Manufacture_Data(scan_filter,
511+
bleAdapter):
512+
isTestSuccessFull = True
513+
514+
# Check when manufacture data length is 0, but pointer is valid
515+
runTest._advertisement_start(scan_filter=scan_filter,
516+
UUID=runTest.DUT_UUID_128,
517+
discoveryEvent_Cb=runTest.discoveryEventCb,
518+
bleAdapter=bleAdapter)
519+
manufacture_data = runTest.get_manufacture_data(runTest.testDevice)
520+
if manufacture_data != None:
521+
isTestSuccessFull = False
522+
runTest._simple_connect()
523+
runTest.stopAdvertisement(scan_filter)
524+
isTestSuccessFull &= bleAdapter.disconnect()
525+
testutils.removeBondedDevices()
526+
527+
# Check when manufacture data pointer is NULL, but length is not 0
528+
runTest._advertisement_start(scan_filter=scan_filter,
529+
UUID=runTest.DUT_UUID_128,
530+
discoveryEvent_Cb=runTest.discoveryEventCb,
531+
bleAdapter=bleAdapter)
532+
manufacture_data = runTest.get_manufacture_data(runTest.testDevice)
533+
if manufacture_data != None:
534+
isTestSuccessFull = False
535+
runTest._simple_connect()
536+
runTest.stopAdvertisement(scan_filter)
537+
isTestSuccessFull &= bleAdapter.disconnect()
538+
testutils.removeBondedDevices()
539+
540+
# Check when manufacture data length is not 0, and pointer is valid
541+
runTest._advertisement_start(scan_filter=scan_filter,
542+
UUID=runTest.DUT_UUID_128,
543+
discoveryEvent_Cb=runTest.discoveryEventCb,
544+
bleAdapter=bleAdapter)
545+
manufacture_data = runTest.get_manufacture_data(runTest.testDevice)
546+
for data in manufacture_data:
547+
if data != runTest.MANU_DATA:
548+
isTestSuccessFull = False
549+
runTest._simple_connect()
550+
runTest.stopAdvertisement(scan_filter)
551+
isTestSuccessFull &= bleAdapter.disconnect()
552+
testutils.removeBondedDevices()
553+
554+
return isTestSuccessFull
555+
486556
@staticmethod
487557
def Advertise_With_16bit_ServiceUUID(scan_filter,
488558
bleAdapter):
@@ -557,6 +627,7 @@ def submitTestResult(isSuccessfull, testMethod):
557627
runTest.stopAdvertisement: "_stopAdvertisement",
558628
runTest.Advertise_Without_Properties: "_Advertise_Without_Properties",
559629
runTest.Advertise_With_16bit_ServiceUUID: "_Advertise_With_16bit_ServiceUUID",
630+
runTest.Advertise_With_Manufacture_Data: "_Advertise_With_Manufacture_Data",
560631
# runTest.Advertise_Interval_Consistent_After_BT_Reset: "_Advertise_Interval_Consistent_After_BT_Reset",
561632
runTest.Write_Notification_Size_Greater_Than_MTU_3: "_Write_Notification_Size_Greater_Than_MTU_3"
562633
}

0 commit comments

Comments
 (0)