184242f88SMatthias Ringwald #include <stdio.h> 284242f88SMatthias Ringwald 384242f88SMatthias Ringwald #include "CppUTest/TestHarness.h" 484242f88SMatthias Ringwald #include "CppUTest/CommandLineTestRunner.h" 584242f88SMatthias Ringwald 684242f88SMatthias Ringwald #include "bluetooth_data_types.h" 784242f88SMatthias Ringwald #include "bluetooth_gatt.h" 8aaa248aaSMatthias Ringwald #include "btstack_debug.h" 984242f88SMatthias Ringwald #include "btstack_memory.h" 1084242f88SMatthias Ringwald #include "btstack_util.h" 1184242f88SMatthias Ringwald #include "mesh/adv_bearer.h" 1284242f88SMatthias Ringwald #include "mesh/gatt_bearer.h" 1363197f45SMatthias Ringwald #include "mesh/mesh_access.h" 1484242f88SMatthias Ringwald #include "mesh/mesh_crypto.h" 1584242f88SMatthias Ringwald #include "mesh/mesh_foundation.h" 1684242f88SMatthias Ringwald #include "mesh/mesh_iv_index_seq_number.h" 1784242f88SMatthias Ringwald #include "mesh/mesh_lower_transport.h" 1884242f88SMatthias Ringwald #include "mesh/mesh_network.h" 1984242f88SMatthias Ringwald #include "mesh/mesh_upper_transport.h" 2084242f88SMatthias Ringwald #include "mesh/provisioning.h" 2184242f88SMatthias Ringwald #include "mesh/mesh_peer.h" 2284242f88SMatthias Ringwald 2384242f88SMatthias Ringwald extern "C" int mock_process_hci_cmd(void); 2484242f88SMatthias Ringwald 2584242f88SMatthias Ringwald static mesh_network_pdu_t * received_network_pdu; 2684242f88SMatthias Ringwald static mesh_network_pdu_t * received_proxy_pdu; 2784242f88SMatthias Ringwald 2884242f88SMatthias Ringwald static uint8_t outgoing_gatt_network_pdu_data[29]; 2984242f88SMatthias Ringwald static uint8_t outgoing_gatt_network_pdu_len; 3084242f88SMatthias Ringwald 3184242f88SMatthias Ringwald static uint8_t outgoing_adv_network_pdu_data[29]; 3284242f88SMatthias Ringwald static uint8_t outgoing_adv_network_pdu_len; 3384242f88SMatthias Ringwald 3484242f88SMatthias Ringwald static uint8_t recv_upper_transport_pdu_data[100]; 3584242f88SMatthias Ringwald static uint16_t recv_upper_transport_pdu_len; 3684242f88SMatthias Ringwald 3784242f88SMatthias Ringwald #ifdef ENABLE_MESH_ADV_BEARER 3884242f88SMatthias Ringwald static btstack_packet_handler_t adv_packet_handler; 3984242f88SMatthias Ringwald void adv_bearer_register_for_network_pdu(btstack_packet_handler_t packet_handler){ 4084242f88SMatthias Ringwald adv_packet_handler = packet_handler; 4184242f88SMatthias Ringwald } 4284242f88SMatthias Ringwald void adv_bearer_request_can_send_now_for_network_pdu(void){ 4384242f88SMatthias Ringwald // simulate can send now 4484242f88SMatthias Ringwald uint8_t event[3]; 4584242f88SMatthias Ringwald event[0] = HCI_EVENT_MESH_META; 4684242f88SMatthias Ringwald event[1] = 1; 4784242f88SMatthias Ringwald event[2] = MESH_SUBEVENT_CAN_SEND_NOW; 4884242f88SMatthias Ringwald (*adv_packet_handler)(HCI_EVENT_PACKET, 0, &event[0], sizeof(event)); 4984242f88SMatthias Ringwald } 5084242f88SMatthias Ringwald void adv_bearer_send_network_pdu(const uint8_t * network_pdu, uint16_t size, uint8_t count, uint16_t interval){ 5184242f88SMatthias Ringwald (void) count; 5284242f88SMatthias Ringwald (void) interval; 5384242f88SMatthias Ringwald // printf("ADV Network PDU: "); 5484242f88SMatthias Ringwald // printf_hexdump(network_pdu, size); 5584242f88SMatthias Ringwald memcpy(outgoing_adv_network_pdu_data, network_pdu, size); 5684242f88SMatthias Ringwald outgoing_adv_network_pdu_len = size; 5784242f88SMatthias Ringwald } 5884242f88SMatthias Ringwald static void adv_bearer_emit_sent(void){ 5984242f88SMatthias Ringwald uint8_t event[3]; 6084242f88SMatthias Ringwald event[0] = HCI_EVENT_MESH_META; 6184242f88SMatthias Ringwald event[1] = 1; 6284242f88SMatthias Ringwald event[2] = MESH_SUBEVENT_MESSAGE_SENT; 6384242f88SMatthias Ringwald (*adv_packet_handler)(HCI_EVENT_PACKET, 0, &event[0], sizeof(event)); 6484242f88SMatthias Ringwald } 6584242f88SMatthias Ringwald #endif 6684242f88SMatthias Ringwald 6784242f88SMatthias Ringwald #ifdef ENABLE_MESH_GATT_BEARER 6884242f88SMatthias Ringwald static btstack_packet_handler_t gatt_packet_handler; 6984242f88SMatthias Ringwald void gatt_bearer_register_for_network_pdu(btstack_packet_handler_t packet_handler){ 7084242f88SMatthias Ringwald gatt_packet_handler = packet_handler; 7184242f88SMatthias Ringwald } 7284242f88SMatthias Ringwald void gatt_bearer_register_for_mesh_proxy_configuration(btstack_packet_handler_t packet_handler){ 7384242f88SMatthias Ringwald } 7484242f88SMatthias Ringwald void gatt_bearer_request_can_send_now_for_network_pdu(void){ 7584242f88SMatthias Ringwald // simulate can send now 7684242f88SMatthias Ringwald uint8_t event[3]; 7784242f88SMatthias Ringwald event[0] = HCI_EVENT_MESH_META; 7884242f88SMatthias Ringwald event[1] = 1; 7984242f88SMatthias Ringwald event[2] = MESH_SUBEVENT_CAN_SEND_NOW; 8084242f88SMatthias Ringwald (*gatt_packet_handler)(HCI_EVENT_PACKET, 0, &event[0], sizeof(event)); 8184242f88SMatthias Ringwald } 8284242f88SMatthias Ringwald void gatt_bearer_send_network_pdu(const uint8_t * network_pdu, uint16_t size){ 8384242f88SMatthias Ringwald // printf("ADV Network PDU: "); 8484242f88SMatthias Ringwald // printf_hexdump(network_pdu, size); 8584242f88SMatthias Ringwald memcpy(outgoing_gatt_network_pdu_data, network_pdu, size); 8684242f88SMatthias Ringwald outgoing_gatt_network_pdu_len = size; 8784242f88SMatthias Ringwald } 8884242f88SMatthias Ringwald static void gatt_bearer_emit_sent(void){ 8984242f88SMatthias Ringwald uint8_t event[3]; 9084242f88SMatthias Ringwald event[0] = HCI_EVENT_MESH_META; 9184242f88SMatthias Ringwald event[1] = 1; 9284242f88SMatthias Ringwald event[2] = MESH_SUBEVENT_MESSAGE_SENT; 9384242f88SMatthias Ringwald (*gatt_packet_handler)(HCI_EVENT_PACKET, 0, &event[0], sizeof(event)); 9484242f88SMatthias Ringwald } 9584242f88SMatthias Ringwald static void gatt_bearer_emit_connected(void){ 9684242f88SMatthias Ringwald uint8_t event[5]; 9784242f88SMatthias Ringwald event[0] = HCI_EVENT_MESH_META; 9884242f88SMatthias Ringwald event[1] = 1; 9984242f88SMatthias Ringwald event[2] = MESH_SUBEVENT_PROXY_CONNECTED; 10084242f88SMatthias Ringwald little_endian_store_16(event, 3, 0x1234); 10184242f88SMatthias Ringwald (*gatt_packet_handler)(HCI_EVENT_PACKET, 0, &event[0], sizeof(event)); 10284242f88SMatthias Ringwald } 10384242f88SMatthias Ringwald #endif 10484242f88SMatthias Ringwald 10563197f45SMatthias Ringwald // copy from mesh_message.c for now 10663197f45SMatthias Ringwald uint16_t mesh_pdu_dst(mesh_pdu_t * pdu){ 10763197f45SMatthias Ringwald switch (pdu->pdu_type){ 108e4121a34SMatthias Ringwald case MESH_PDU_TYPE_UNSEGMENTED: 10963197f45SMatthias Ringwald case MESH_PDU_TYPE_NETWORK: 1108ec600ffSMatthias Ringwald case MESH_PDU_TYPE_UPPER_UNSEGMENTED_CONTROL: 11163197f45SMatthias Ringwald return mesh_network_dst((mesh_network_pdu_t *) pdu); 1122ddfd9e2SMatthias Ringwald case MESH_PDU_TYPE_ACCESS: { 1132ddfd9e2SMatthias Ringwald return ((mesh_access_pdu_t *) pdu)->dst; 1142ddfd9e2SMatthias Ringwald } 115242605faSMatthias Ringwald case MESH_PDU_TYPE_UPPER_SEGMENTED_ACCESS: 1161b51af65SMatthias Ringwald case MESH_PDU_TYPE_UPPER_UNSEGMENTED_ACCESS: 117242605faSMatthias Ringwald return ((mesh_upper_transport_pdu_t *) pdu)->dst; 11863197f45SMatthias Ringwald default: 1197a0b7488SMatthias Ringwald btstack_assert(false); 12063197f45SMatthias Ringwald return MESH_ADDRESS_UNSASSIGNED; 12163197f45SMatthias Ringwald } 12263197f45SMatthias Ringwald } 12363197f45SMatthias Ringwald uint16_t mesh_pdu_ctl(mesh_pdu_t * pdu){ 12463197f45SMatthias Ringwald switch (pdu->pdu_type){ 12563197f45SMatthias Ringwald case MESH_PDU_TYPE_NETWORK: 1268ec600ffSMatthias Ringwald case MESH_PDU_TYPE_UPPER_UNSEGMENTED_CONTROL: 12763197f45SMatthias Ringwald return mesh_network_control((mesh_network_pdu_t *) pdu); 1282ddfd9e2SMatthias Ringwald case MESH_PDU_TYPE_ACCESS: { 1292ddfd9e2SMatthias Ringwald return ((mesh_access_pdu_t *) pdu)->ctl_ttl >> 7; 1302ddfd9e2SMatthias Ringwald } 13163197f45SMatthias Ringwald default: 1327a0b7488SMatthias Ringwald btstack_assert(false); 13363197f45SMatthias Ringwald return 0; 13463197f45SMatthias Ringwald } 13563197f45SMatthias Ringwald } 13663197f45SMatthias Ringwald 13784242f88SMatthias Ringwald void CHECK_EQUAL_ARRAY(uint8_t * expected, uint8_t * actual, int size){ 13884242f88SMatthias Ringwald int i; 13984242f88SMatthias Ringwald for (i=0; i<size; i++){ 14084242f88SMatthias Ringwald if (expected[i] != actual[i]) { 14184242f88SMatthias Ringwald printf("offset %u wrong\n", i); 14284242f88SMatthias Ringwald printf("expected: "); printf_hexdump(expected, size); 14384242f88SMatthias Ringwald printf("actual: "); printf_hexdump(actual, size); 14484242f88SMatthias Ringwald } 14584242f88SMatthias Ringwald BYTES_EQUAL(expected[i], actual[i]); 14684242f88SMatthias Ringwald } 14784242f88SMatthias Ringwald } 14884242f88SMatthias Ringwald 14984242f88SMatthias Ringwald static int scan_hex_byte(const char * byte_string){ 15084242f88SMatthias Ringwald int upper_nibble = nibble_for_char(*byte_string++); 15184242f88SMatthias Ringwald if (upper_nibble < 0) return -1; 15284242f88SMatthias Ringwald int lower_nibble = nibble_for_char(*byte_string); 15384242f88SMatthias Ringwald if (lower_nibble < 0) return -1; 15484242f88SMatthias Ringwald return (upper_nibble << 4) | lower_nibble; 15584242f88SMatthias Ringwald } 15684242f88SMatthias Ringwald 15784242f88SMatthias Ringwald static int btstack_parse_hex(const char * string, uint16_t len, uint8_t * buffer){ 15884242f88SMatthias Ringwald int i; 15984242f88SMatthias Ringwald for (i = 0; i < len; i++) { 16084242f88SMatthias Ringwald int single_byte = scan_hex_byte(string); 16184242f88SMatthias Ringwald if (single_byte < 0) return 0; 16284242f88SMatthias Ringwald string += 2; 16384242f88SMatthias Ringwald buffer[i] = (uint8_t)single_byte; 16484242f88SMatthias Ringwald // don't check seperator after last byte 16584242f88SMatthias Ringwald if (i == len - 1) { 16684242f88SMatthias Ringwald return 1; 16784242f88SMatthias Ringwald } 16884242f88SMatthias Ringwald // optional seperator 16984242f88SMatthias Ringwald char separator = *string; 17084242f88SMatthias Ringwald if (separator == ':' && separator == '-' && separator == ' ') { 17184242f88SMatthias Ringwald string++; 17284242f88SMatthias Ringwald } 17384242f88SMatthias Ringwald } 17484242f88SMatthias Ringwald return 1; 17584242f88SMatthias Ringwald } 17684242f88SMatthias Ringwald 17784242f88SMatthias Ringwald #if 0 17884242f88SMatthias Ringwald static void btstack_print_hex(const uint8_t * data, uint16_t len, char separator){ 17984242f88SMatthias Ringwald int i; 18084242f88SMatthias Ringwald for (i=0;i<len;i++){ 18184242f88SMatthias Ringwald printf("%02x", data[i]); 18284242f88SMatthias Ringwald if (separator){ 18384242f88SMatthias Ringwald printf("%c", separator); 18484242f88SMatthias Ringwald } 18584242f88SMatthias Ringwald } 18684242f88SMatthias Ringwald printf("\n"); 18784242f88SMatthias Ringwald } 18884242f88SMatthias Ringwald #endif 18984242f88SMatthias Ringwald 19084242f88SMatthias Ringwald static mesh_transport_key_t test_application_key; 19184242f88SMatthias Ringwald static void mesh_application_key_set(uint16_t netkey_index, uint16_t appkey_index, uint8_t aid, const uint8_t *application_key) { 19284242f88SMatthias Ringwald test_application_key.netkey_index = netkey_index; 19384242f88SMatthias Ringwald test_application_key.appkey_index = appkey_index; 19484242f88SMatthias Ringwald test_application_key.aid = aid; 19584242f88SMatthias Ringwald test_application_key.akf = 1; 19684242f88SMatthias Ringwald memcpy(test_application_key.key, application_key, 16); 19784242f88SMatthias Ringwald mesh_transport_key_add(&test_application_key); 19884242f88SMatthias Ringwald } 19984242f88SMatthias Ringwald 20084242f88SMatthias Ringwald static void load_network_key_nid_68(void){ 20184242f88SMatthias Ringwald mesh_network_key_t * network_key = btstack_memory_mesh_network_key_get(); 20284242f88SMatthias Ringwald network_key->nid = 0x68; 20384242f88SMatthias Ringwald btstack_parse_hex("0953fa93e7caac9638f58820220a398e", 16, network_key->encryption_key); 20484242f88SMatthias Ringwald btstack_parse_hex("8b84eedec100067d670971dd2aa700cf", 16, network_key->privacy_key); 20584242f88SMatthias Ringwald mesh_network_key_add(network_key); 20684242f88SMatthias Ringwald mesh_subnet_setup_for_netkey_index(network_key->netkey_index); 20784242f88SMatthias Ringwald } 20884242f88SMatthias Ringwald 20984242f88SMatthias Ringwald static void load_network_key_nid_5e(void){ 21084242f88SMatthias Ringwald mesh_network_key_t * network_key = btstack_memory_mesh_network_key_get(); 21184242f88SMatthias Ringwald network_key->nid = 0x5e; 21284242f88SMatthias Ringwald btstack_parse_hex("be635105434859f484fc798e043ce40e", 16, network_key->encryption_key); 21384242f88SMatthias Ringwald btstack_parse_hex("5d396d4b54d3cbafe943e051fe9a4eb8", 16, network_key->privacy_key); 21484242f88SMatthias Ringwald mesh_network_key_add(network_key); 21584242f88SMatthias Ringwald mesh_subnet_setup_for_netkey_index(network_key->netkey_index); 21684242f88SMatthias Ringwald } 21784242f88SMatthias Ringwald 21884242f88SMatthias Ringwald static void load_network_key_nid_10(void){ 21984242f88SMatthias Ringwald mesh_network_key_t * network_key = btstack_memory_mesh_network_key_get(); 22084242f88SMatthias Ringwald network_key->nid = 0x10; 22184242f88SMatthias Ringwald btstack_parse_hex("3a4fe84a6cc2c6a766ea93f1084d4039", 16, network_key->encryption_key); 22284242f88SMatthias Ringwald btstack_parse_hex("f695fcce709ccface4d8b7a1e6e39d25", 16, network_key->privacy_key); 22384242f88SMatthias Ringwald mesh_network_key_add(network_key); 22484242f88SMatthias Ringwald mesh_subnet_setup_for_netkey_index(network_key->netkey_index); 22584242f88SMatthias Ringwald } 22684242f88SMatthias Ringwald 22784242f88SMatthias Ringwald static void load_provisioning_data_test_message(void){ 22884242f88SMatthias Ringwald uint8_t application_key[16]; 22984242f88SMatthias Ringwald btstack_parse_hex("63964771734fbd76e3b40519d1d94a48", 16, application_key); 23084242f88SMatthias Ringwald mesh_application_key_set( 0, 0, 0x26, application_key); 23184242f88SMatthias Ringwald 23284242f88SMatthias Ringwald uint8_t device_key[16]; 23384242f88SMatthias Ringwald btstack_parse_hex("9d6dd0e96eb25dc19a40ed9914f8f03f", 16, device_key); 23484242f88SMatthias Ringwald mesh_transport_set_device_key(device_key); 23584242f88SMatthias Ringwald } 23684242f88SMatthias Ringwald 23784242f88SMatthias Ringwald static void test_lower_transport_callback_handler(mesh_network_callback_type_t callback_type, mesh_network_pdu_t * network_pdu){ 23884242f88SMatthias Ringwald switch (callback_type){ 23984242f88SMatthias Ringwald case MESH_NETWORK_PDU_RECEIVED: 24084242f88SMatthias Ringwald printf("test MESH_NETWORK_PDU_RECEIVED\n"); 24184242f88SMatthias Ringwald received_network_pdu = network_pdu; 24284242f88SMatthias Ringwald break; 24384242f88SMatthias Ringwald case MESH_NETWORK_PDU_SENT: 24484242f88SMatthias Ringwald printf("test MESH_NETWORK_PDU_SENT\n"); 24584242f88SMatthias Ringwald mesh_lower_transport_received_message(MESH_NETWORK_PDU_SENT, network_pdu); 24684242f88SMatthias Ringwald break; 24784242f88SMatthias Ringwald default: 24884242f88SMatthias Ringwald break; 24984242f88SMatthias Ringwald } 25084242f88SMatthias Ringwald } 25184242f88SMatthias Ringwald 25284242f88SMatthias Ringwald static void test_proxy_server_callback_handler(mesh_network_callback_type_t callback_type, mesh_network_pdu_t * network_pdu){ 25384242f88SMatthias Ringwald switch (callback_type){ 25484242f88SMatthias Ringwald case MESH_NETWORK_PDU_RECEIVED: 25584242f88SMatthias Ringwald printf("test MESH_PROXY_PDU_RECEIVED\n"); 25684242f88SMatthias Ringwald received_proxy_pdu = network_pdu; 25784242f88SMatthias Ringwald break; 25884242f88SMatthias Ringwald case MESH_NETWORK_PDU_SENT: 25984242f88SMatthias Ringwald // printf("test MESH_PROXY_PDU_SENT\n"); 26084242f88SMatthias Ringwald // mesh_lower_transport_received_mesage(MESH_NETWORK_PDU_SENT, network_pdu); 26184242f88SMatthias Ringwald break; 2621aa2a11eSMatthias Ringwald case MESH_NETWORK_PDU_ENCRYPTED: 2631aa2a11eSMatthias Ringwald printf("test MESH_NETWORK_PDU_ENCRYPTED\n"); 2641aa2a11eSMatthias Ringwald received_proxy_pdu = network_pdu; 2651aa2a11eSMatthias Ringwald break; 26684242f88SMatthias Ringwald default: 26784242f88SMatthias Ringwald break; 26884242f88SMatthias Ringwald } 26984242f88SMatthias Ringwald } 27084242f88SMatthias Ringwald 271404d2482SMatthias Ringwald static void test_upper_transport_access_message_handler(mesh_transport_callback_type_t callback_type, mesh_transport_status_t status, mesh_pdu_t * pdu){ 2727a0b7488SMatthias Ringwald 2737a0b7488SMatthias Ringwald // ignore pdu sent 2747a0b7488SMatthias Ringwald if (callback_type == MESH_TRANSPORT_PDU_SENT) return; 2757a0b7488SMatthias Ringwald 2767a0b7488SMatthias Ringwald // process pdu received 277160d2809SMatthias Ringwald mesh_access_pdu_t * access_pdu; 27884242f88SMatthias Ringwald mesh_network_pdu_t * network_pdu; 279a4bbc09dSMatthias Ringwald mesh_segmented_pdu_t * message_pdu; 2807a0b7488SMatthias Ringwald 28184242f88SMatthias Ringwald switch(pdu->pdu_type){ 282160d2809SMatthias Ringwald case MESH_PDU_TYPE_ACCESS: 283160d2809SMatthias Ringwald access_pdu = (mesh_access_pdu_t *) pdu; 284160d2809SMatthias Ringwald printf("test access handler MESH_PDU_TYPE_ACCESS received\n"); 285160d2809SMatthias Ringwald recv_upper_transport_pdu_len = access_pdu->len; 286160d2809SMatthias Ringwald memcpy(recv_upper_transport_pdu_data, access_pdu->data, recv_upper_transport_pdu_len); 28784242f88SMatthias Ringwald mesh_upper_transport_message_processed_by_higher_layer(pdu); 28884242f88SMatthias Ringwald break; 289a4bbc09dSMatthias Ringwald case MESH_PDU_TYPE_SEGMENTED: 290a4bbc09dSMatthias Ringwald message_pdu = (mesh_segmented_pdu_t *) pdu; 291a4bbc09dSMatthias Ringwald printf("test access handler MESH_PDU_TYPE_SEGMENTED received\n"); 292aaa248aaSMatthias Ringwald network_pdu = (mesh_network_pdu_t *) btstack_linked_list_get_first_item(&message_pdu->segments); 29384242f88SMatthias Ringwald recv_upper_transport_pdu_len = mesh_network_pdu_len(network_pdu) - 1; 29484242f88SMatthias Ringwald memcpy(recv_upper_transport_pdu_data, mesh_network_pdu_data(network_pdu) + 1, recv_upper_transport_pdu_len); 29584242f88SMatthias Ringwald mesh_upper_transport_message_processed_by_higher_layer(pdu); 29684242f88SMatthias Ringwald break; 29784242f88SMatthias Ringwald default: 298160d2809SMatthias Ringwald btstack_assert(0); 29984242f88SMatthias Ringwald break; 30084242f88SMatthias Ringwald } 30184242f88SMatthias Ringwald } 30284242f88SMatthias Ringwald 303404d2482SMatthias Ringwald static void test_upper_transport_control_message_handler(mesh_transport_callback_type_t callback_type, mesh_transport_status_t status, mesh_pdu_t * pdu){ 3047a0b7488SMatthias Ringwald // ignore pdu sent 3057a0b7488SMatthias Ringwald if (callback_type == MESH_TRANSPORT_PDU_SENT) return; 3067a0b7488SMatthias Ringwald 3077a0b7488SMatthias Ringwald // process pdu received 3085131e195SMatthias Ringwald mesh_control_pdu_t * control_pdu; 30984242f88SMatthias Ringwald switch(pdu->pdu_type){ 3105131e195SMatthias Ringwald case MESH_PDU_TYPE_CONTROL: 3115131e195SMatthias Ringwald control_pdu = (mesh_control_pdu_t *) pdu; 3125131e195SMatthias Ringwald printf("test MESH_PDU_TYPE_CONTROL\n"); 3135131e195SMatthias Ringwald recv_upper_transport_pdu_len = control_pdu->len + 1; 3145131e195SMatthias Ringwald recv_upper_transport_pdu_data[0] = control_pdu->akf_aid_control; 3155131e195SMatthias Ringwald memcpy(&recv_upper_transport_pdu_data[1], control_pdu->data, control_pdu->len); 31684242f88SMatthias Ringwald mesh_upper_transport_message_processed_by_higher_layer(pdu); 31784242f88SMatthias Ringwald break; 31884242f88SMatthias Ringwald default: 319160d2809SMatthias Ringwald btstack_assert(0); 32084242f88SMatthias Ringwald break; 32184242f88SMatthias Ringwald } 32284242f88SMatthias Ringwald } 32384242f88SMatthias Ringwald 32484242f88SMatthias Ringwald TEST_GROUP(MessageTest){ 32584242f88SMatthias Ringwald void setup(void){ 32684242f88SMatthias Ringwald btstack_memory_init(); 32784242f88SMatthias Ringwald btstack_crypto_init(); 32884242f88SMatthias Ringwald load_provisioning_data_test_message(); 32984242f88SMatthias Ringwald mesh_network_init(); 33084242f88SMatthias Ringwald mesh_lower_transport_init(); 33184242f88SMatthias Ringwald mesh_upper_transport_init(); 33284242f88SMatthias Ringwald mesh_network_key_init(); 33384242f88SMatthias Ringwald // intercept messages between network and lower layer 33484242f88SMatthias Ringwald mesh_network_set_higher_layer_handler(&test_lower_transport_callback_handler); 33584242f88SMatthias Ringwald mesh_network_set_proxy_message_handler(&test_proxy_server_callback_handler); 33684242f88SMatthias Ringwald // register to receive upper transport messages 33784242f88SMatthias Ringwald mesh_upper_transport_register_access_message_handler(&test_upper_transport_access_message_handler); 33884242f88SMatthias Ringwald mesh_upper_transport_register_control_message_handler(&test_upper_transport_control_message_handler); 33984242f88SMatthias Ringwald mesh_seq_auth_reset(); 34084242f88SMatthias Ringwald #ifdef ENABLE_MESH_GATT_BEARER 34184242f88SMatthias Ringwald mesh_foundation_gatt_proxy_set(1); 34284242f88SMatthias Ringwald gatt_bearer_emit_connected(); 34384242f88SMatthias Ringwald #endif 34484242f88SMatthias Ringwald outgoing_gatt_network_pdu_len = 0; 34584242f88SMatthias Ringwald outgoing_adv_network_pdu_len = 0; 34684242f88SMatthias Ringwald received_network_pdu = NULL; 34784242f88SMatthias Ringwald recv_upper_transport_pdu_len =0; 34884242f88SMatthias Ringwald } 34984242f88SMatthias Ringwald void teardown(void){ 35084242f88SMatthias Ringwald // printf("-- teardown start --\n\n"); 35184242f88SMatthias Ringwald btstack_crypto_reset(); 35284242f88SMatthias Ringwald mesh_network_reset(); 35384242f88SMatthias Ringwald mesh_lower_transport_reset(); 35484242f88SMatthias Ringwald mesh_upper_transport_dump(); 35584242f88SMatthias Ringwald mesh_upper_transport_reset(); 35684242f88SMatthias Ringwald // mesh_network_dump(); 35784242f88SMatthias Ringwald // mesh_transport_dump(); 35884242f88SMatthias Ringwald printf("-- teardown complete --\n\n"); 35984242f88SMatthias Ringwald } 36084242f88SMatthias Ringwald }; 36184242f88SMatthias Ringwald 36284242f88SMatthias Ringwald static uint8_t transport_pdu_data[64]; 36384242f88SMatthias Ringwald static uint16_t transport_pdu_len; 36484242f88SMatthias Ringwald 36584242f88SMatthias Ringwald static uint8_t test_network_pdu_len; 36684242f88SMatthias Ringwald static uint8_t test_network_pdu_data[29]; 36784242f88SMatthias Ringwald 36884242f88SMatthias Ringwald void test_receive_network_pdus(int count, char ** network_pdus, char ** lower_transport_pdus, char * access_pdu){ 36984242f88SMatthias Ringwald int i; 37084242f88SMatthias Ringwald for (i=0;i<count;i++){ 37184242f88SMatthias Ringwald test_network_pdu_len = strlen(network_pdus[i]) / 2; 37284242f88SMatthias Ringwald btstack_parse_hex(network_pdus[i], test_network_pdu_len, test_network_pdu_data); 37384242f88SMatthias Ringwald 37484242f88SMatthias Ringwald mesh_network_received_message(test_network_pdu_data, test_network_pdu_len, 0); 37584242f88SMatthias Ringwald 37684242f88SMatthias Ringwald while (received_network_pdu == NULL) { 37784242f88SMatthias Ringwald mock_process_hci_cmd(); 37884242f88SMatthias Ringwald } 37984242f88SMatthias Ringwald 38084242f88SMatthias Ringwald transport_pdu_len = strlen(lower_transport_pdus[i]) / 2; 38184242f88SMatthias Ringwald btstack_parse_hex(lower_transport_pdus[i], transport_pdu_len, transport_pdu_data); 38284242f88SMatthias Ringwald 38384242f88SMatthias Ringwald uint8_t * lower_transport_pdu = mesh_network_pdu_data(received_network_pdu); 38484242f88SMatthias Ringwald uint8_t lower_transport_pdu_len = mesh_network_pdu_len(received_network_pdu); 38584242f88SMatthias Ringwald 38684242f88SMatthias Ringwald // printf_hexdump(lower_transport_pdu, lower_transport_pdu_len); 38784242f88SMatthias Ringwald 38884242f88SMatthias Ringwald CHECK_EQUAL( transport_pdu_len, lower_transport_pdu_len); 38984242f88SMatthias Ringwald CHECK_EQUAL_ARRAY(transport_pdu_data, lower_transport_pdu, transport_pdu_len); 39084242f88SMatthias Ringwald 39184242f88SMatthias Ringwald // forward to mesh_transport 39284242f88SMatthias Ringwald mesh_lower_transport_received_message(MESH_NETWORK_PDU_RECEIVED, received_network_pdu); 39384242f88SMatthias Ringwald 39484242f88SMatthias Ringwald // done 39584242f88SMatthias Ringwald received_network_pdu = NULL; 39684242f88SMatthias Ringwald } 39784242f88SMatthias Ringwald 39884242f88SMatthias Ringwald // wait for tranport pdu 39984242f88SMatthias Ringwald while (recv_upper_transport_pdu_len == 0) { 40084242f88SMatthias Ringwald mock_process_hci_cmd(); 40184242f88SMatthias Ringwald } 40284242f88SMatthias Ringwald 40384242f88SMatthias Ringwald transport_pdu_len = strlen(access_pdu) / 2; 40484242f88SMatthias Ringwald btstack_parse_hex(access_pdu, transport_pdu_len, transport_pdu_data); 40584242f88SMatthias Ringwald 40684242f88SMatthias Ringwald printf("UpperTransportPDU: "); 40784242f88SMatthias Ringwald printf_hexdump(recv_upper_transport_pdu_data, recv_upper_transport_pdu_len); 40884242f88SMatthias Ringwald CHECK_EQUAL( transport_pdu_len, recv_upper_transport_pdu_len); 40984242f88SMatthias Ringwald CHECK_EQUAL_ARRAY(transport_pdu_data, recv_upper_transport_pdu_data, transport_pdu_len); 41084242f88SMatthias Ringwald } 41184242f88SMatthias Ringwald 41284242f88SMatthias Ringwald static void expect_gatt_network_pdu(const uint8_t * data, uint16_t len){ 41384242f88SMatthias Ringwald while (outgoing_gatt_network_pdu_len == 0) { 41484242f88SMatthias Ringwald mock_process_hci_cmd(); 41584242f88SMatthias Ringwald } 41684242f88SMatthias Ringwald 41784242f88SMatthias Ringwald if (outgoing_gatt_network_pdu_len != test_network_pdu_len){ 41884242f88SMatthias Ringwald printf("Test Network PDU (%u): ", outgoing_gatt_network_pdu_len); printf_hexdump(outgoing_gatt_network_pdu_data, outgoing_gatt_network_pdu_len); 41984242f88SMatthias Ringwald printf("Expected PDU (%u): ", test_network_pdu_len); printf_hexdump(test_network_pdu_data, test_network_pdu_len); 42084242f88SMatthias Ringwald } 42184242f88SMatthias Ringwald CHECK_EQUAL( outgoing_gatt_network_pdu_len, test_network_pdu_len); 42284242f88SMatthias Ringwald CHECK_EQUAL_ARRAY(test_network_pdu_data, outgoing_gatt_network_pdu_data, test_network_pdu_len); 42384242f88SMatthias Ringwald 42484242f88SMatthias Ringwald outgoing_gatt_network_pdu_len = 0; 42584242f88SMatthias Ringwald gatt_bearer_emit_sent(); 42684242f88SMatthias Ringwald } 42784242f88SMatthias Ringwald 42884242f88SMatthias Ringwald static void expect_adv_network_pdu(const uint8_t * data, uint16_t len){ 42984242f88SMatthias Ringwald while (outgoing_adv_network_pdu_len == 0) { 43084242f88SMatthias Ringwald mock_process_hci_cmd(); 43184242f88SMatthias Ringwald } 43284242f88SMatthias Ringwald 43384242f88SMatthias Ringwald if (outgoing_adv_network_pdu_len != test_network_pdu_len){ 43484242f88SMatthias Ringwald printf("Test Network PDU (%u): ", outgoing_adv_network_pdu_len); printf_hexdump(outgoing_adv_network_pdu_data, outgoing_adv_network_pdu_len); 43584242f88SMatthias Ringwald printf("Expected PDU (%u): ", test_network_pdu_len); printf_hexdump(test_network_pdu_data, test_network_pdu_len); 43684242f88SMatthias Ringwald } 43784242f88SMatthias Ringwald CHECK_EQUAL( outgoing_adv_network_pdu_len, test_network_pdu_len); 43884242f88SMatthias Ringwald CHECK_EQUAL_ARRAY(test_network_pdu_data, outgoing_adv_network_pdu_data, test_network_pdu_len); 43984242f88SMatthias Ringwald 44084242f88SMatthias Ringwald outgoing_adv_network_pdu_len = 0; 44184242f88SMatthias Ringwald adv_bearer_emit_sent(); 44284242f88SMatthias Ringwald } 44384242f88SMatthias Ringwald 4448ec600ffSMatthias Ringwald static mesh_upper_transport_pdu_t upper_pdu = { 0 }; 44584242f88SMatthias Ringwald void test_send_access_message(uint16_t netkey_index, uint16_t appkey_index, uint8_t ttl, uint16_t src, uint16_t dest, uint8_t szmic, char * control_pdu, int count, char ** lower_transport_pdus, char ** network_pdus){ 44684242f88SMatthias Ringwald 44784242f88SMatthias Ringwald transport_pdu_len = strlen(control_pdu) / 2; 44884242f88SMatthias Ringwald btstack_parse_hex(control_pdu, transport_pdu_len, transport_pdu_data); 44984242f88SMatthias Ringwald 450*734bae65SMatthias Ringwald mesh_pdu_type_t pdu_type; 45184242f88SMatthias Ringwald if (count == 1 ){ 45284242f88SMatthias Ringwald // send as unsegmented access pdu 453*734bae65SMatthias Ringwald pdu_type = MESH_PDU_TYPE_UPPER_UNSEGMENTED_ACCESS; 45484242f88SMatthias Ringwald } else { 45584242f88SMatthias Ringwald // send as segmented access pdu 456*734bae65SMatthias Ringwald pdu_type = MESH_PDU_TYPE_UPPER_SEGMENTED_ACCESS; 45784242f88SMatthias Ringwald } 458*734bae65SMatthias Ringwald #if 0 459*734bae65SMatthias Ringwald // 460*734bae65SMatthias Ringwald upper_pdu.lower_pdu = NULL; 461*734bae65SMatthias Ringwald upper_pdu.flags = 0; 462*734bae65SMatthias Ringwald upper_pdu.pdu_type = pdu_type; 4638ec600ffSMatthias Ringwald mesh_pdu_t * pdu = (mesh_pdu_t *) &upper_pdu; 46484242f88SMatthias Ringwald mesh_upper_transport_setup_access_pdu(pdu, netkey_index, appkey_index, ttl, src, dest, szmic, transport_pdu_data, transport_pdu_len); 465*734bae65SMatthias Ringwald #else 466*734bae65SMatthias Ringwald mesh_upper_transport_builder_t builder; 467*734bae65SMatthias Ringwald mesh_upper_transport_message_init(&builder, pdu_type); 468*734bae65SMatthias Ringwald mesh_upper_transport_message_add_data(&builder, transport_pdu_data, transport_pdu_len); 469*734bae65SMatthias Ringwald mesh_pdu_t * pdu = (mesh_pdu_t *) mesh_upper_transport_message_finalize(&builder); 470*734bae65SMatthias Ringwald mesh_upper_transport_setup_access_pdu_header(pdu, netkey_index, appkey_index, ttl, src, dest, szmic); 471*734bae65SMatthias Ringwald #endif 47284242f88SMatthias Ringwald mesh_upper_transport_send_access_pdu(pdu); 47384242f88SMatthias Ringwald 47484242f88SMatthias Ringwald // check for all network pdus 47584242f88SMatthias Ringwald int i; 47684242f88SMatthias Ringwald for (i=0;i<count;i++){ 47784242f88SMatthias Ringwald // parse expected network pdu 47884242f88SMatthias Ringwald test_network_pdu_len = strlen(network_pdus[i]) / 2; 47984242f88SMatthias Ringwald btstack_parse_hex(network_pdus[i], test_network_pdu_len, test_network_pdu_data); 48084242f88SMatthias Ringwald 48184242f88SMatthias Ringwald #ifdef ENABLE_MESH_GATT_BEARER 48284242f88SMatthias Ringwald expect_gatt_network_pdu(test_network_pdu_data, test_network_pdu_len); 48384242f88SMatthias Ringwald #endif 48484242f88SMatthias Ringwald 48584242f88SMatthias Ringwald #ifdef ENABLE_MESH_ADV_BEARER 48684242f88SMatthias Ringwald expect_adv_network_pdu(test_network_pdu_data, test_network_pdu_len); 48784242f88SMatthias Ringwald #endif 48884242f88SMatthias Ringwald } 489242605faSMatthias Ringwald } 49084242f88SMatthias Ringwald 49184242f88SMatthias Ringwald void test_send_control_message(uint16_t netkey_index, uint8_t ttl, uint16_t src, uint16_t dest, char * control_pdu, int count, char ** lower_transport_pdus, char ** network_pdus){ 49284242f88SMatthias Ringwald 49384242f88SMatthias Ringwald transport_pdu_len = strlen(control_pdu) / 2; 49484242f88SMatthias Ringwald btstack_parse_hex(control_pdu, transport_pdu_len, transport_pdu_data); 49584242f88SMatthias Ringwald 49684242f88SMatthias Ringwald uint8_t opcode = transport_pdu_data[0]; 49784242f88SMatthias Ringwald 49884242f88SMatthias Ringwald mesh_pdu_t * pdu; 49984242f88SMatthias Ringwald if (transport_pdu_len < 12){ 50084242f88SMatthias Ringwald // send as unsegmented control pdu 50184242f88SMatthias Ringwald pdu = (mesh_pdu_t *) mesh_network_pdu_get(); 5028ec600ffSMatthias Ringwald pdu->pdu_type = MESH_PDU_TYPE_UPPER_UNSEGMENTED_CONTROL; 50384242f88SMatthias Ringwald } else { 50484242f88SMatthias Ringwald // send as segmented control pdu 505a97cf70aSMatthias Ringwald pdu = (mesh_pdu_t *) &upper_pdu; 506a97cf70aSMatthias Ringwald upper_pdu.pdu_header.pdu_type = MESH_PDU_TYPE_UPPER_SEGMENTED_CONTROL; 50784242f88SMatthias Ringwald } 50884242f88SMatthias Ringwald mesh_upper_transport_setup_control_pdu(pdu, netkey_index, ttl, src, dest, opcode, transport_pdu_data+1, transport_pdu_len-1); 50984242f88SMatthias Ringwald mesh_upper_transport_send_control_pdu(pdu); 51084242f88SMatthias Ringwald 51184242f88SMatthias Ringwald // check for all network pdus 51284242f88SMatthias Ringwald int i; 51384242f88SMatthias Ringwald for (i=0;i<count;i++){ 51484242f88SMatthias Ringwald // expected network pdu 51584242f88SMatthias Ringwald test_network_pdu_len = strlen(network_pdus[i]) / 2; 51684242f88SMatthias Ringwald btstack_parse_hex(network_pdus[i], test_network_pdu_len, test_network_pdu_data); 51784242f88SMatthias Ringwald 51884242f88SMatthias Ringwald #ifdef ENABLE_MESH_GATT_BEARER 51984242f88SMatthias Ringwald expect_gatt_network_pdu(test_network_pdu_data, test_network_pdu_len); 52084242f88SMatthias Ringwald #endif 52184242f88SMatthias Ringwald 52284242f88SMatthias Ringwald #ifdef ENABLE_MESH_ADV_BEARER 52384242f88SMatthias Ringwald expect_adv_network_pdu(test_network_pdu_data, test_network_pdu_len); 52484242f88SMatthias Ringwald #endif 52584242f88SMatthias Ringwald 52684242f88SMatthias Ringwald } 52784242f88SMatthias Ringwald } 52884242f88SMatthias Ringwald #if 1 52984242f88SMatthias Ringwald // Message 1 53084242f88SMatthias Ringwald char * message1_network_pdus[] = { 53184242f88SMatthias Ringwald (char *) "68eca487516765b5e5bfdacbaf6cb7fb6bff871f035444ce83a670df" 53284242f88SMatthias Ringwald }; 53384242f88SMatthias Ringwald char * message1_lower_transport_pdus[] = { 53484242f88SMatthias Ringwald (char *) "034b50057e400000010000", 53584242f88SMatthias Ringwald }; 53684242f88SMatthias Ringwald char * message1_upper_transport_pdu = (char *) "034b50057e400000010000"; 53784242f88SMatthias Ringwald TEST(MessageTest, Message1Receive){ 53884242f88SMatthias Ringwald load_network_key_nid_68(); 53984242f88SMatthias Ringwald mesh_set_iv_index(0x12345678); 54084242f88SMatthias Ringwald test_receive_network_pdus(1, message1_network_pdus, message1_lower_transport_pdus, message1_upper_transport_pdu); 54184242f88SMatthias Ringwald } 54284242f88SMatthias Ringwald TEST(MessageTest, Message1Send){ 54384242f88SMatthias Ringwald uint16_t netkey_index = 0; 54484242f88SMatthias Ringwald uint8_t ttl = 0; 54584242f88SMatthias Ringwald uint16_t src = 0x1201; 54684242f88SMatthias Ringwald uint16_t dest = 0xfffd; 54784242f88SMatthias Ringwald uint32_t seq = 1; 54884242f88SMatthias Ringwald load_network_key_nid_68(); 54984242f88SMatthias Ringwald mesh_set_iv_index(0x12345678); 55084242f88SMatthias Ringwald mesh_sequence_number_set(seq); 55184242f88SMatthias Ringwald test_send_control_message(netkey_index, ttl, src, dest, message1_upper_transport_pdu, 1, message1_lower_transport_pdus, message1_network_pdus); 55284242f88SMatthias Ringwald } 55384242f88SMatthias Ringwald 55484242f88SMatthias Ringwald // Message 2 55584242f88SMatthias Ringwald char * message2_network_pdus[] = { 55684242f88SMatthias Ringwald (char *) "68d4c826296d7979d7dbc0c9b4d43eebec129d20a620d01e" 55784242f88SMatthias Ringwald }; 55884242f88SMatthias Ringwald char * message2_lower_transport_pdus[] = { 55984242f88SMatthias Ringwald (char *) "04320308ba072f", 56084242f88SMatthias Ringwald }; 56184242f88SMatthias Ringwald char * message2_upper_transport_pdu = (char *) "04320308ba072f"; 56284242f88SMatthias Ringwald TEST(MessageTest, Message2Receive){ 56384242f88SMatthias Ringwald load_network_key_nid_68(); 56484242f88SMatthias Ringwald mesh_set_iv_index(0x12345678); 56584242f88SMatthias Ringwald test_receive_network_pdus(1, message2_network_pdus, message2_lower_transport_pdus, message2_upper_transport_pdu); 56684242f88SMatthias Ringwald } 56784242f88SMatthias Ringwald TEST(MessageTest, Message2Send){ 56884242f88SMatthias Ringwald uint16_t netkey_index = 0; 56984242f88SMatthias Ringwald uint8_t ttl = 0; 57084242f88SMatthias Ringwald uint16_t src = 0x2345; 57184242f88SMatthias Ringwald uint16_t dest = 0x1201; 57284242f88SMatthias Ringwald uint32_t seq = 0x014820; 57384242f88SMatthias Ringwald load_network_key_nid_68(); 57484242f88SMatthias Ringwald mesh_set_iv_index(0x12345678); 57584242f88SMatthias Ringwald mesh_sequence_number_set(seq); 57684242f88SMatthias Ringwald test_send_control_message(netkey_index, ttl, src, dest, message2_upper_transport_pdu, 1, message2_lower_transport_pdus, message2_network_pdus); 57784242f88SMatthias Ringwald } 57884242f88SMatthias Ringwald 57984242f88SMatthias Ringwald // Message 3 58084242f88SMatthias Ringwald char * message3_network_pdus[] = { 58184242f88SMatthias Ringwald (char *) "68da062bc96df253273086b8c5ee00bdd9cfcc62a2ddf572" 58284242f88SMatthias Ringwald }; 58384242f88SMatthias Ringwald char * message3_lower_transport_pdus[] = { 58484242f88SMatthias Ringwald (char *) "04fa0205a6000a", 58584242f88SMatthias Ringwald }; 58684242f88SMatthias Ringwald char * message3_upper_transport_pdu = (char *) "04fa0205a6000a"; 58784242f88SMatthias Ringwald TEST(MessageTest, Message3Receive){ 58884242f88SMatthias Ringwald load_network_key_nid_68(); 58984242f88SMatthias Ringwald mesh_set_iv_index(0x12345678); 59084242f88SMatthias Ringwald test_receive_network_pdus(1, message3_network_pdus, message3_lower_transport_pdus, message3_upper_transport_pdu); 59184242f88SMatthias Ringwald } 59284242f88SMatthias Ringwald TEST(MessageTest, Message3Send){ 59384242f88SMatthias Ringwald uint16_t netkey_index = 0; 59484242f88SMatthias Ringwald uint8_t ttl = 0; 59584242f88SMatthias Ringwald uint16_t src = 0x2fe3; 59684242f88SMatthias Ringwald uint16_t dest = 0x1201; 59784242f88SMatthias Ringwald uint32_t seq = 0x2b3832; 59884242f88SMatthias Ringwald load_network_key_nid_68(); 59984242f88SMatthias Ringwald mesh_set_iv_index(0x12345678); 60084242f88SMatthias Ringwald mesh_sequence_number_set(seq); 60184242f88SMatthias Ringwald test_send_control_message(netkey_index, ttl, src, dest, message3_upper_transport_pdu, 1, message3_lower_transport_pdus, message3_network_pdus); 60284242f88SMatthias Ringwald } 60384242f88SMatthias Ringwald 60484242f88SMatthias Ringwald // Message 4 60584242f88SMatthias Ringwald char * message4_network_pdus[] = { 60684242f88SMatthias Ringwald (char *) "5e84eba092380fb0e5d0ad970d579a4e88051c" 60784242f88SMatthias Ringwald }; 60884242f88SMatthias Ringwald char * message4_lower_transport_pdus[] = { 60984242f88SMatthias Ringwald (char *) "0100", 61084242f88SMatthias Ringwald }; 61184242f88SMatthias Ringwald char * message4_upper_transport_pdu = (char *) "0100"; 61284242f88SMatthias Ringwald TEST(MessageTest, Message4Receive){ 61384242f88SMatthias Ringwald load_network_key_nid_5e(); 61484242f88SMatthias Ringwald mesh_set_iv_index(0x12345678); 61584242f88SMatthias Ringwald test_receive_network_pdus(1, message4_network_pdus, message4_lower_transport_pdus, message4_upper_transport_pdu); 61684242f88SMatthias Ringwald } 61784242f88SMatthias Ringwald TEST(MessageTest, Message4Send){ 61884242f88SMatthias Ringwald uint16_t netkey_index = 0; 61984242f88SMatthias Ringwald uint8_t ttl = 0; 62084242f88SMatthias Ringwald uint16_t src = 0x1201; 62184242f88SMatthias Ringwald uint16_t dest = 0x2345; 62284242f88SMatthias Ringwald uint32_t seq = 0x000002; 62384242f88SMatthias Ringwald load_network_key_nid_5e(); 62484242f88SMatthias Ringwald mesh_set_iv_index(0x12345678); 62584242f88SMatthias Ringwald mesh_sequence_number_set(seq); 62684242f88SMatthias Ringwald test_send_control_message(netkey_index, ttl, src, dest, message4_upper_transport_pdu, 1, message4_lower_transport_pdus, message4_network_pdus); 62784242f88SMatthias Ringwald } 62884242f88SMatthias Ringwald 62984242f88SMatthias Ringwald // Message 5 63084242f88SMatthias Ringwald char * message5_network_pdus[] = { 63184242f88SMatthias Ringwald (char *) "5eafd6f53c43db5c39da1792b1fee9ec74b786c56d3a9dee", 63284242f88SMatthias Ringwald }; 63384242f88SMatthias Ringwald char * message5_lower_transport_pdus[] = { 63484242f88SMatthias Ringwald (char *) "02001234567800", 63584242f88SMatthias Ringwald }; 63684242f88SMatthias Ringwald char * message5_upper_transport_pdu = (char *) "02001234567800"; 63784242f88SMatthias Ringwald TEST(MessageTest, Message5Receive){ 63884242f88SMatthias Ringwald load_network_key_nid_5e(); 63984242f88SMatthias Ringwald mesh_set_iv_index(0x12345678); 64084242f88SMatthias Ringwald test_receive_network_pdus(1, message5_network_pdus, message5_lower_transport_pdus, message5_upper_transport_pdu); 64184242f88SMatthias Ringwald } 64284242f88SMatthias Ringwald TEST(MessageTest, Message5Send){ 64384242f88SMatthias Ringwald uint16_t netkey_index = 0; 64484242f88SMatthias Ringwald uint8_t ttl = 0; 64584242f88SMatthias Ringwald uint16_t src = 0x2345; 64684242f88SMatthias Ringwald uint16_t dest = 0x1201; 64784242f88SMatthias Ringwald uint32_t seq = 0x014834; 64884242f88SMatthias Ringwald load_network_key_nid_5e(); 64984242f88SMatthias Ringwald mesh_set_iv_index(0x12345678); 65084242f88SMatthias Ringwald mesh_sequence_number_set(seq); 65184242f88SMatthias Ringwald test_send_control_message(netkey_index, ttl, src, dest, message5_upper_transport_pdu, 1, message5_lower_transport_pdus, message5_network_pdus); 65284242f88SMatthias Ringwald } 65384242f88SMatthias Ringwald 65484242f88SMatthias Ringwald // Message 6 65584242f88SMatthias Ringwald char * message6_network_pdus[] = { 65684242f88SMatthias Ringwald (char *) "68cab5c5348a230afba8c63d4e686364979deaf4fd40961145939cda0e", 65784242f88SMatthias Ringwald (char *) "681615b5dd4a846cae0c032bf0746f44f1b8cc8ce5edc57e55beed49c0", 65884242f88SMatthias Ringwald }; 65984242f88SMatthias Ringwald char * message6_lower_transport_pdus[] = { 66084242f88SMatthias Ringwald (char *) "8026ac01ee9dddfd2169326d23f3afdf", 66184242f88SMatthias Ringwald (char *) "8026ac21cfdc18c52fdef772e0e17308", 66284242f88SMatthias Ringwald }; 66384242f88SMatthias Ringwald char * message6_upper_transport_pdu = (char *) "0056341263964771734fbd76e3b40519d1d94a48"; 66484242f88SMatthias Ringwald TEST(MessageTest, Message6Receive){ 66584242f88SMatthias Ringwald load_network_key_nid_68(); 66684242f88SMatthias Ringwald mesh_set_iv_index(0x12345678); 66784242f88SMatthias Ringwald test_receive_network_pdus(2, message6_network_pdus, message6_lower_transport_pdus, message6_upper_transport_pdu); 66884242f88SMatthias Ringwald } 66984242f88SMatthias Ringwald TEST(MessageTest, Message6Send){ 67084242f88SMatthias Ringwald uint16_t netkey_index = 0; 67184242f88SMatthias Ringwald uint16_t appkey_index = MESH_DEVICE_KEY_INDEX; 67284242f88SMatthias Ringwald uint8_t ttl = 4; 67384242f88SMatthias Ringwald uint16_t src = 0x0003; 67484242f88SMatthias Ringwald uint16_t dest = 0x1201; 67584242f88SMatthias Ringwald uint32_t seq = 0x3129ab; 67684242f88SMatthias Ringwald uint8_t szmic = 0; 67784242f88SMatthias Ringwald 67884242f88SMatthias Ringwald load_network_key_nid_68(); 67984242f88SMatthias Ringwald mesh_set_iv_index(0x12345678); 68084242f88SMatthias Ringwald mesh_sequence_number_set(seq); 68184242f88SMatthias Ringwald test_send_access_message(netkey_index, appkey_index, ttl, src, dest, szmic, message6_upper_transport_pdu, 2, message6_lower_transport_pdus, message6_network_pdus); 68284242f88SMatthias Ringwald } 68384242f88SMatthias Ringwald 68484242f88SMatthias Ringwald // Message 7 - ACK 68584242f88SMatthias Ringwald char * message7_network_pdus[] = { 68684242f88SMatthias Ringwald (char *) "68e476b5579c980d0d730f94d7f3509df987bb417eb7c05f", 68784242f88SMatthias Ringwald }; 68884242f88SMatthias Ringwald char * message7_lower_transport_pdus[] = { 68984242f88SMatthias Ringwald (char *) "00a6ac00000002", 69084242f88SMatthias Ringwald }; 69184242f88SMatthias Ringwald char * message7_upper_transport_pdu = (char *) "00a6ac00000002"; 69284242f88SMatthias Ringwald TEST(MessageTest, Message7Send){ 69384242f88SMatthias Ringwald uint16_t netkey_index = 0; 69484242f88SMatthias Ringwald uint8_t ttl = 0x0b; 69584242f88SMatthias Ringwald uint16_t src = 0x2345; 69684242f88SMatthias Ringwald uint16_t dest = 0x0003; 69784242f88SMatthias Ringwald uint32_t seq = 0x014835; 69884242f88SMatthias Ringwald 69984242f88SMatthias Ringwald load_network_key_nid_68(); 70084242f88SMatthias Ringwald mesh_set_iv_index(0x12345678); 70184242f88SMatthias Ringwald mesh_sequence_number_set(seq); 70284242f88SMatthias Ringwald test_send_control_message(netkey_index, ttl, src, dest, message7_upper_transport_pdu, 1, message7_lower_transport_pdus, message7_network_pdus); 70384242f88SMatthias Ringwald } 70484242f88SMatthias Ringwald // ACK message, handled in mesh_transport - can be checked with test_control_receive_network_pdu 70584242f88SMatthias Ringwald // TEST(MessageTest, Message7Receive){ 70684242f88SMatthias Ringwald // mesh_set_iv_index(0x12345678); 70784242f88SMatthias Ringwald // test_receive_network_pdus(1, message7_network_pdus, message7_lower_transport_pdus, message7_upper_transport_pdu); 70884242f88SMatthias Ringwald // } 70984242f88SMatthias Ringwald 71084242f88SMatthias Ringwald // Message 8 - ACK 71184242f88SMatthias Ringwald char * message8_network_pdus[] = { 71284242f88SMatthias Ringwald (char *) "684daa6267c2cf0e2f91add6f06e66006844cec97f973105ae2534f958", 71384242f88SMatthias Ringwald }; 71484242f88SMatthias Ringwald char * message8_lower_transport_pdus[] = { 71584242f88SMatthias Ringwald (char *) "8026ac01ee9dddfd2169326d23f3afdf", 71684242f88SMatthias Ringwald }; 71784242f88SMatthias Ringwald char * message8_upper_transport_pdu = (char *) "8026ac01ee9dddfd2169326d23f3afdf"; 71884242f88SMatthias Ringwald // ACK message, handled in mesh_transport - can be checked with test_control_receive_network_pdu 71984242f88SMatthias Ringwald // TEST(MessageTest, Message8Receive){ 72084242f88SMatthias Ringwald // mesh_set_iv_index(0x12345678); 72184242f88SMatthias Ringwald // test_receive_network_pdus(1, message8_network_pdus, message8_lower_transport_pdus, message8_upper_transport_pdu); 72284242f88SMatthias Ringwald // } 72384242f88SMatthias Ringwald 72484242f88SMatthias Ringwald // Message 9 - ACK 72584242f88SMatthias Ringwald 72684242f88SMatthias Ringwald // Message 10 72784242f88SMatthias Ringwald char * message10_network_pdus[] = { 72884242f88SMatthias Ringwald (char *) "5e7b786568759f7777ed355afaf66d899c1e3d", 72984242f88SMatthias Ringwald }; 73084242f88SMatthias Ringwald char * message10_lower_transport_pdus[] = { 73184242f88SMatthias Ringwald (char *) "0101", 73284242f88SMatthias Ringwald }; 73384242f88SMatthias Ringwald char * message10_upper_transport_pdu = (char *) "0101"; 73484242f88SMatthias Ringwald TEST(MessageTest, Message10Receive){ 73584242f88SMatthias Ringwald load_network_key_nid_5e(); 73684242f88SMatthias Ringwald mesh_set_iv_index(0x12345678); 73784242f88SMatthias Ringwald test_receive_network_pdus(1, message10_network_pdus, message10_lower_transport_pdus, message10_upper_transport_pdu); 73884242f88SMatthias Ringwald } 73984242f88SMatthias Ringwald TEST(MessageTest, Message10Send){ 74084242f88SMatthias Ringwald uint16_t netkey_index = 0; 74184242f88SMatthias Ringwald uint8_t ttl = 0; 74284242f88SMatthias Ringwald uint16_t src = 0x1201; 74384242f88SMatthias Ringwald uint16_t dest = 0x2345; 74484242f88SMatthias Ringwald uint32_t seq = 0x000003; 74584242f88SMatthias Ringwald 74684242f88SMatthias Ringwald load_network_key_nid_5e(); 74784242f88SMatthias Ringwald mesh_set_iv_index(0x12345678); 74884242f88SMatthias Ringwald mesh_sequence_number_set(seq); 74984242f88SMatthias Ringwald test_send_control_message(netkey_index, ttl, src, dest, message10_upper_transport_pdu, 1, message10_lower_transport_pdus, message10_network_pdus); 75084242f88SMatthias Ringwald } 75184242f88SMatthias Ringwald 75284242f88SMatthias Ringwald // Message 11 75384242f88SMatthias Ringwald // The Friend node responds to this poll with the first segment of the stored message. It also indicates that it has more data. 75484242f88SMatthias Ringwald 75584242f88SMatthias Ringwald // Message 12 75684242f88SMatthias Ringwald char * message12_network_pdus[] = { 75784242f88SMatthias Ringwald (char *) "5e8a18fc6e4d05ae21466087599c2426ce9a35", 75884242f88SMatthias Ringwald }; 75984242f88SMatthias Ringwald char * message12_lower_transport_pdus[] = { 76084242f88SMatthias Ringwald (char *) "0101", 76184242f88SMatthias Ringwald }; 76284242f88SMatthias Ringwald char * message12_upper_transport_pdu = (char *) "0101"; 76384242f88SMatthias Ringwald TEST(MessageTest, Message12Receive){ 76484242f88SMatthias Ringwald load_network_key_nid_5e(); 76584242f88SMatthias Ringwald mesh_set_iv_index(0x12345678); 76684242f88SMatthias Ringwald test_receive_network_pdus(1, message12_network_pdus, message12_lower_transport_pdus, message12_upper_transport_pdu); 76784242f88SMatthias Ringwald } 76884242f88SMatthias Ringwald TEST(MessageTest, Message12Send){ 76984242f88SMatthias Ringwald uint16_t netkey_index = 0; 77084242f88SMatthias Ringwald uint8_t ttl = 0; 77184242f88SMatthias Ringwald uint16_t src = 0x1201; 77284242f88SMatthias Ringwald uint16_t dest = 0x2345; 77384242f88SMatthias Ringwald uint32_t seq = 0x000004; 77484242f88SMatthias Ringwald 77584242f88SMatthias Ringwald load_network_key_nid_5e(); 77684242f88SMatthias Ringwald mesh_set_iv_index(0x12345678); 77784242f88SMatthias Ringwald mesh_sequence_number_set(seq); 77884242f88SMatthias Ringwald test_send_control_message(netkey_index, ttl, src, dest, message12_upper_transport_pdu, 1, message12_lower_transport_pdus, message12_network_pdus); 77984242f88SMatthias Ringwald } 78084242f88SMatthias Ringwald 78184242f88SMatthias Ringwald // Message 13 78284242f88SMatthias Ringwald // The Friend node responds with the same message as last time. 78384242f88SMatthias Ringwald // Message 14 78484242f88SMatthias Ringwald // The Low Power node received the retransmitted stored message. As that message has the MD bit set 78584242f88SMatthias Ringwald // it sends another Friend Poll to obtain the next message. 78684242f88SMatthias Ringwald char * message14_network_pdus[] = { 78784242f88SMatthias Ringwald (char *) "5e0bbaf92b5c8f7d3ae62a3c75dff683dce24e", 78884242f88SMatthias Ringwald }; 78984242f88SMatthias Ringwald char * message14_lower_transport_pdus[] = { 79084242f88SMatthias Ringwald (char *) "0100", 79184242f88SMatthias Ringwald }; 79284242f88SMatthias Ringwald char * message14_upper_transport_pdu = (char *) "0100"; 79384242f88SMatthias Ringwald TEST(MessageTest, Message14Receive){ 79484242f88SMatthias Ringwald load_network_key_nid_5e(); 79584242f88SMatthias Ringwald mesh_set_iv_index(0x12345678); 79684242f88SMatthias Ringwald test_receive_network_pdus(1, message14_network_pdus, message14_lower_transport_pdus, message14_upper_transport_pdu); 79784242f88SMatthias Ringwald } 79884242f88SMatthias Ringwald TEST(MessageTest, Message14Send){ 79984242f88SMatthias Ringwald uint16_t netkey_index = 0; 80084242f88SMatthias Ringwald uint8_t ttl = 0; 80184242f88SMatthias Ringwald uint16_t src = 0x1201; 80284242f88SMatthias Ringwald uint16_t dest = 0x2345; 80384242f88SMatthias Ringwald uint32_t seq = 0x000005; 80484242f88SMatthias Ringwald 80584242f88SMatthias Ringwald load_network_key_nid_5e(); 80684242f88SMatthias Ringwald mesh_set_iv_index(0x12345678); 80784242f88SMatthias Ringwald mesh_sequence_number_set(seq); 80884242f88SMatthias Ringwald test_send_control_message(netkey_index, ttl, src, dest, message14_upper_transport_pdu, 1, message14_lower_transport_pdus, message14_network_pdus); 80984242f88SMatthias Ringwald } 81084242f88SMatthias Ringwald 81184242f88SMatthias Ringwald // Message 15 81284242f88SMatthias Ringwald // The Friend node responds, with the next message in the friend queue. The Friend node has no more data, so it sets the MD to 0. 81384242f88SMatthias Ringwald char * message15_network_pdus[] = { 81484242f88SMatthias Ringwald (char *) "5ea8dab50e7ee7f1d29805664d235eacd707217dedfe78497fefec7391", 81584242f88SMatthias Ringwald }; 81684242f88SMatthias Ringwald char * message15_lower_transport_pdus[] = { 81784242f88SMatthias Ringwald (char *) "8026ac21cfdc18c52fdef772e0e17308", 81884242f88SMatthias Ringwald }; 81984242f88SMatthias Ringwald char * message15_upper_transport_pdu = (char *) "0100"; 82084242f88SMatthias Ringwald // ACK message, handled in mesh_transport - can be checked with test_control_receive_network_pdu 82184242f88SMatthias Ringwald // not sure - no upper access message 82284242f88SMatthias Ringwald // TEST(MessageTest, Message15Receive){ 82384242f88SMatthias Ringwald // load_network_key_nid_5e(); 82484242f88SMatthias Ringwald // mesh_set_iv_index(0x12345678); 82584242f88SMatthias Ringwald // test_receive_network_pdus(1, message15_network_pdus, message15_lower_transport_pdus, message15_upper_transport_pdu); 82684242f88SMatthias Ringwald // } 82784242f88SMatthias Ringwald 82884242f88SMatthias Ringwald // Message 16 82984242f88SMatthias Ringwald char * message16_network_pdus[] = { 83084242f88SMatthias Ringwald (char *) "68e80e5da5af0e6b9be7f5a642f2f98680e61c3a8b47f228", 83184242f88SMatthias Ringwald }; 83284242f88SMatthias Ringwald char * message16_lower_transport_pdus[] = { 83384242f88SMatthias Ringwald (char *) "0089511bf1d1a81c11dcef", 83484242f88SMatthias Ringwald }; 83584242f88SMatthias Ringwald char * message16_upper_transport_pdu = (char *) "800300563412"; 83684242f88SMatthias Ringwald TEST(MessageTest, Message16Receive){ 83784242f88SMatthias Ringwald load_network_key_nid_68(); 83884242f88SMatthias Ringwald mesh_set_iv_index(0x12345678); 83984242f88SMatthias Ringwald test_receive_network_pdus(1, message16_network_pdus, message16_lower_transport_pdus, message16_upper_transport_pdu); 84084242f88SMatthias Ringwald } 84184242f88SMatthias Ringwald TEST(MessageTest, Message16Send){ 84284242f88SMatthias Ringwald uint16_t netkey_index = 0; 84384242f88SMatthias Ringwald uint16_t appkey_index = MESH_DEVICE_KEY_INDEX; 84484242f88SMatthias Ringwald uint8_t ttl = 0x0b; 84584242f88SMatthias Ringwald uint16_t src = 0x1201; 84684242f88SMatthias Ringwald uint16_t dest = 0x0003; 84784242f88SMatthias Ringwald uint32_t seq = 0x000006; 84884242f88SMatthias Ringwald uint8_t szmic = 0; 84984242f88SMatthias Ringwald 85084242f88SMatthias Ringwald load_network_key_nid_68(); 85184242f88SMatthias Ringwald mesh_set_iv_index(0x12345678); 85284242f88SMatthias Ringwald mesh_sequence_number_set(seq); 85384242f88SMatthias Ringwald test_send_access_message(netkey_index, appkey_index, ttl, src, dest, szmic, message16_upper_transport_pdu, 1, message16_lower_transport_pdus, message16_network_pdus); 85484242f88SMatthias Ringwald } 85584242f88SMatthias Ringwald 85684242f88SMatthias Ringwald // Message 17 85784242f88SMatthias Ringwald // A Relay node receives the message from the Low Power node and relays it, decrementing the TTL value. 85884242f88SMatthias Ringwald // Message 18 85984242f88SMatthias Ringwald char * message18_network_pdus[] = { 86084242f88SMatthias Ringwald (char *) "6848cba437860e5673728a627fb938535508e21a6baf57", 86184242f88SMatthias Ringwald }; 86284242f88SMatthias Ringwald char * message18_lower_transport_pdus[] = { 86384242f88SMatthias Ringwald (char *) "665a8bde6d9106ea078a", 86484242f88SMatthias Ringwald }; 86584242f88SMatthias Ringwald char * message18_upper_transport_pdu = (char *) "0400000000"; 86684242f88SMatthias Ringwald TEST(MessageTest, Message18Receive){ 86784242f88SMatthias Ringwald load_network_key_nid_68(); 86884242f88SMatthias Ringwald mesh_set_iv_index(0x12345678); 86984242f88SMatthias Ringwald test_receive_network_pdus(1, message18_network_pdus, message18_lower_transport_pdus, message18_upper_transport_pdu); 87084242f88SMatthias Ringwald } 87184242f88SMatthias Ringwald TEST(MessageTest, Message18Send){ 87284242f88SMatthias Ringwald uint16_t netkey_index = 0; 87384242f88SMatthias Ringwald uint16_t appkey_index = 0; 87484242f88SMatthias Ringwald uint8_t ttl = 3; 87584242f88SMatthias Ringwald uint16_t src = 0x1201; 87684242f88SMatthias Ringwald uint16_t dest = 0xffff; 87784242f88SMatthias Ringwald uint32_t seq = 0x00007; 87884242f88SMatthias Ringwald uint8_t szmic = 0; 87984242f88SMatthias Ringwald 88084242f88SMatthias Ringwald load_network_key_nid_68(); 88184242f88SMatthias Ringwald mesh_set_iv_index(0x12345678); 88284242f88SMatthias Ringwald mesh_sequence_number_set(seq); 88384242f88SMatthias Ringwald test_send_access_message(netkey_index, appkey_index, ttl, src, dest, szmic, message18_upper_transport_pdu, 1, message18_lower_transport_pdus, message18_network_pdus); 88484242f88SMatthias Ringwald } 88584242f88SMatthias Ringwald 88684242f88SMatthias Ringwald 88784242f88SMatthias Ringwald // Message 19 88884242f88SMatthias Ringwald // The Low Power node sends another Health Current Status message indicating that there are three faults: 88984242f88SMatthias Ringwald // Battery Low Warning, Power Supply Interrupted Warning, and Supply Voltage Too Low Warning. 89084242f88SMatthias Ringwald char * message19_network_pdus[] = { 89184242f88SMatthias Ringwald (char *) "68110edeecd83c3010a05e1b23a926023da75d25ba91793736", 89284242f88SMatthias Ringwald }; 89384242f88SMatthias Ringwald char * message19_lower_transport_pdus[] = { 89484242f88SMatthias Ringwald (char *) "66ca6cd88e698d1265f43fc5", 89584242f88SMatthias Ringwald }; 89684242f88SMatthias Ringwald char * message19_upper_transport_pdu = (char *) "04000000010703"; 89784242f88SMatthias Ringwald TEST(MessageTest, Message19Receive){ 89884242f88SMatthias Ringwald load_network_key_nid_68(); 89984242f88SMatthias Ringwald mesh_set_iv_index(0x12345678); 90084242f88SMatthias Ringwald test_receive_network_pdus(1, message19_network_pdus, message19_lower_transport_pdus, message19_upper_transport_pdu); 90184242f88SMatthias Ringwald } 90284242f88SMatthias Ringwald TEST(MessageTest, Message19Send){ 90384242f88SMatthias Ringwald uint16_t netkey_index = 0; 90484242f88SMatthias Ringwald uint16_t appkey_index = 0; 90584242f88SMatthias Ringwald uint8_t ttl = 3; 90684242f88SMatthias Ringwald uint16_t src = 0x1201; 90784242f88SMatthias Ringwald uint16_t dest = 0xffff; 90884242f88SMatthias Ringwald uint32_t seq = 0x00009; 90984242f88SMatthias Ringwald uint8_t szmic = 0; 91084242f88SMatthias Ringwald 91184242f88SMatthias Ringwald load_network_key_nid_68(); 91284242f88SMatthias Ringwald mesh_set_iv_index(0x12345678); 91384242f88SMatthias Ringwald mesh_sequence_number_set(seq); 91484242f88SMatthias Ringwald test_send_access_message(netkey_index, appkey_index, ttl, src, dest, szmic, message19_upper_transport_pdu, 1, message19_lower_transport_pdus, message19_network_pdus); 91584242f88SMatthias Ringwald } 91684242f88SMatthias Ringwald 91784242f88SMatthias Ringwald // Message 20 91884242f88SMatthias Ringwald char * message20_network_pdus[] = { 91984242f88SMatthias Ringwald (char *) "e85cca51e2e8998c3dc87344a16c787f6b08cc897c941a5368", 92084242f88SMatthias Ringwald }; 92184242f88SMatthias Ringwald char * message20_lower_transport_pdus[] = { 92284242f88SMatthias Ringwald (char *) "669c9803e110fea929e9542d", 92384242f88SMatthias Ringwald }; 92484242f88SMatthias Ringwald char * message20_upper_transport_pdu = (char *) "04000000010703"; 92584242f88SMatthias Ringwald TEST(MessageTest, Message20Receive){ 92684242f88SMatthias Ringwald load_network_key_nid_68(); 92784242f88SMatthias Ringwald mesh_set_iv_index(0x12345677); 92884242f88SMatthias Ringwald test_receive_network_pdus(1, message20_network_pdus, message20_lower_transport_pdus, message20_upper_transport_pdu); 92984242f88SMatthias Ringwald } 93084242f88SMatthias Ringwald TEST(MessageTest, Message20Send){ 93184242f88SMatthias Ringwald uint16_t netkey_index = 0; 93284242f88SMatthias Ringwald uint16_t appkey_index = 0; 93384242f88SMatthias Ringwald uint8_t ttl = 3; 93484242f88SMatthias Ringwald uint16_t src = 0x1234; 93584242f88SMatthias Ringwald uint16_t dest = 0xffff; 93684242f88SMatthias Ringwald uint32_t seq = 0x070809; 93784242f88SMatthias Ringwald uint8_t szmic = 0; 93884242f88SMatthias Ringwald 93984242f88SMatthias Ringwald load_network_key_nid_68(); 94084242f88SMatthias Ringwald mesh_set_iv_index(0x12345677); 94184242f88SMatthias Ringwald mesh_sequence_number_set(seq); 94284242f88SMatthias Ringwald test_send_access_message(netkey_index, appkey_index, ttl, src, dest, szmic, message20_upper_transport_pdu, 1, message20_lower_transport_pdus, message20_network_pdus); 94384242f88SMatthias Ringwald } 94484242f88SMatthias Ringwald 94584242f88SMatthias Ringwald // Message 21 94684242f88SMatthias Ringwald // The Low Power node sends a vendor command to a group address. 94784242f88SMatthias Ringwald char * message21_network_pdus[] = { 94884242f88SMatthias Ringwald (char *) "e84e8fbe003f58a4d61157bb76352ea6307eebfe0f30b83500e9", 94984242f88SMatthias Ringwald }; 95084242f88SMatthias Ringwald char * message21_lower_transport_pdus[] = { 95184242f88SMatthias Ringwald (char *) "664d92e9dfcf3ab85b6e8fcf03", 95284242f88SMatthias Ringwald }; 95384242f88SMatthias Ringwald char * message21_upper_transport_pdu = (char *) "d50a0048656c6c6f"; 95484242f88SMatthias Ringwald TEST(MessageTest, Message21Receive){ 95584242f88SMatthias Ringwald load_network_key_nid_68(); 95684242f88SMatthias Ringwald mesh_set_iv_index(0x12345677); 95784242f88SMatthias Ringwald test_receive_network_pdus(1, message21_network_pdus, message21_lower_transport_pdus, message21_upper_transport_pdu); 95884242f88SMatthias Ringwald } 95984242f88SMatthias Ringwald TEST(MessageTest, Message21Send){ 96084242f88SMatthias Ringwald uint16_t netkey_index = 0; 96184242f88SMatthias Ringwald uint16_t appkey_index = 0; 96284242f88SMatthias Ringwald uint8_t ttl = 3; 96384242f88SMatthias Ringwald uint16_t src = 0x1234; 96484242f88SMatthias Ringwald uint16_t dest = 0xc105; 96584242f88SMatthias Ringwald uint32_t seq = 0x07080a; 96684242f88SMatthias Ringwald uint8_t szmic = 0; 96784242f88SMatthias Ringwald 96884242f88SMatthias Ringwald load_network_key_nid_68(); 96984242f88SMatthias Ringwald mesh_set_iv_index(0x12345677); 97084242f88SMatthias Ringwald mesh_sequence_number_set(seq); 97184242f88SMatthias Ringwald test_send_access_message(netkey_index, appkey_index, ttl, src, dest, szmic, message21_upper_transport_pdu, 1, message21_lower_transport_pdus, message21_network_pdus); 97284242f88SMatthias Ringwald } 97384242f88SMatthias Ringwald 97484242f88SMatthias Ringwald // Message 22 97584242f88SMatthias Ringwald char * message22_network_pdus[] = { 97684242f88SMatthias Ringwald (char *) "e8d85caecef1e3ed31f3fdcf88a411135fea55df730b6b28e255", 97784242f88SMatthias Ringwald }; 97884242f88SMatthias Ringwald char * message22_lower_transport_pdus[] = { 97984242f88SMatthias Ringwald (char *) "663871b904d431526316ca48a0", 98084242f88SMatthias Ringwald }; 98184242f88SMatthias Ringwald char * message22_upper_transport_pdu = (char *) "d50a0048656c6c6f"; 98284242f88SMatthias Ringwald char * message22_label_string = (char *) "0073e7e4d8b9440faf8415df4c56c0e1"; 98384242f88SMatthias Ringwald 98484242f88SMatthias Ringwald TEST(MessageTest, Message22Receive){ 98584242f88SMatthias Ringwald load_network_key_nid_68(); 98684242f88SMatthias Ringwald mesh_set_iv_index(0x12345677); 98784242f88SMatthias Ringwald uint8_t label_uuid[16]; 98884242f88SMatthias Ringwald btstack_parse_hex(message22_label_string, 16, label_uuid); 98984242f88SMatthias Ringwald mesh_virtual_address_register(label_uuid, 0xb529); 99084242f88SMatthias Ringwald test_receive_network_pdus(1, message22_network_pdus, message22_lower_transport_pdus, message22_upper_transport_pdu); 99184242f88SMatthias Ringwald } 99284242f88SMatthias Ringwald 99384242f88SMatthias Ringwald TEST(MessageTest, Message22Send){ 99484242f88SMatthias Ringwald uint16_t netkey_index = 0; 99584242f88SMatthias Ringwald uint16_t appkey_index = 0; 99684242f88SMatthias Ringwald uint8_t ttl = 3; 99784242f88SMatthias Ringwald uint16_t src = 0x1234; 99884242f88SMatthias Ringwald uint32_t seq = 0x07080b; 99984242f88SMatthias Ringwald uint8_t szmic = 0; 100084242f88SMatthias Ringwald 100184242f88SMatthias Ringwald load_network_key_nid_68(); 100284242f88SMatthias Ringwald mesh_set_iv_index(0x12345677); 100384242f88SMatthias Ringwald mesh_sequence_number_set(seq); 100484242f88SMatthias Ringwald uint8_t label_uuid[16]; 100584242f88SMatthias Ringwald btstack_parse_hex(message22_label_string, 16, label_uuid); 100684242f88SMatthias Ringwald mesh_virtual_address_t * virtual_address = mesh_virtual_address_register(label_uuid, 0xb529); 100784242f88SMatthias Ringwald uint16_t pseudo_dst = virtual_address->pseudo_dst; 100884242f88SMatthias Ringwald test_send_access_message(netkey_index, appkey_index, ttl, src, pseudo_dst, szmic, message22_upper_transport_pdu, 1, message22_lower_transport_pdus, message22_network_pdus); 100984242f88SMatthias Ringwald } 101084242f88SMatthias Ringwald 101184242f88SMatthias Ringwald // Message 23 101284242f88SMatthias Ringwald char * message23_network_pdus[] = { 101384242f88SMatthias Ringwald (char *) "e877a48dd5fe2d7a9d696d3dd16a75489696f0b70c711b881385", 101484242f88SMatthias Ringwald }; 101584242f88SMatthias Ringwald char * message23_lower_transport_pdus[] = { 101684242f88SMatthias Ringwald (char *) "662456db5e3100eef65daa7a38", 101784242f88SMatthias Ringwald }; 101884242f88SMatthias Ringwald char * message23_upper_transport_pdu = (char *) "d50a0048656c6c6f"; 101984242f88SMatthias Ringwald char * message23_label_string = (char *) "f4a002c7fb1e4ca0a469a021de0db875"; 102084242f88SMatthias Ringwald 102184242f88SMatthias Ringwald TEST(MessageTest, Message23Receive){ 102284242f88SMatthias Ringwald load_network_key_nid_68(); 102384242f88SMatthias Ringwald mesh_set_iv_index(0x12345677); 102484242f88SMatthias Ringwald uint8_t label_uuid[16]; 102584242f88SMatthias Ringwald btstack_parse_hex(message23_label_string, 16, label_uuid); 102684242f88SMatthias Ringwald mesh_virtual_address_register(label_uuid, 0x9736); 102784242f88SMatthias Ringwald test_receive_network_pdus(1, message23_network_pdus, message23_lower_transport_pdus, message23_upper_transport_pdu); 102884242f88SMatthias Ringwald } 102984242f88SMatthias Ringwald TEST(MessageTest, Message23Send){ 103084242f88SMatthias Ringwald uint16_t netkey_index = 0; 103184242f88SMatthias Ringwald uint16_t appkey_index = 0; 103284242f88SMatthias Ringwald uint8_t ttl = 3; 103384242f88SMatthias Ringwald uint16_t src = 0x1234; 103484242f88SMatthias Ringwald uint32_t seq = 0x07080c; 103584242f88SMatthias Ringwald uint8_t szmic = 0; 103684242f88SMatthias Ringwald 103784242f88SMatthias Ringwald load_network_key_nid_68(); 103884242f88SMatthias Ringwald mesh_set_iv_index(0x12345677); 103984242f88SMatthias Ringwald mesh_sequence_number_set(seq); 104084242f88SMatthias Ringwald uint8_t label_uuid[16]; 104184242f88SMatthias Ringwald btstack_parse_hex(message23_label_string, 16, label_uuid); 104284242f88SMatthias Ringwald mesh_virtual_address_t * virtual_address = mesh_virtual_address_register(label_uuid, 0x9736); 104384242f88SMatthias Ringwald uint16_t pseudo_dst = virtual_address->pseudo_dst; 104484242f88SMatthias Ringwald test_send_access_message(netkey_index, appkey_index, ttl, src, pseudo_dst, szmic, message23_upper_transport_pdu, 1, message23_lower_transport_pdus, message23_network_pdus); 104584242f88SMatthias Ringwald } 104684242f88SMatthias Ringwald #endif 104784242f88SMatthias Ringwald 104884242f88SMatthias Ringwald // Message 24 104984242f88SMatthias Ringwald char * message24_network_pdus[] = { 105084242f88SMatthias Ringwald (char *) "e8624e65bb8c1794e998b4081f47a35251fdd3896d99e4db489b918599", 105184242f88SMatthias Ringwald (char *) "e8a7d0f0a2ea42dc2f4dd6fb4db33a6c088d023b47", 105284242f88SMatthias Ringwald }; 105384242f88SMatthias Ringwald char * message24_lower_transport_pdus[] = { 105484242f88SMatthias Ringwald (char *) "e6a03401c3c51d8e476b28e3aa5001f3", 105584242f88SMatthias Ringwald (char *) "e6a034211c01cea6", 105684242f88SMatthias Ringwald }; 105784242f88SMatthias Ringwald char * message24_upper_transport_pdu = (char *) "ea0a00576f726c64"; 105884242f88SMatthias Ringwald char * message24_label_string = (char *) "f4a002c7fb1e4ca0a469a021de0db875"; 105984242f88SMatthias Ringwald TEST(MessageTest, Message24Receive){ 106084242f88SMatthias Ringwald load_network_key_nid_68(); 106184242f88SMatthias Ringwald mesh_set_iv_index(0x12345677); 106284242f88SMatthias Ringwald uint8_t label_uuid[16]; 106384242f88SMatthias Ringwald btstack_parse_hex(message24_label_string, 16, label_uuid); 106484242f88SMatthias Ringwald mesh_virtual_address_register(label_uuid, 0x9736); 106584242f88SMatthias Ringwald test_receive_network_pdus(2, message24_network_pdus, message24_lower_transport_pdus, message24_upper_transport_pdu); 106684242f88SMatthias Ringwald } 106784242f88SMatthias Ringwald TEST(MessageTest, Message24Send){ 106884242f88SMatthias Ringwald uint16_t netkey_index = 0; 106984242f88SMatthias Ringwald uint16_t appkey_index = 0; 107084242f88SMatthias Ringwald uint8_t ttl = 3; 107184242f88SMatthias Ringwald uint16_t src = 0x1234; 107284242f88SMatthias Ringwald uint32_t seq = 0x07080d; 107384242f88SMatthias Ringwald uint8_t szmic = 1; 107484242f88SMatthias Ringwald 107584242f88SMatthias Ringwald load_network_key_nid_68(); 107684242f88SMatthias Ringwald mesh_set_iv_index(0x12345677); 107784242f88SMatthias Ringwald mesh_sequence_number_set(seq); 107884242f88SMatthias Ringwald uint8_t label_uuid[16]; 107984242f88SMatthias Ringwald btstack_parse_hex(message24_label_string, 16, label_uuid); 108084242f88SMatthias Ringwald mesh_virtual_address_t * virtual_address = mesh_virtual_address_register(label_uuid, 0x9736); 108184242f88SMatthias Ringwald uint16_t pseudo_dst = virtual_address->pseudo_dst; 108284242f88SMatthias Ringwald test_send_access_message(netkey_index, appkey_index, ttl, src, pseudo_dst, szmic, message24_upper_transport_pdu, 2, message24_lower_transport_pdus, message24_network_pdus); 108384242f88SMatthias Ringwald } 108484242f88SMatthias Ringwald 108584242f88SMatthias Ringwald // Proxy Configuration Test 108684242f88SMatthias Ringwald char * proxy_config_pdus[] = { 108784242f88SMatthias Ringwald (char *) "0210386bd60efbbb8b8c28512e792d3711f4b526", 108884242f88SMatthias Ringwald }; 108984242f88SMatthias Ringwald char * proxy_config_lower_transport_pdus[] = { 109084242f88SMatthias Ringwald (char *) "0000", 109184242f88SMatthias Ringwald }; 109284242f88SMatthias Ringwald char * proxy_config_upper_transport_pdu = (char *) "ea0a00576f726c64"; 109384242f88SMatthias Ringwald TEST(MessageTest, ProxyConfigReceive){ 109484242f88SMatthias Ringwald mesh_set_iv_index(0x12345678); 109584242f88SMatthias Ringwald load_network_key_nid_10(); 109684242f88SMatthias Ringwald int i = 0; 109784242f88SMatthias Ringwald char ** network_pdus = proxy_config_pdus; 109884242f88SMatthias Ringwald test_network_pdu_len = strlen(network_pdus[i]) / 2; 109984242f88SMatthias Ringwald btstack_parse_hex(network_pdus[i], test_network_pdu_len, test_network_pdu_data); 110084242f88SMatthias Ringwald mesh_network_process_proxy_configuration_message(&test_network_pdu_data[1], test_network_pdu_len-1); 110184242f88SMatthias Ringwald while (received_proxy_pdu == NULL) { 110284242f88SMatthias Ringwald mock_process_hci_cmd(); 110384242f88SMatthias Ringwald } 110484242f88SMatthias Ringwald char ** lower_transport_pdus = proxy_config_lower_transport_pdus; 110584242f88SMatthias Ringwald transport_pdu_len = strlen(lower_transport_pdus[i]) / 2; 110684242f88SMatthias Ringwald btstack_parse_hex(lower_transport_pdus[i], transport_pdu_len, transport_pdu_data); 110784242f88SMatthias Ringwald 110884242f88SMatthias Ringwald uint8_t * lower_transport_pdu = mesh_network_pdu_data(received_proxy_pdu); 110984242f88SMatthias Ringwald uint8_t lower_transport_pdu_len = mesh_network_pdu_len(received_proxy_pdu); 111084242f88SMatthias Ringwald 111184242f88SMatthias Ringwald // printf_hexdump(lower_transport_pdu, lower_transport_pdu_len); 111284242f88SMatthias Ringwald 111384242f88SMatthias Ringwald CHECK_EQUAL( transport_pdu_len, lower_transport_pdu_len); 111484242f88SMatthias Ringwald CHECK_EQUAL_ARRAY(transport_pdu_data, lower_transport_pdu, transport_pdu_len); 111584242f88SMatthias Ringwald 111684242f88SMatthias Ringwald // done 111784242f88SMatthias Ringwald mesh_network_message_processed_by_higher_layer(received_proxy_pdu); 111884242f88SMatthias Ringwald received_proxy_pdu = NULL; 111984242f88SMatthias Ringwald } 112084242f88SMatthias Ringwald 112184242f88SMatthias Ringwald 112284242f88SMatthias Ringwald TEST(MessageTest, ProxyConfigSend){ 112384242f88SMatthias Ringwald uint16_t netkey_index = 0; 112484242f88SMatthias Ringwald uint8_t ctl = 1; 112584242f88SMatthias Ringwald uint8_t ttl = 0; 112684242f88SMatthias Ringwald uint16_t src = 1; 112784242f88SMatthias Ringwald uint16_t dest = 0; 112884242f88SMatthias Ringwald uint32_t seq = 1; 112984242f88SMatthias Ringwald uint8_t nid = 0x10; 113084242f88SMatthias Ringwald mesh_set_iv_index(0x12345678); 113184242f88SMatthias Ringwald load_network_key_nid_10(); 113284242f88SMatthias Ringwald mesh_network_pdu_t * network_pdu = mesh_network_pdu_get(); 113384242f88SMatthias Ringwald uint8_t data[] = { 0 , 0 }; 113484242f88SMatthias Ringwald mesh_network_setup_pdu(network_pdu, netkey_index, nid, ctl, ttl, seq, src, dest, data, sizeof(data)); 11351aa2a11eSMatthias Ringwald mesh_network_encrypt_proxy_configuration_message(network_pdu); 113684242f88SMatthias Ringwald while (received_proxy_pdu == NULL) { 113784242f88SMatthias Ringwald mock_process_hci_cmd(); 113884242f88SMatthias Ringwald } 113984242f88SMatthias Ringwald uint8_t * proxy_pdu_data = received_proxy_pdu->data; 114084242f88SMatthias Ringwald uint8_t proxy_pdu_len = received_proxy_pdu->len; 114184242f88SMatthias Ringwald 114284242f88SMatthias Ringwald int i = 0; 114384242f88SMatthias Ringwald char ** network_pdus = proxy_config_pdus; 114484242f88SMatthias Ringwald transport_pdu_len = strlen(network_pdus[i]) / 2; 114584242f88SMatthias Ringwald btstack_parse_hex(network_pdus[i], transport_pdu_len, transport_pdu_data); 114684242f88SMatthias Ringwald 114784242f88SMatthias Ringwald CHECK_EQUAL( transport_pdu_len-1, proxy_pdu_len); 114884242f88SMatthias Ringwald CHECK_EQUAL_ARRAY(transport_pdu_data+1, proxy_pdu_data, transport_pdu_len-1); 114984242f88SMatthias Ringwald 115084242f88SMatthias Ringwald received_proxy_pdu = NULL; 115184242f88SMatthias Ringwald 115284242f88SMatthias Ringwald mesh_network_pdu_free(network_pdu); 115384242f88SMatthias Ringwald } 115484242f88SMatthias Ringwald 115584242f88SMatthias Ringwald static btstack_crypto_aes128_t crypto_request_aes128; 115684242f88SMatthias Ringwald static uint8_t plaintext[16]; 115784242f88SMatthias Ringwald static uint8_t identity_key[16]; 115884242f88SMatthias Ringwald static uint8_t hash[16]; 115984242f88SMatthias Ringwald static uint8_t random_value[8]; 116084242f88SMatthias Ringwald 116184242f88SMatthias Ringwald static void mesh_proxy_handle_get_aes128(void * arg){ 116284242f88SMatthias Ringwald UNUSED(arg); 116384242f88SMatthias Ringwald uint8_t expected_hash[8]; 116484242f88SMatthias Ringwald uint8_t expected_random_value[8]; 116584242f88SMatthias Ringwald 116684242f88SMatthias Ringwald btstack_parse_hex("00861765aefcc57b", 8, expected_hash); 116784242f88SMatthias Ringwald CHECK_EQUAL_ARRAY(&hash[8], expected_hash, 8); 116884242f88SMatthias Ringwald 116984242f88SMatthias Ringwald btstack_parse_hex("34ae608fbbc1f2c6", 8, expected_random_value); 117084242f88SMatthias Ringwald CHECK_EQUAL_ARRAY(random_value, expected_random_value, 8); 117184242f88SMatthias Ringwald } 117284242f88SMatthias Ringwald 117384242f88SMatthias Ringwald TEST(MessageTest, ServiceDataUsingNodeIdentityTest){ 117484242f88SMatthias Ringwald btstack_parse_hex("34ae608fbbc1f2c6", 8, random_value); 117584242f88SMatthias Ringwald memset(plaintext, 0, sizeof(plaintext)); 117684242f88SMatthias Ringwald memcpy(&plaintext[6] , random_value, 8); 117784242f88SMatthias Ringwald big_endian_store_16(plaintext, 14, 0x1201); 117884242f88SMatthias Ringwald // 84396c435ac48560b5965385253e210c 117984242f88SMatthias Ringwald btstack_parse_hex("84396c435ac48560b5965385253e210c", 16, identity_key); 118084242f88SMatthias Ringwald btstack_crypto_aes128_encrypt(&crypto_request_aes128, identity_key, plaintext, hash, mesh_proxy_handle_get_aes128, NULL); 118184242f88SMatthias Ringwald } 118284242f88SMatthias Ringwald 118384242f88SMatthias Ringwald // Mesh v1.0, 8.2.1 118484242f88SMatthias Ringwald static btstack_crypto_aes128_cmac_t aes_cmac_request; 118584242f88SMatthias Ringwald static uint8_t k4_result[1]; 118684242f88SMatthias Ringwald static void handle_k4_result(void *arg){ 118784242f88SMatthias Ringwald printf("ApplicationkeyIDTest: %02x\n", k4_result[0]); 118884242f88SMatthias Ringwald CHECK_EQUAL( 0x26, k4_result[0]); 118984242f88SMatthias Ringwald } 119084242f88SMatthias Ringwald TEST(MessageTest, ApplicationkeyIDTest){ 119184242f88SMatthias Ringwald static uint8_t application_key[16]; 119284242f88SMatthias Ringwald btstack_parse_hex("63964771734fbd76e3b40519d1d94a48", 16, application_key); 119384242f88SMatthias Ringwald mesh_k4(&aes_cmac_request, application_key, &k4_result[0], &handle_k4_result, NULL); 119484242f88SMatthias Ringwald } 119584242f88SMatthias Ringwald 119684242f88SMatthias Ringwald int main (int argc, const char * argv[]){ 119784242f88SMatthias Ringwald return CommandLineTestRunner::RunAllTests(argc, argv); 119884242f88SMatthias Ringwald } 1199