mesh: deliver encrypted proxy message with MESH_NETWORK_PDU_ENCRYPTED and remove callback from mesh_network_t

This commit is contained in:
Matthias Ringwald 2020-03-11 18:17:10 +01:00
parent bb588228df
commit 1aa2a11e65
4 changed files with 34 additions and 17 deletions

View File

@ -307,7 +307,23 @@ static void mesh_network_send_c(void *arg){
// done // done
mesh_network_pdu_t * network_pdu = outgoing_pdu; mesh_network_pdu_t * network_pdu = outgoing_pdu;
outgoing_pdu = NULL; outgoing_pdu = NULL;
(network_pdu->callback)(network_pdu);
if ((network_pdu->flags & MESH_NETWORK_PDU_FLAGS_PROXY_CONFIGURATION) != 0){
// encryption requested by mesh_network_encrypt_proxy_configuration_message
(*mesh_network_proxy_message_handler)(MESH_NETWORK_PDU_ENCRYPTED, network_pdu);
return;
}
#ifdef LOG_NETWORK
printf("TX-D-NetworkPDU (%p): ", network_pdu);
printf_hexdump(network_pdu->data, network_pdu->len);
#endif
// add to queue
btstack_linked_list_add_tail(&network_pdus_outgoing_gatt, (btstack_linked_item_t *) network_pdu);
// go
mesh_network_run();
} }
static void mesh_network_send_b(void *arg){ static void mesh_network_send_b(void *arg){
@ -410,7 +426,6 @@ static void mesh_network_relay_message(mesh_network_pdu_t * network_pdu){
network_pdu->flags |= MESH_NETWORK_PDU_FLAGS_RELAY; network_pdu->flags |= MESH_NETWORK_PDU_FLAGS_RELAY;
// queue up // queue up
network_pdu->callback = &mesh_network_send_d;
btstack_linked_list_add_tail(&network_pdus_queued, (btstack_linked_item_t *) network_pdu); btstack_linked_list_add_tail(&network_pdus_queued, (btstack_linked_item_t *) network_pdu);
} }
#endif #endif
@ -433,7 +448,7 @@ void mesh_network_message_processed_by_higher_layer(mesh_network_pdu_t * network
#ifdef ENABLE_MESH_RELAY #ifdef ENABLE_MESH_RELAY
if (mesh_foundation_relay_get() != 0){ if (mesh_foundation_relay_get() != 0){
// - to ADV bearer, if Relay supported and enabled // - to ADV bearer, if Relay supported and enabledx
mesh_network_relay_message(network_pdu); mesh_network_relay_message(network_pdu);
mesh_network_run(); mesh_network_run();
return; return;
@ -1057,7 +1072,6 @@ void mesh_network_send_pdu(mesh_network_pdu_t * network_pdu){
btstack_assert(network_pdu->len >= 9); btstack_assert(network_pdu->len >= 9);
// setup callback // setup callback
network_pdu->callback = &mesh_network_send_d;
network_pdu->flags = 0; network_pdu->flags = 0;
// queue up // queue up
@ -1069,13 +1083,15 @@ void mesh_network_send_pdu(mesh_network_pdu_t * network_pdu){
// go // go
mesh_network_run(); mesh_network_run();
} }
static void mesh_network_encrypt_proxy_configuration_encrypted(mesh_network_pdu_t * network_pdu){
(*mesh_network_proxy_message_handler)(MESH_NETWORK_PDU_ENCRYPTED, network_pdu);
}
void mesh_network_encrypt_proxy_configuration_message(mesh_network_pdu_t * network_pdu, void (* callback)(mesh_network_pdu_t * callback)){ void mesh_network_encrypt_proxy_configuration_message(mesh_network_pdu_t * network_pdu){
printf("ProxyPDU(unencrypted): "); printf("ProxyPDU(unencrypted): ");
printf_hexdump(network_pdu->data, network_pdu->len); printf_hexdump(network_pdu->data, network_pdu->len);
// setup callback // setup callback
network_pdu->callback = callback;
network_pdu->flags = MESH_NETWORK_PDU_FLAGS_PROXY_CONFIGURATION; network_pdu->flags = MESH_NETWORK_PDU_FLAGS_PROXY_CONFIGURATION;
// queue up // queue up

View File

@ -62,6 +62,7 @@ extern "C" {
typedef enum { typedef enum {
MESH_NETWORK_PDU_RECEIVED, MESH_NETWORK_PDU_RECEIVED,
MESH_NETWORK_PDU_SENT, MESH_NETWORK_PDU_SENT,
MESH_NETWORK_PDU_ENCRYPTED,
MESH_NETWORK_CAN_SEND_NOW, MESH_NETWORK_CAN_SEND_NOW,
} mesh_network_callback_type_t; } mesh_network_callback_type_t;
@ -87,9 +88,6 @@ typedef struct mesh_pdu {
typedef struct mesh_network_pdu { typedef struct mesh_network_pdu {
mesh_pdu_t pdu_header; mesh_pdu_t pdu_header;
// callback
void (*callback)(struct mesh_network_pdu * network_pdu);
// meta data network layer // meta data network layer
uint16_t netkey_index; uint16_t netkey_index;
// MESH_NETWORK_PDU_FLAGS // MESH_NETWORK_PDU_FLAGS
@ -427,7 +425,7 @@ void mesh_network_pdu_set_seq(mesh_network_pdu_t * network_pdu, uint32_t seq);
// Testing only // Testing only
void mesh_network_received_message(const uint8_t * pdu_data, uint8_t pdu_len, uint8_t flags); void mesh_network_received_message(const uint8_t * pdu_data, uint8_t pdu_len, uint8_t flags);
void mesh_network_process_proxy_configuration_message(const uint8_t * pdu_data, uint8_t pdu_len); void mesh_network_process_proxy_configuration_message(const uint8_t * pdu_data, uint8_t pdu_len);
void mesh_network_encrypt_proxy_configuration_message(mesh_network_pdu_t * network_pdu, void (* callback)(mesh_network_pdu_t * callback)); void mesh_network_encrypt_proxy_configuration_message(mesh_network_pdu_t * network_pdu);
void mesh_network_dump(void); void mesh_network_dump(void);
void mesh_network_reset(void); void mesh_network_reset(void);

View File

@ -381,7 +381,7 @@ static void proxy_configuration_message_handler(mesh_network_callback_type_t cal
big_endian_store_16(data, pos, proxy_configuration_filter_list_len); big_endian_store_16(data, pos, proxy_configuration_filter_list_len);
mesh_network_setup_pdu(network_pdu, netkey_index, nid, ctl, ttl, seq, src, dest, data, sizeof(data)); mesh_network_setup_pdu(network_pdu, netkey_index, nid, ctl, ttl, seq, src, dest, data, sizeof(data));
mesh_network_encrypt_proxy_configuration_message(network_pdu, &request_can_send_now_proxy_configuration_callback_handler); mesh_network_encrypt_proxy_configuration_message(network_pdu);
// received_network_pdu is processed // received_network_pdu is processed
btstack_memory_mesh_network_pdu_free(received_network_pdu); btstack_memory_mesh_network_pdu_free(received_network_pdu);
@ -401,6 +401,9 @@ static void proxy_configuration_message_handler(mesh_network_callback_type_t cal
// printf("test MESH_PROXY_PDU_SENT\n"); // printf("test MESH_PROXY_PDU_SENT\n");
// mesh_lower_transport_received_mesage(MESH_NETWORK_PDU_SENT, network_pdu); // mesh_lower_transport_received_mesage(MESH_NETWORK_PDU_SENT, network_pdu);
break; break;
case MESH_NETWORK_PDU_ENCRYPTED:
request_can_send_now_proxy_configuration_callback_handler(network_pdu);
break;
default: default:
break; break;
} }

View File

@ -242,13 +242,17 @@ static void test_lower_transport_callback_handler(mesh_network_callback_type_t c
static void test_proxy_server_callback_handler(mesh_network_callback_type_t callback_type, mesh_network_pdu_t * network_pdu){ static void test_proxy_server_callback_handler(mesh_network_callback_type_t callback_type, mesh_network_pdu_t * network_pdu){
switch (callback_type){ switch (callback_type){
case MESH_NETWORK_PDU_RECEIVED: case MESH_NETWORK_PDU_RECEIVED:
printf("test MESH_PROXY_PDU_RECEIVED\n"); printf("test MESH_PROXY_PDU_RECEIVED\n");
received_proxy_pdu = network_pdu; received_proxy_pdu = network_pdu;
break; break;
case MESH_NETWORK_PDU_SENT: case MESH_NETWORK_PDU_SENT:
// printf("test MESH_PROXY_PDU_SENT\n"); // printf("test MESH_PROXY_PDU_SENT\n");
// mesh_lower_transport_received_mesage(MESH_NETWORK_PDU_SENT, network_pdu); // mesh_lower_transport_received_mesage(MESH_NETWORK_PDU_SENT, network_pdu);
break; break;
case MESH_NETWORK_PDU_ENCRYPTED:
printf("test MESH_NETWORK_PDU_ENCRYPTED\n");
received_proxy_pdu = network_pdu;
break;
default: default:
break; break;
} }
@ -1089,10 +1093,6 @@ TEST(MessageTest, ProxyConfigReceive){
received_proxy_pdu = NULL; received_proxy_pdu = NULL;
} }
static void test_proxy_callback_handler(mesh_network_pdu_t * network_pdu){
received_proxy_pdu = network_pdu;
}
TEST(MessageTest, ProxyConfigSend){ TEST(MessageTest, ProxyConfigSend){
uint16_t netkey_index = 0; uint16_t netkey_index = 0;
@ -1107,7 +1107,7 @@ TEST(MessageTest, ProxyConfigSend){
mesh_network_pdu_t * network_pdu = mesh_network_pdu_get(); mesh_network_pdu_t * network_pdu = mesh_network_pdu_get();
uint8_t data[] = { 0 , 0 }; uint8_t data[] = { 0 , 0 };
mesh_network_setup_pdu(network_pdu, netkey_index, nid, ctl, ttl, seq, src, dest, data, sizeof(data)); mesh_network_setup_pdu(network_pdu, netkey_index, nid, ctl, ttl, seq, src, dest, data, sizeof(data));
mesh_network_encrypt_proxy_configuration_message(network_pdu, &test_proxy_callback_handler); mesh_network_encrypt_proxy_configuration_message(network_pdu);
while (received_proxy_pdu == NULL) { while (received_proxy_pdu == NULL) {
mock_process_hci_cmd(); mock_process_hci_cmd();
} }