mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-03-31 19:20:26 +00:00
use bd_addr_to_str instead of print_bd_addr - and provide compat-svn.c to deal with fact that bd_addr_to_str is not in current Cydia release of BTstack
This commit is contained in:
parent
e67516028b
commit
7bba34d17e
14
example/compat-svn.c
Normal file
14
example/compat-svn.c
Normal file
@ -0,0 +1,14 @@
|
||||
/**
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <btstack/utils.h>
|
||||
|
||||
|
||||
static char new_bd_addr_to_str_buffer[6*3]; // 12:45:78:01:34:67\0
|
||||
static char * new_bd_addr_to_str(bd_addr_t addr){
|
||||
sprintf(new_bd_addr_to_str_buffer, "%02x:%02x:%02x:%02x:%02x:%02x", addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
|
||||
return (char *) new_bd_addr_to_str_buffer;
|
||||
}
|
||||
|
||||
#define bd_addr_to_str(x) new_bd_addr_to_str(x)
|
@ -42,6 +42,9 @@
|
||||
|
||||
#include <btstack/btstack.h>
|
||||
|
||||
// until next BTstack Cydia update
|
||||
#include "compat-svn.c"
|
||||
|
||||
#define MAX_DEVICES 10
|
||||
struct device {
|
||||
bd_addr_t address;
|
||||
@ -85,9 +88,7 @@ void next(void){
|
||||
if (devices[i].state == 1){
|
||||
found = 1;
|
||||
devices[i].state = 2;
|
||||
printf("Get remote name of ");
|
||||
print_bd_addr(devices[i].address);
|
||||
printf("...\n");
|
||||
printf("Get remote name of %s...\n", bd_addr_to_str(devices[i].address));
|
||||
bt_send_cmd(&hci_remote_name_request, devices[i].address,
|
||||
devices[i].pageScanRepetitionMode, 0, devices[i].clockOffset | 0x8000);
|
||||
break;
|
||||
@ -141,10 +142,8 @@ void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint
|
||||
devices[deviceCount].clockOffset = READ_BT_16(packet, 3 + numResponses*(6+1+1+1+3) + i*2) & 0x7fff;
|
||||
devices[deviceCount].rssi = 0;
|
||||
devices[deviceCount].state = 1;
|
||||
printf("Device found: ");
|
||||
print_bd_addr(addr);
|
||||
printf(" with COD: 0x%06x, pageScan %u, clock offset 0x%04x\n", devices[deviceCount].classOfDevice,
|
||||
devices[deviceCount].pageScanRepetitionMode, devices[deviceCount].clockOffset);
|
||||
printf("Device found: %s with COD: %x, pageScan %u, clock offset %x\n", bd_addr_to_str(addr), devices[deviceCount].classOfDevice,
|
||||
devices[deviceCount].pageScanRepetitionMode, devices[deviceCount].clockOffset);
|
||||
deviceCount++;
|
||||
}
|
||||
break;
|
||||
@ -161,19 +160,16 @@ void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint
|
||||
devices[deviceCount].clockOffset = READ_BT_16(packet, 3 + numResponses*(6+1+1+3) + i*2) & 0x7fff;
|
||||
devices[deviceCount].rssi = packet [3 + numResponses*(6+1+1+3+2) + i*1];
|
||||
devices[deviceCount].state = 1;
|
||||
printf("Device found: ");
|
||||
print_bd_addr(addr);
|
||||
printf(" with COD: 0x%06x, pageScan %u, clock offset 0x%04x, rssi 0x%02x\n", devices[deviceCount].classOfDevice,
|
||||
devices[deviceCount].pageScanRepetitionMode, devices[deviceCount].clockOffset, devices[deviceCount].rssi);
|
||||
printf("Device found: %s with COD: 0x%06x, pageScan %u, clock offset 0x%04x, rssi 0x%02x\n", bd_addr_to_str(addr),
|
||||
devices[deviceCount].classOfDevice, devices[deviceCount].pageScanRepetitionMode,
|
||||
devices[deviceCount].clockOffset, devices[deviceCount].rssi);
|
||||
deviceCount++;
|
||||
}
|
||||
break;
|
||||
|
||||
case BTSTACK_EVENT_REMOTE_NAME_CACHED:
|
||||
bt_flip_addr(addr, &packet[3]);
|
||||
printf("Cached remote name for ");
|
||||
print_bd_addr(addr);
|
||||
printf(": %s\n", &packet[9]);
|
||||
printf("Cached remote name for %s: '%s'\n", bd_addr_to_str(addr), &packet[9]);
|
||||
break;
|
||||
|
||||
case HCI_EVENT_REMOTE_NAME_REQUEST_COMPLETE:
|
||||
|
@ -44,6 +44,9 @@
|
||||
#include <btstack/hci_cmds.h>
|
||||
#include <btstack/sdp_util.h>
|
||||
|
||||
// until next BTstack Cydia update
|
||||
#include "compat-svn.c"
|
||||
|
||||
hci_con_handle_t con_handle;
|
||||
|
||||
uint16_t hid_control = 0;
|
||||
@ -90,10 +93,8 @@ void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint
|
||||
psm = READ_BT_16(packet, 10);
|
||||
local_cid = READ_BT_16(packet, 12);
|
||||
remote_cid = READ_BT_16(packet, 14);
|
||||
printf("L2CAP_EVENT_INCOMING_CONNECTION ");
|
||||
print_bd_addr(event_addr);
|
||||
printf(", handle 0x%02x, psm 0x%02x, local cid 0x%02x, remote cid 0x%02x\n",
|
||||
handle, psm, local_cid, remote_cid);
|
||||
printf("L2CAP_EVENT_INCOMING_CONNECTION %s, handle 0x%02x, psm 0x%02x, local cid 0x%02x, remote cid 0x%02x\n",
|
||||
bd_addr_to_str(event_addr), handle, psm, local_cid, remote_cid);
|
||||
|
||||
// accept
|
||||
bt_send_cmd(&l2cap_accept_connection, local_cid);
|
||||
@ -125,10 +126,8 @@ void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint
|
||||
local_cid = READ_BT_16(packet, 13);
|
||||
handle = READ_BT_16(packet, 9);
|
||||
if (packet[2] == 0) {
|
||||
printf("Channel successfully opened: ");
|
||||
print_bd_addr(event_addr);
|
||||
printf(", handle 0x%02x, psm 0x%02x, local cid 0x%02x, remote cid 0x%02x\n",
|
||||
handle, psm, local_cid, READ_BT_16(packet, 15));
|
||||
printf("Channel successfully opened: %s, handle 0x%02x, psm 0x%02x, local cid 0x%02x, remote cid 0x%02x\n",
|
||||
bd_addr_to_str(event_addr), handle, psm, local_cid, READ_BT_16(packet, 15));
|
||||
|
||||
if (psm == PSM_HID_CONTROL){
|
||||
hid_control = local_cid;
|
||||
@ -140,9 +139,7 @@ void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint
|
||||
bt_send_cmd(&hci_switch_role_command, &event_addr, 0);
|
||||
}
|
||||
} else {
|
||||
printf("L2CAP connection to device ");
|
||||
print_bd_addr(event_addr);
|
||||
printf(" failed. status code %u\n", packet[2]);
|
||||
printf("L2CAP connection to device %s failed. status code %u\n", bd_addr_to_str(event_addr), packet[2]);
|
||||
exit(1);
|
||||
}
|
||||
break;
|
||||
|
@ -43,6 +43,9 @@
|
||||
#include <btstack/btstack.h>
|
||||
#include <btstack/hci_cmds.h>
|
||||
|
||||
// until next BTstack Cydia update
|
||||
#include "compat-svn.c"
|
||||
|
||||
#define PSM_TEST 0xdead
|
||||
#define PACKET_SIZE 1000
|
||||
|
||||
@ -126,9 +129,7 @@ void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint
|
||||
psm = READ_BT_16(packet, 10);
|
||||
local_cid = READ_BT_16(packet, 12);
|
||||
remote_cid = READ_BT_16(packet, 14);
|
||||
printf("L2CAP_EVENT_INCOMING_CONNECTION ");
|
||||
print_bd_addr(event_addr);
|
||||
printf(", handle 0x%02x, psm 0x%02x, local cid 0x%02x\n", handle, psm, local_cid);
|
||||
printf("L2CAP_EVENT_INCOMING_CONNECTION %s, handle 0x%02x, psm 0x%02x, local cid 0x%02x\n", bd_addr_to_str(event_addr), handle, psm, local_cid);
|
||||
// accept
|
||||
bt_send_cmd(&l2cap_accept_connection, local_cid);
|
||||
break;
|
||||
@ -160,14 +161,10 @@ void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint
|
||||
local_cid = READ_BT_16(packet, 13);
|
||||
handle = READ_BT_16(packet, 9);
|
||||
if (packet[2] == 0) {
|
||||
printf("Channel successfully opened: ");
|
||||
print_bd_addr(event_addr);
|
||||
printf(", handle 0x%02x, psm 0x%02x, local cid 0x%02x, remote cid 0x%02x\n",
|
||||
handle, psm, local_cid, READ_BT_16(packet, 15));
|
||||
printf("Channel successfully opened: %s, handle 0x%02x, psm 0x%02x, local cid 0x%02x, remote cid 0x%02x\n",
|
||||
bd_addr_to_str(event_addr), handle, psm, local_cid, READ_BT_16(packet, 15));
|
||||
} else {
|
||||
printf("L2CAP connection to device ");
|
||||
print_bd_addr(event_addr);
|
||||
printf(" failed. status code %u\n", packet[2]);
|
||||
printf("L2CAP connection to device %s failed. status code %u\n", bd_addr_to_str(event_addr), packet[2]);
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -50,6 +50,9 @@
|
||||
#include <btstack/btstack.h>
|
||||
#include <btstack/sdp_util.h>
|
||||
|
||||
// until next BTstack Cydia update
|
||||
#include "compat-svn.c"
|
||||
|
||||
// input from command line arguments
|
||||
bd_addr_t addr = { };
|
||||
uint16_t con_handle;
|
||||
@ -164,9 +167,7 @@ int main (int argc, const char * argv[]){
|
||||
}
|
||||
bt_register_packet_handler(packet_handler);
|
||||
|
||||
printf("Trying connection to ");
|
||||
print_bd_addr(addr);
|
||||
printf(" channel %d\n", rfcomm_channel);
|
||||
printf("Trying to connect to %s, channel %d\n", bd_addr_to_str(addr), rfcomm_channel);
|
||||
|
||||
bt_send_cmd(&btstack_set_power_mode, HCI_POWER_ON );
|
||||
run_loop_execute();
|
||||
|
@ -46,6 +46,9 @@
|
||||
#include <btstack/btstack.h>
|
||||
#include <btstack/sdp_util.h>
|
||||
|
||||
// until next BTstack Cydia update
|
||||
#include "compat-svn.c"
|
||||
|
||||
// input from command line arguments
|
||||
bd_addr_t addr = { };
|
||||
uint16_t con_handle;
|
||||
@ -196,9 +199,7 @@ void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint
|
||||
bt_flip_addr(event_addr, &packet[2]);
|
||||
rfcomm_channel_nr = packet[8];
|
||||
rfcomm_channel_id = READ_BT_16(packet, 9);
|
||||
printf("RFCOMM channel %u requested for ", rfcomm_channel_nr);
|
||||
print_bd_addr(event_addr);
|
||||
printf("\n");
|
||||
printf("RFCOMM channel %u requested for %s\n", rfcomm_channel_nr, bd_addr_to_str(addr));
|
||||
bt_send_cmd(&rfcomm_accept_connection, rfcomm_channel_id);
|
||||
break;
|
||||
|
||||
|
@ -46,6 +46,9 @@
|
||||
#include <btstack/btstack.h>
|
||||
#include <btstack/sdp_util.h>
|
||||
|
||||
// until next BTstack Cydia update
|
||||
#include "compat-svn.c"
|
||||
|
||||
// input from command line arguments
|
||||
bd_addr_t addr = { };
|
||||
uint16_t con_handle;
|
||||
@ -199,9 +202,7 @@ void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint
|
||||
bt_flip_addr(event_addr, &packet[2]);
|
||||
rfcomm_channel_nr = packet[8];
|
||||
rfcomm_channel_id = READ_BT_16(packet, 9);
|
||||
printf("RFCOMM channel %u requested for ", rfcomm_channel_nr);
|
||||
print_bd_addr(event_addr);
|
||||
printf("\n");
|
||||
printf("RFCOMM channel %u requested for %s\n", rfcomm_channel_nr, bd_addr_to_str(event_addr));
|
||||
bt_send_cmd(&rfcomm_accept_connection, rfcomm_channel_id);
|
||||
break;
|
||||
|
||||
|
@ -43,6 +43,9 @@
|
||||
#include <btstack/btstack.h>
|
||||
#include <btstack/hci_cmds.h>
|
||||
|
||||
// until next BTstack Cydia update
|
||||
#include "compat-svn.c"
|
||||
|
||||
// bd_addr_t addr = {0x00, 0x03, 0xc9, 0x3d, 0x77, 0x43 }; // Think Outside Keyboard
|
||||
// bd_addr_t addr = {0x00, 0x19, 0x1d, 0x90, 0x44, 0x68 }; // WiiMote
|
||||
bd_addr_t addr = {0x76, 0x6d, 0x62, 0xdb, 0xca, 0x73 }; // iPad
|
||||
@ -111,10 +114,8 @@ void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint
|
||||
uint16_t source_cid = READ_BT_16(packet, 13);
|
||||
con_handle = READ_BT_16(packet, 9);
|
||||
if (packet[2] == 0) {
|
||||
printf("Channel successfully opened: ");
|
||||
print_bd_addr(event_addr);
|
||||
printf(", handle 0x%02x, psm 0x%02x, source cid 0x%02x, dest cid 0x%02x\n",
|
||||
con_handle, psm, source_cid, READ_BT_16(packet, 15));
|
||||
printf("Channel successfully opened: %s, handle 0x%02x, psm 0x%02x, source cid 0x%02x, dest cid 0x%02x\n",
|
||||
bd_addr_to_str(event_addr), con_handle, psm, source_cid, READ_BT_16(packet, 15));
|
||||
|
||||
if (psm == 0x13) {
|
||||
source_cid_interrupt = source_cid;
|
||||
@ -130,9 +131,7 @@ void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint
|
||||
// bt_send_l2cap( source_cid, setLEDs, sizeof(setLEDs));
|
||||
}
|
||||
} else {
|
||||
printf("L2CAP connection to device ");
|
||||
print_bd_addr(event_addr);
|
||||
printf(" failed. status code %u\n", packet[2]);
|
||||
printf("L2CAP connection to device %s failed. status code %u\n", bd_addr_to_str(event_addr), packet[2]);
|
||||
exit(1);
|
||||
}
|
||||
break;
|
||||
|
Loading…
x
Reference in New Issue
Block a user