mesh: fix event len for MESH_PB_TRANSPORT_LINK_CLOSED/OPEN, store conn type in provisioning device, prepare dispatch

This commit is contained in:
Milanka Ringwald 2018-11-16 11:11:14 +01:00 committed by Matthias Ringwald
parent 26ecb6246e
commit 339c5cba81
4 changed files with 34 additions and 27 deletions

View File

@ -86,14 +86,14 @@ static hci_con_handle_t get_con_handle(void){
}
static void pb_adv_emit_link_open(hci_con_handle_t con_handle, uint8_t status){
uint8_t event[6] = { HCI_EVENT_MESH_META, 6, MESH_PB_TRANSPORT_LINK_OPEN, status, PB_TYPE_GATT};
uint8_t event[7] = { HCI_EVENT_MESH_META, 5, MESH_PB_TRANSPORT_LINK_OPEN, status};
little_endian_store_16(event, 4, con_handle);
event[5] = PB_TYPE_GATT;
event[6] = PB_TYPE_GATT;
mesh_provisioning_service_packet_handler(HCI_EVENT_PACKET, 0, event, sizeof(event));
}
static void pb_adv_emit_link_close(hci_con_handle_t con_handle, uint8_t reason){
uint8_t event[5] = { HCI_EVENT_MESH_META, 6, MESH_PB_TRANSPORT_LINK_CLOSED};
uint8_t event[5] = { HCI_EVENT_MESH_META, 3, MESH_PB_TRANSPORT_LINK_CLOSED};
little_endian_store_16(event, 4, con_handle);
mesh_provisioning_service_packet_handler(HCI_EVENT_PACKET, 0, event, sizeof(event));
}
@ -136,11 +136,12 @@ static int mesh_provisioning_service_write_callback(hci_con_handle_t con_handle,
return ATT_ERROR_INVALID_OFFSET;
}
instance->data_out_client_configuration_descriptor_value = little_endian_read_16(buffer, 0);
printf("mesh_provisioning_service_write_callback: data out notify enabled %d\n", instance->data_out_client_configuration_descriptor_value);
printf("mesh_provisioning_service_write_callback: data out notify enabled %d, con handle 0x%02x\n", instance->data_out_client_configuration_descriptor_value, con_handle);
if (instance->data_out_client_configuration_descriptor_value){
pb_adv_emit_link_close(con_handle, 0);
} else {
printf("mesh_provisioning_service_write_callback: emit pb_adv_emit_link_open 0x%02x\n", con_handle);
pb_adv_emit_link_open(con_handle, 0);
} else {
pb_adv_emit_link_close(con_handle, 0);
}
return 0;
}
@ -285,6 +286,7 @@ void pb_adv_send_pdu(uint16_t pb_adv_cid, const uint8_t * pdu, uint16_t size){
proxy_pdu_size = size;
buffer_offset = 0;
printf("pb_gatt_send_pdu received 0x%02x, used 0x%02x\n", pb_adv_cid, get_con_handle());
// check if segmentation is necessary
if (proxy_pdu_size > (pb_gatt_mtu - 1)){

View File

@ -139,14 +139,14 @@ static void pb_adv_emit_pdu_sent(uint8_t status){
}
static void pb_adv_emit_link_open(uint8_t status, uint16_t pb_adv_cid){
uint8_t event[6] = { HCI_EVENT_MESH_META, 6, MESH_PB_TRANSPORT_LINK_OPEN, status};
uint8_t event[7] = { HCI_EVENT_MESH_META, 5, MESH_PB_TRANSPORT_LINK_OPEN, status};
little_endian_store_16(event, 4, pb_adv_cid);
event[5] = PB_TYPE_ADV;
event[6] = PB_TYPE_ADV;
pb_adv_packet_handler(HCI_EVENT_PACKET, 0, event, sizeof(event));
}
static void pb_adv_emit_link_close(uint16_t pb_adv_cid, uint8_t reason){
uint8_t event[5] = { HCI_EVENT_MESH_META, 6, MESH_PB_TRANSPORT_LINK_CLOSED};
uint8_t event[5] = { HCI_EVENT_MESH_META, 3, MESH_PB_TRANSPORT_LINK_CLOSED};
little_endian_store_16(event, 4, pb_adv_cid);
pb_adv_packet_handler(HCI_EVENT_PACKET, 0, event, sizeof(event));
}

View File

@ -159,6 +159,7 @@ static uint16_t pb_transport_cid;
// derived
static uint8_t network_id[8];
static uint8_t beacon_key[16];
static pb_type_t pb_type;
static void provisioning_emit_event(uint16_t pb_adv_cid, uint8_t mesh_subevent){
if (!prov_packet_handler) return;
@ -220,11 +221,22 @@ static void provisioning_attention_timer_set(void){
// Outgoing Provisioning PDUs
static void pb_send_pdu(uint16_t transport_cid, const uint8_t * buffer, uint16_t buffer_size){
switch (pb_type){
case PB_TYPE_ADV:
pb_adv_send_pdu(transport_cid, buffer, buffer_size);
break;
case PB_TYPE_GATT:
pb_adv_send_pdu(transport_cid, buffer, buffer_size);
break;
}
}
static void provisioning_send_provisioning_error(void){
// setup response
prov_buffer_out[0] = MESH_PROV_FAILED;
prov_buffer_out[1] = prov_error_code;
pb_adv_send_pdu(pb_transport_cid, prov_buffer_out, 2);
pb_send_pdu(pb_transport_cid, prov_buffer_out, 2);
}
static void provisioning_send_capabilites(void){
@ -260,17 +272,9 @@ static void provisioning_send_capabilites(void){
// send
pb_adv_send_pdu(pb_transport_cid, prov_buffer_out, 12);
pb_send_pdu(pb_transport_cid, prov_buffer_out, 12);
}
// void pb_send_pdu(prov_buffer_out, 12){
// if (pb_use_gatt){
// pb_gatt_send_pdu(prov_buffer_out, 12);
// } else {
// pb_adv_send_pdu(pb_transport_cid, prov_buffer_out, 12);
// }
// }
static void provisioning_send_public_key(void){
// setup response
prov_buffer_out[0] = MESH_PROV_PUB_KEY;
@ -280,7 +284,7 @@ static void provisioning_send_public_key(void){
memcpy(&prov_confirmation_inputs[81], &prov_buffer_out[1], 64);
// send
pb_adv_send_pdu(pb_transport_cid, prov_buffer_out, 65);
pb_send_pdu(pb_transport_cid, prov_buffer_out, 65);
}
static void provisioning_send_input_complete(void){
@ -288,7 +292,7 @@ static void provisioning_send_input_complete(void){
prov_buffer_out[0] = MESH_PROV_INPUT_COMPLETE;
// send
pb_adv_send_pdu(pb_transport_cid, prov_buffer_out, 17);
pb_send_pdu(pb_transport_cid, prov_buffer_out, 17);
}
static void provisioning_send_confirm(void){
// setup response
@ -296,7 +300,7 @@ static void provisioning_send_confirm(void){
memcpy(&prov_buffer_out[1], confirmation_device, 16);
// send
pb_adv_send_pdu(pb_transport_cid, prov_buffer_out, 17);
pb_send_pdu(pb_transport_cid, prov_buffer_out, 17);
}
static void provisioning_send_random(void){
@ -305,7 +309,7 @@ static void provisioning_send_random(void){
memcpy(&prov_buffer_out[1], random_device, 16);
// send pdu
pb_adv_send_pdu(pb_transport_cid, prov_buffer_out, 17);
pb_send_pdu(pb_transport_cid, prov_buffer_out, 17);
}
static void provisioning_send_complete(void){
@ -313,7 +317,7 @@ static void provisioning_send_complete(void){
prov_buffer_out[0] = MESH_PROV_COMPLETE;
// send pdu
pb_adv_send_pdu(pb_transport_cid, prov_buffer_out, 1);
pb_send_pdu(pb_transport_cid, prov_buffer_out, 1);
}
static void provisioning_done(void){
@ -773,8 +777,9 @@ static void provisioning_handle_pdu(uint8_t packet_type, uint16_t channel, uint8
if (packet[0] != HCI_EVENT_MESH_META) break;
switch (packet[2]){
case MESH_PB_TRANSPORT_LINK_OPEN:
printf("Link opened, reset state\n");
pb_transport_cid = mesh_pb_transport_link_open_event_get_pb_transport_cid(packet);
pb_type = mesh_pb_transport_link_open_event_get_pb_type(packet);
printf("Link opened, reset state, transport cid 0x%02x, PB type %d\n", pb_transport_cid, pb_type);
provisioning_done();
break;
case MESH_PB_TRANSPORT_PDU_SENT:

View File

@ -97,9 +97,9 @@ static uint8_t * pdu_data;
static uint16_t pdu_size;
static void pb_adv_emit_link_open(uint8_t status, uint16_t pb_adv_cid){
uint8_t event[6] = { HCI_EVENT_MESH_META, 6, MESH_PB_TRANSPORT_LINK_OPEN, status};
uint8_t event[7] = { HCI_EVENT_MESH_META, 5, MESH_PB_TRANSPORT_LINK_OPEN, status};
little_endian_store_16(event, 4, pb_adv_cid);
event[5] = PB_TYPE_ADV;
event[6] = PB_TYPE_ADV;
pb_adv_packet_handler(HCI_EVENT_PACKET, 0, event, sizeof(event));
}