mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-03-29 22:20:37 +00:00
mesh: validate lower transport pdu
This commit is contained in:
parent
77eae4789e
commit
7e9790c014
@ -16,6 +16,18 @@ void adv_bearer_register_for_mesh_message(btstack_packet_handler_t packet_handle
|
||||
void adv_bearer_request_can_send_now_for_mesh_message(void){}
|
||||
void adv_bearer_send_mesh_message(const uint8_t * network_pdu, uint16_t size){}
|
||||
|
||||
void CHECK_EQUAL_ARRAY(uint8_t * expected, uint8_t * actual, int size){
|
||||
int i;
|
||||
for (i=0; i<size; i++){
|
||||
if (expected[i] != actual[i]) {
|
||||
printf("offset %u wrong\n", i);
|
||||
printf("expected: "); printf_hexdump(expected, size);
|
||||
printf("actual: "); printf_hexdump(actual, size);
|
||||
}
|
||||
BYTES_EQUAL(expected[i], actual[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static int scan_hex_byte(const char * byte_string){
|
||||
int upper_nibble = nibble_for_char(*byte_string++);
|
||||
if (upper_nibble < 0) return -1;
|
||||
@ -62,7 +74,7 @@ static void load_provisioning_data_test_message(void){
|
||||
btstack_parse_hex("0953fa93e7caac9638f58820220a398e", 16, provisioning_data.encryption_key);
|
||||
btstack_parse_hex("8b84eedec100067d670971dd2aa700cf", 16, provisioning_data.privacy_key);
|
||||
mesh_network_key_list_add_from_provisioning_data(&provisioning_data);
|
||||
#if 0
|
||||
|
||||
uint8_t application_key[16];
|
||||
btstack_parse_hex("63964771734fbd76e3b40519d1d94a48", 16, application_key);
|
||||
mesh_application_key_set( 0, 0x26, application_key);
|
||||
@ -70,14 +82,11 @@ static void load_provisioning_data_test_message(void){
|
||||
uint8_t device_key[16];
|
||||
btstack_parse_hex("9d6dd0e96eb25dc19a40ed9914f8f03f", 16, device_key);
|
||||
mesh_transport_set_device_key(device_key);
|
||||
#endif
|
||||
}
|
||||
|
||||
static mesh_network_pdu_t * received_network_pdu;
|
||||
|
||||
#if 0
|
||||
static void mesh_lower_transport_received_mesage(mesh_network_callback_type_t callback_type, mesh_network_pdu_t * network_pdu){
|
||||
printf("mesh_lower_transport_received_mesage, type %u\n", callback_type);
|
||||
static void test_lower_transport_callback_handler(mesh_network_callback_type_t callback_type, mesh_network_pdu_t * network_pdu){
|
||||
switch (callback_type){
|
||||
case MESH_NETWORK_PDU_RECEIVED:
|
||||
received_network_pdu = network_pdu;
|
||||
@ -88,7 +97,6 @@ static void mesh_lower_transport_received_mesage(mesh_network_callback_type_t ca
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
TEST_GROUP(MessageTest){
|
||||
void setup(void){
|
||||
@ -96,28 +104,43 @@ TEST_GROUP(MessageTest){
|
||||
btstack_crypto_init();
|
||||
load_provisioning_data_test_message();
|
||||
mesh_network_init();
|
||||
mesh_network_set_higher_layer_handler(&mesh_lower_transport_received_mesage);
|
||||
mesh_network_set_higher_layer_handler(&test_lower_transport_callback_handler);
|
||||
received_network_pdu = NULL;
|
||||
}
|
||||
};
|
||||
|
||||
static uint8_t transport_pdu_data[32];
|
||||
static uint8_t transport_pdu_data[64];
|
||||
static uint16_t transport_pdu_len;
|
||||
static const char * transport_pdu_string;
|
||||
|
||||
static uint8_t test_network_pdu_len;
|
||||
static uint8_t test_network_pdu_data[29];
|
||||
static const char * test_network_pdu_string;
|
||||
static const char * test_network_pdu_string;
|
||||
|
||||
TEST(MessageTest, Test1){
|
||||
uint8_t test_network_pdu_data[29];
|
||||
|
||||
// Network PDU 1
|
||||
test_network_pdu_string = "68eca487516765b5e5bfdacbaf6cb7fb6bff871f035444ce83a670df";
|
||||
test_network_pdu_len = strlen(test_network_pdu_string) / 2;
|
||||
btstack_parse_hex(test_network_pdu_string, test_network_pdu_len, test_network_pdu_data);
|
||||
|
||||
mesh_network_received_message(test_network_pdu_data, test_network_pdu_len);
|
||||
|
||||
// Expected Lower Transport PDU
|
||||
transport_pdu_string = "034b50057e400000010000";
|
||||
transport_pdu_len = strlen(transport_pdu_string) / 2;
|
||||
btstack_parse_hex(transport_pdu_string, transport_pdu_len, transport_pdu_data);
|
||||
|
||||
//
|
||||
while (received_network_pdu == NULL) {
|
||||
mock_process_hci_cmd();
|
||||
}
|
||||
// TODO: check
|
||||
|
||||
uint8_t * lower_transport_pdu = mesh_network_pdu_data(received_network_pdu);
|
||||
uint8_t lower_transport_pdu_len = mesh_network_pdu_len(received_network_pdu);
|
||||
|
||||
CHECK_EQUAL( transport_pdu_len, lower_transport_pdu_len);
|
||||
CHECK_EQUAL_ARRAY(transport_pdu_data, lower_transport_pdu, transport_pdu_len);
|
||||
}
|
||||
|
||||
TEST(MessageTest, Test2){
|
||||
|
Loading…
x
Reference in New Issue
Block a user