mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-02-03 20:54:18 +00:00
mesh: add pb_adv_cid to pb_adv_send_pdu
This commit is contained in:
parent
323c8bf909
commit
beeedc4565
@ -276,7 +276,7 @@ static uint16_t buffer_offset;
|
||||
static mesh_msg_sar_field_t buffer_state;
|
||||
static uint16_t pb_gatt_mtu;
|
||||
|
||||
void pb_adv_send_pdu(const uint8_t * pdu, uint16_t size){
|
||||
void pb_adv_send_pdu(uint16_t pb_adv_cid, const uint8_t * pdu, uint16_t size){
|
||||
if (!pdu || size <= 0) return;
|
||||
// store pdu, request to send
|
||||
printf_hexdump(pdu, size);
|
||||
|
@ -559,7 +559,8 @@ void pb_adv_register_packet_handler(btstack_packet_handler_t packet_handler){
|
||||
pb_adv_packet_handler = packet_handler;
|
||||
}
|
||||
|
||||
void pb_adv_send_pdu(const uint8_t * pdu, uint16_t size){
|
||||
void pb_adv_send_pdu(uint16_t pb_adv_cid, const uint8_t * pdu, uint16_t size){
|
||||
UNUSED(pb_adv_cid);
|
||||
printf("PB-ADV: Send packet ");
|
||||
printf_hexdump(pdu, size);
|
||||
pb_adv_msg_out_buffer = pdu;
|
||||
|
@ -60,8 +60,11 @@ void pb_adv_register_packet_handler(btstack_packet_handler_t packet_handler);
|
||||
|
||||
/**
|
||||
* Send Provisioning PDU
|
||||
* @param pb_adv_cid
|
||||
* @param pdu
|
||||
* @param pb_adv_cid
|
||||
*/
|
||||
void pb_adv_send_pdu(const uint8_t * pdu, uint16_t size);
|
||||
void pb_adv_send_pdu(uint16_t pb_adv_cid, const uint8_t * pdu, uint16_t pdu_size);
|
||||
|
||||
/**
|
||||
* Close Link
|
||||
|
@ -64,6 +64,8 @@ static int counter = 'a';
|
||||
|
||||
static uint8_t mesh_flags;
|
||||
|
||||
static uint16_t pb_transport_cid = MESH_PB_TRANSPORT_INVALID_CID;
|
||||
|
||||
// pin entry
|
||||
static int ui_chars_for_pin;
|
||||
static uint8_t ui_pin[17];
|
||||
@ -159,6 +161,10 @@ static void mesh_message_handler (uint8_t packet_type, uint16_t channel, uint8_t
|
||||
switch(packet[2]){
|
||||
case MESH_PB_ADV_LINK_OPEN:
|
||||
printf("Provisioner link opened");
|
||||
pb_transport_cid = mesh_pb_adv_link_open_event_get_pb_adv_cid(packet);
|
||||
break;
|
||||
case MESH_PB_ADV_LINK_CLOSED:
|
||||
pb_transport_cid = MESH_PB_TRANSPORT_INVALID_CID;
|
||||
break;
|
||||
case MESH_PB_PROV_ATTENTION_TIMER:
|
||||
printf("Attention Timer: %u\n", packet[3]);
|
||||
@ -1108,17 +1114,17 @@ static void stdin_process(char cmd){
|
||||
break;
|
||||
case '4':
|
||||
printf("Send invite with attention timer = 0\n");
|
||||
pb_adv_send_pdu(adv_prov_invite_pdu, sizeof(adv_prov_invite_pdu));
|
||||
pb_adv_send_pdu(pb_transport_cid, adv_prov_invite_pdu, sizeof(adv_prov_invite_pdu));
|
||||
break;
|
||||
case '5':
|
||||
printf("Send Start\n");
|
||||
pb_adv_send_pdu(adv_prov_start_pdu, sizeof(adv_prov_start_pdu));
|
||||
pb_adv_send_pdu(pb_transport_cid, adv_prov_start_pdu, sizeof(adv_prov_start_pdu));
|
||||
break;
|
||||
case '6':
|
||||
printf("Send Public key\n");
|
||||
adv_prov_public_key_pdu[0] = 0x03;
|
||||
memset(&adv_prov_public_key_pdu[1], 0x5a, 64);
|
||||
pb_adv_send_pdu(adv_prov_public_key_pdu, sizeof(adv_prov_public_key_pdu));
|
||||
pb_adv_send_pdu(pb_transport_cid, adv_prov_public_key_pdu, sizeof(adv_prov_public_key_pdu));
|
||||
break;
|
||||
case 'p':
|
||||
printf("+ Public Key OOB Enabled\n");
|
||||
@ -1183,7 +1189,7 @@ int btstack_main(void)
|
||||
// Network layer
|
||||
mesh_network_init();
|
||||
mesh_network_set_higher_layer_handler(&mesh_transport_received_mesage);
|
||||
|
||||
|
||||
// PTS app key
|
||||
uint8_t application_key[16];
|
||||
const char * application_key_string = "3216D1509884B533248541792B877F98";
|
||||
|
@ -51,8 +51,10 @@ extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#define PROVISIONING_PROTOCOL_TIMEOUT_MS 60000
|
||||
#define MESH_PROV_MAX_PROXY_PDU 66
|
||||
#define PROVISIONING_PROTOCOL_TIMEOUT_MS 60000
|
||||
#define MESH_PROV_MAX_PROXY_PDU 66
|
||||
#define MESH_PB_TRANSPORT_INVALID_CID 0xFFFF
|
||||
|
||||
// Provisioning Bearer Control
|
||||
|
||||
#define MESH_PROV_INVITE 0x00
|
||||
|
@ -155,7 +155,7 @@ typedef enum {
|
||||
} device_state_t;
|
||||
|
||||
static device_state_t device_state;
|
||||
|
||||
static uint16_t pb_transport_cid;
|
||||
// derived
|
||||
static uint8_t network_id[8];
|
||||
static uint8_t beacon_key[16];
|
||||
@ -224,7 +224,7 @@ 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(prov_buffer_out, 2);
|
||||
pb_adv_send_pdu(pb_transport_cid, prov_buffer_out, 2);
|
||||
}
|
||||
|
||||
static void provisioning_send_capabilites(void){
|
||||
@ -259,9 +259,18 @@ static void provisioning_send_capabilites(void){
|
||||
memcpy(&prov_confirmation_inputs[1], &prov_buffer_out[1], 11);
|
||||
|
||||
// send
|
||||
pb_adv_send_pdu(prov_buffer_out, 12);
|
||||
|
||||
pb_adv_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;
|
||||
@ -271,7 +280,7 @@ static void provisioning_send_public_key(void){
|
||||
memcpy(&prov_confirmation_inputs[81], &prov_buffer_out[1], 64);
|
||||
|
||||
// send
|
||||
pb_adv_send_pdu(prov_buffer_out, 65);
|
||||
pb_adv_send_pdu(pb_transport_cid, prov_buffer_out, 65);
|
||||
}
|
||||
|
||||
static void provisioning_send_input_complete(void){
|
||||
@ -279,7 +288,7 @@ static void provisioning_send_input_complete(void){
|
||||
prov_buffer_out[0] = MESH_PROV_INPUT_COMPLETE;
|
||||
|
||||
// send
|
||||
pb_adv_send_pdu(prov_buffer_out, 17);
|
||||
pb_adv_send_pdu(pb_transport_cid, prov_buffer_out, 17);
|
||||
}
|
||||
static void provisioning_send_confirm(void){
|
||||
// setup response
|
||||
@ -287,7 +296,7 @@ static void provisioning_send_confirm(void){
|
||||
memcpy(&prov_buffer_out[1], confirmation_device, 16);
|
||||
|
||||
// send
|
||||
pb_adv_send_pdu(prov_buffer_out, 17);
|
||||
pb_adv_send_pdu(pb_transport_cid, prov_buffer_out, 17);
|
||||
}
|
||||
|
||||
static void provisioning_send_random(void){
|
||||
@ -296,7 +305,7 @@ static void provisioning_send_random(void){
|
||||
memcpy(&prov_buffer_out[1], random_device, 16);
|
||||
|
||||
// send pdu
|
||||
pb_adv_send_pdu(prov_buffer_out, 17);
|
||||
pb_adv_send_pdu(pb_transport_cid, prov_buffer_out, 17);
|
||||
}
|
||||
|
||||
static void provisioning_send_complete(void){
|
||||
@ -304,7 +313,7 @@ static void provisioning_send_complete(void){
|
||||
prov_buffer_out[0] = MESH_PROV_COMPLETE;
|
||||
|
||||
// send pdu
|
||||
pb_adv_send_pdu(prov_buffer_out, 1);
|
||||
pb_adv_send_pdu(pb_transport_cid, prov_buffer_out, 1);
|
||||
}
|
||||
|
||||
static void provisioning_done(void){
|
||||
@ -765,6 +774,7 @@ static void provisioning_handle_pdu(uint8_t packet_type, uint16_t channel, uint8
|
||||
switch (packet[2]){
|
||||
case MESH_PB_ADV_LINK_OPEN:
|
||||
printf("Link opened, reset state\n");
|
||||
pb_transport_cid = mesh_pb_adv_link_open_event_get_pb_adv_cid(packet);
|
||||
provisioning_done();
|
||||
break;
|
||||
case MESH_PB_ADV_PDU_SENT:
|
||||
@ -773,6 +783,7 @@ static void provisioning_handle_pdu(uint8_t packet_type, uint16_t channel, uint8
|
||||
break;
|
||||
case MESH_PB_ADV_LINK_CLOSED:
|
||||
printf("Link close, reset state\n");
|
||||
pb_transport_cid = MESH_PB_TRANSPORT_INVALID_CID;
|
||||
provisioning_done();
|
||||
break;
|
||||
}
|
||||
@ -841,7 +852,8 @@ static void prov_key_generated(void * arg){
|
||||
void provisioning_device_init(const uint8_t * device_uuid){
|
||||
pb_adv_init(device_uuid);
|
||||
pb_adv_register_packet_handler(&provisioning_handle_pdu);
|
||||
|
||||
pb_transport_cid = MESH_PB_TRANSPORT_INVALID_CID;
|
||||
|
||||
// init provisioning state
|
||||
provisioning_done();
|
||||
|
||||
|
@ -119,7 +119,8 @@ void pb_adv_register_packet_handler(btstack_packet_handler_t packet_handler){
|
||||
/**
|
||||
* Send Provisioning PDU
|
||||
*/
|
||||
void pb_adv_send_pdu(const uint8_t * pdu, uint16_t size){
|
||||
void pb_adv_send_pdu(uint16_t pb_transport_cid, const uint8_t * pdu, uint16_t size){
|
||||
UNUSED(pb_transport_cid);
|
||||
pdu_data = (uint8_t*) pdu;
|
||||
pdu_size = size;
|
||||
// dump_data((uint8_t*)pdu,size);
|
||||
|
@ -180,7 +180,7 @@ static void provisioning_timer_stop(void){
|
||||
static void provisioning_send_invite(uint16_t pb_adv_cid){
|
||||
prov_buffer_out[0] = MESH_PROV_INVITE;
|
||||
prov_buffer_out[1] = prov_attention_timer;
|
||||
pb_adv_send_pdu(prov_buffer_out, 2);
|
||||
pb_adv_send_pdu(pb_adv_cid, prov_buffer_out, 2);
|
||||
// collect confirmation_inputs
|
||||
memcpy(&prov_confirmation_inputs[0], &prov_buffer_out[1], 1);
|
||||
}
|
||||
@ -192,7 +192,7 @@ static void provisioning_send_start(uint16_t pb_adv_cid){
|
||||
prov_buffer_out[3] = prov_start_authentication_method;
|
||||
prov_buffer_out[4] = prov_start_authentication_action;
|
||||
prov_buffer_out[5] = prov_start_authentication_size;
|
||||
pb_adv_send_pdu(prov_buffer_out, 6);
|
||||
pb_adv_send_pdu(pb_adv_cid, prov_buffer_out, 6);
|
||||
// store for confirmation inputs: len 5
|
||||
memcpy(&prov_confirmation_inputs[12], &prov_buffer_out[1], 5);
|
||||
}
|
||||
@ -200,13 +200,13 @@ static void provisioning_send_start(uint16_t pb_adv_cid){
|
||||
static void provisioning_send_provisioning_error(void){
|
||||
prov_buffer_out[0] = MESH_PROV_FAILED;
|
||||
prov_buffer_out[1] = prov_error_code;
|
||||
pb_adv_send_pdu(prov_buffer_out, 2);
|
||||
pb_adv_send_pdu(pb_adv_cid, prov_buffer_out, 2);
|
||||
}
|
||||
|
||||
static void provisioning_send_public_key(void){
|
||||
prov_buffer_out[0] = MESH_PROV_PUB_KEY;
|
||||
memcpy(&prov_buffer_out[1], prov_ec_q, 64);
|
||||
pb_adv_send_pdu(prov_buffer_out, 65);
|
||||
pb_adv_send_pdu(pb_adv_cid, prov_buffer_out, 65);
|
||||
// store for confirmation inputs: len 64
|
||||
memcpy(&prov_confirmation_inputs[17], &prov_buffer_out[1], 64);
|
||||
}
|
||||
@ -214,20 +214,20 @@ static void provisioning_send_public_key(void){
|
||||
static void provisioning_send_confirm(void){
|
||||
prov_buffer_out[0] = MESH_PROV_CONFIRM;
|
||||
memcpy(&prov_buffer_out[1], confirmation_provisioner, 16);
|
||||
pb_adv_send_pdu(prov_buffer_out, 17);
|
||||
pb_adv_send_pdu(pb_adv_cid, prov_buffer_out, 17);
|
||||
}
|
||||
|
||||
static void provisioning_send_random(void){
|
||||
prov_buffer_out[0] = MESH_PROV_RANDOM;
|
||||
memcpy(&prov_buffer_out[1], random_provisioner, 16);
|
||||
pb_adv_send_pdu(prov_buffer_out, 17);
|
||||
pb_adv_send_pdu(pb_adv_cid, prov_buffer_out, 17);
|
||||
}
|
||||
|
||||
static void provisioning_send_data(void){
|
||||
prov_buffer_out[0] = MESH_PROV_DATA;
|
||||
memcpy(&prov_buffer_out[1], enc_provisioning_data, 25);
|
||||
memcpy(&prov_buffer_out[26], provisioning_data_mic, 8);
|
||||
pb_adv_send_pdu(prov_buffer_out, 34);
|
||||
pb_adv_send_pdu(pb_adv_cid, prov_buffer_out, 34);
|
||||
}
|
||||
|
||||
typedef enum {
|
||||
@ -710,6 +710,7 @@ static void prov_key_generated(void * arg){
|
||||
}
|
||||
|
||||
void provisioning_provisioner_init(void){
|
||||
pb_adv_cid = MESH_PB_TRANSPORT_INVALID_CID;
|
||||
pb_adv_init(NULL);
|
||||
pb_adv_register_packet_handler(&provisioning_handle_pdu);
|
||||
}
|
||||
@ -722,7 +723,7 @@ uint16_t provisioning_provisioner_start_provisioning(const uint8_t * device_uuid
|
||||
// generate new public key
|
||||
btstack_crypto_ecc_p256_generate_key(&prov_ecc_p256_request, prov_ec_q, &prov_key_generated, NULL);
|
||||
|
||||
if (pb_adv_cid == 0) {
|
||||
if (pb_adv_cid == MESH_PB_TRANSPORT_INVALID_CID) {
|
||||
pb_adv_cid = pb_adv_create_link(device_uuid);
|
||||
}
|
||||
return pb_adv_cid;
|
||||
|
@ -118,7 +118,8 @@ void pb_adv_register_packet_handler(btstack_packet_handler_t packet_handler){
|
||||
pb_adv_packet_handler = packet_handler;
|
||||
}
|
||||
|
||||
void pb_adv_send_pdu(const uint8_t * pdu, uint16_t size){
|
||||
void pb_adv_send_pdu(uint16_t pb_transport_cid, const uint8_t * pdu, uint16_t size){
|
||||
UNUSED(pb_transport_cid);
|
||||
pdu_data = (uint8_t*) pdu;
|
||||
pdu_size = size;
|
||||
// dump_data((uint8_t*)pdu,size);
|
||||
|
Loading…
x
Reference in New Issue
Block a user