mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-02-04 06:39:53 +00:00
replace link_key_db_t with a remote_device_db_t that also holds cached remote names
This commit is contained in:
parent
63dfdee5e8
commit
29d5309818
@ -166,8 +166,8 @@ if test "x$target" = xiphone; then
|
||||
echo "USE_LDID: no"
|
||||
fi
|
||||
|
||||
LINK_KEY_DB_SOURCES="link_key_db_iphone.m"
|
||||
LINK_KEY_DB="link_key_db_iphone"
|
||||
REMOTE_DEVICE_DB_SOURCES="remote_device_db_iphone.m"
|
||||
REMOTE_DEVICE_DB="remote_device_db_iphone"
|
||||
|
||||
else
|
||||
case "$host_os" in
|
||||
@ -202,7 +202,7 @@ fi
|
||||
echo "USE_LAUNCHD: $USE_LAUNCHD"
|
||||
echo "USE_SPRINGBOARD: $USE_SPRINGBOARD"
|
||||
echo "USE_COCOA_RUN_LOOP: $USE_COCOA_RUN_LOOP"
|
||||
echo "LINK_KEY_DB: $LINK_KEY_DB"
|
||||
echo "REMOTE_DEVICE_DB: $REMOTE_DEVICE_DB"
|
||||
echo
|
||||
echo
|
||||
|
||||
@ -240,7 +240,7 @@ fi
|
||||
AC_SUBST(IPHONE_IP)
|
||||
AC_SUBST(HAVE_LIBUSB)
|
||||
AC_SUBST(USE_LDID)
|
||||
AC_SUBST(LINK_KEY_DB_SOURCES)
|
||||
AC_SUBST(REMOTE_DEVICE_DB_SOURCES)
|
||||
AC_SUBST(USB_SOURCES)
|
||||
AC_SUBST(SPRINGBOARD_ACCESS_SOURCES)
|
||||
AC_SUBST(RUN_LOOP_SOURCES)
|
||||
|
@ -62,6 +62,13 @@ typedef uint8_t bd_addr_t[BD_ADDR_LEN];
|
||||
#define LINK_KEY_LEN 16
|
||||
typedef uint8_t link_key_t[LINK_KEY_LEN];
|
||||
|
||||
/**
|
||||
* @brief The device name type
|
||||
*/
|
||||
#define DEVICE_NAME_LEN 248
|
||||
typedef uint8_t device_name_t[DEVICE_NAME_LEN+1];
|
||||
|
||||
|
||||
// helper for BT little endian format
|
||||
#define READ_BT_16( buffer, pos) ( ((uint16_t) buffer[pos]) | (((uint16_t)buffer[pos+1]) << 8))
|
||||
#define READ_BT_24( buffer, pos) ( ((uint32_t) buffer[pos]) | (((uint32_t)buffer[pos+1]) << 8) | (((uint32_t)buffer[pos+2]) << 16))
|
||||
|
@ -19,7 +19,7 @@
|
||||
9C05FC971020D3F300255261 /* socket_connection.c in Sources */ = {isa = PBXBuildFile; fileRef = 9C00F7301017ACC3008DAB17 /* socket_connection.c */; };
|
||||
9C18015C108BAA7200824BE7 /* libusb-1.0.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 9C18015B108BAA7200824BE7 /* libusb-1.0.dylib */; };
|
||||
9C255D4A11E0C59900CDD689 /* run_loop_embedded.c in Sources */ = {isa = PBXBuildFile; fileRef = 9C255D4911E0C59900CDD689 /* run_loop_embedded.c */; };
|
||||
9C3AED88122C201C008046F4 /* link_key_db_iphone.m in Sources */ = {isa = PBXBuildFile; fileRef = 9C3AED87122C201C008046F4 /* link_key_db_iphone.m */; };
|
||||
9C3AED88122C201C008046F4 /* remote_device_db_iphone.m in Sources */ = {isa = PBXBuildFile; fileRef = 9C3AED87122C201C008046F4 /* remote_device_db_iphone.m */; };
|
||||
9C46FC3A0FA906F700ABEF05 /* hci_transport_h4.c in Sources */ = {isa = PBXBuildFile; fileRef = 9C46FC360FA906F700ABEF05 /* hci_transport_h4.c */; };
|
||||
9C77E79210667F0600F39DCF /* platform_iphone.c in Sources */ = {isa = PBXBuildFile; fileRef = 9C77E79110667F0600F39DCF /* platform_iphone.c */; };
|
||||
9C7B5AC0100BD3340065D87E /* linked_list.c in Sources */ = {isa = PBXBuildFile; fileRef = 9C7B5ABF100BD3340065D87E /* linked_list.c */; };
|
||||
@ -74,8 +74,8 @@
|
||||
9C255D4911E0C59900CDD689 /* run_loop_embedded.c */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.c.c; name = run_loop_embedded.c; path = src/run_loop_embedded.c; sourceTree = "<group>"; };
|
||||
9C255D7611E0DD2C00CDD689 /* hci_transport_h4_stellaris.c */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.c.c; name = hci_transport_h4_stellaris.c; path = "../../TI/Stellarware/boards/dk-lm3s9b96/bt_init/hci_transport_h4_stellaris.c"; sourceTree = SOURCE_ROOT; };
|
||||
9C255DB511E10AEB00CDD689 /* debug.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = debug.h; path = src/debug.h; sourceTree = "<group>"; };
|
||||
9C3AED86122C201C008046F4 /* link_key_db.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = link_key_db.h; path = src/link_key_db.h; sourceTree = "<group>"; };
|
||||
9C3AED87122C201C008046F4 /* link_key_db_iphone.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = link_key_db_iphone.m; path = src/link_key_db_iphone.m; sourceTree = "<group>"; };
|
||||
9C3AED86122C201C008046F4 /* remote_device_db.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = remote_device_db.h; path = src/remote_device_db.h; sourceTree = "<group>"; };
|
||||
9C3AED87122C201C008046F4 /* remote_device_db_iphone.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = remote_device_db_iphone.m; path = src/remote_device_db_iphone.m; sourceTree = "<group>"; };
|
||||
9C46FC340FA906F700ABEF05 /* hci.c */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.c.c; name = hci.c; path = src/hci.c; sourceTree = "<group>"; };
|
||||
9C46FC350FA906F700ABEF05 /* hci.h */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.c.h; name = hci.h; path = src/hci.h; sourceTree = "<group>"; };
|
||||
9C46FC360FA906F700ABEF05 /* hci_transport_h4.c */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.c.c; name = hci_transport_h4.c; path = src/hci_transport_h4.c; sourceTree = "<group>"; };
|
||||
@ -229,8 +229,8 @@
|
||||
9CB9846A11BC32A800A2F346 /* sdp_util.c */,
|
||||
9CE7CDD711BFF5470096F5B1 /* sdp.c */,
|
||||
9CFFD48C11C4CD0100A37038 /* sdp.h */,
|
||||
9C3AED86122C201C008046F4 /* link_key_db.h */,
|
||||
9C3AED87122C201C008046F4 /* link_key_db_iphone.m */,
|
||||
9C3AED86122C201C008046F4 /* remote_device_db.h */,
|
||||
9C3AED87122C201C008046F4 /* remote_device_db_iphone.m */,
|
||||
);
|
||||
name = Source;
|
||||
sourceTree = "<group>";
|
||||
@ -444,7 +444,7 @@
|
||||
9CB9846B11BC32A800A2F346 /* sdp_util.c in Sources */,
|
||||
9CE7CDD811BFF5470096F5B1 /* sdp.c in Sources */,
|
||||
9C255D4A11E0C59900CDD689 /* run_loop_embedded.c in Sources */,
|
||||
9C3AED88122C201C008046F4 /* link_key_db_iphone.m in Sources */,
|
||||
9C3AED88122C201C008046F4 /* remote_device_db_iphone.m in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
@ -6,7 +6,7 @@ CPPFLAGS = @CPPFLAGS@ -I../include
|
||||
BTSTACK_LIB_LDFLAGS = @BTSTACK_LIB_LDFLAGS@
|
||||
BTSTACK_LIB_EXTENSION = @BTSTACK_LIB_EXTENSION@
|
||||
|
||||
link_key_db_sources = @LINK_KEY_DB_SOURCES@
|
||||
remote_device_db_sources = @REMOTE_DEVICE_DB_SOURCES@
|
||||
run_loop_sources = @RUN_LOOP_SOURCES@
|
||||
springboard_access_sources = @SPRINGBOARD_ACCESS_SOURCES@
|
||||
usb_sources = @USB_SOURCES@
|
||||
@ -22,7 +22,7 @@ BTdaemon_SOURCES = $(libBTstack_SOURCES) \
|
||||
$(usb_sources) \
|
||||
l2cap.c \
|
||||
l2cap_signaling.c \
|
||||
$(link_key_db_sources) \
|
||||
$(remote_device_db_sources) \
|
||||
platform_iphone.c \
|
||||
sdp.c \
|
||||
$(springboard_access_sources)
|
||||
|
22
src/hci.c
22
src/hci.c
@ -300,6 +300,7 @@ static void event_handler(uint8_t *packet, int size){
|
||||
hci_con_handle_t handle;
|
||||
hci_connection_t * conn;
|
||||
int i;
|
||||
link_key_t link_key;
|
||||
|
||||
// get num_cmd_packets
|
||||
if (packet[0] == HCI_EVENT_COMMAND_COMPLETE || packet[0] == HCI_EVENT_COMMAND_STATUS){
|
||||
@ -376,6 +377,9 @@ static void event_handler(uint8_t *packet, int size){
|
||||
hci_emit_nr_connections_changed();
|
||||
} else {
|
||||
// connection failed, remove entry
|
||||
if (hci_stack.remote_device_db) {
|
||||
hci_stack.remote_device_db->delete_link_key(&addr);
|
||||
}
|
||||
linked_list_remove(&hci_stack.connections, (linked_item_t *) conn);
|
||||
free( conn );
|
||||
}
|
||||
@ -384,10 +388,25 @@ static void event_handler(uint8_t *packet, int size){
|
||||
|
||||
case HCI_EVENT_LINK_KEY_REQUEST:
|
||||
hci_add_connection_flags_for_flipped_bd_addr(&packet[2], RECV_LINK_KEY_REQUEST);
|
||||
if (hci_stack.remote_device_db) {
|
||||
bt_flip_addr(addr, &packet[2]);
|
||||
if ( hci_stack.remote_device_db->get_link_key( &addr, &link_key)){
|
||||
hci_send_cmd(&hci_link_key_request_reply, &addr, &link_key);
|
||||
} else {
|
||||
hci_send_cmd(&hci_link_key_request_negative_reply, &addr);
|
||||
}
|
||||
// request already answered
|
||||
return;
|
||||
}
|
||||
break;
|
||||
|
||||
case HCI_EVENT_LINK_KEY_NOTIFICATION:
|
||||
hci_add_connection_flags_for_flipped_bd_addr(&packet[2], RECV_LINK_KEY_NOTIFICATION);
|
||||
if (hci_stack.remote_device_db) {
|
||||
bt_flip_addr(addr, &packet[2]);
|
||||
hci_stack.remote_device_db->put_link_key(&addr, &link_key);
|
||||
}
|
||||
// still forward event to allow dismiss of pairing dialog
|
||||
break;
|
||||
|
||||
case HCI_EVENT_PIN_CODE_REQUEST:
|
||||
@ -473,6 +492,9 @@ void hci_init(hci_transport_t *transport, void *config, bt_control_t *control){
|
||||
// higher level handler
|
||||
hci_stack.packet_handler = dummy_handler;
|
||||
|
||||
// no link key db yet
|
||||
hci_stack.remote_device_db = NULL;
|
||||
|
||||
// register packet handlers with transport
|
||||
transport->register_packet_handler(&packet_handler);
|
||||
}
|
||||
|
@ -42,6 +42,7 @@
|
||||
#include <btstack/utils.h>
|
||||
#include "hci_transport.h"
|
||||
#include "bt_control.h"
|
||||
#include "remote_device_db.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
@ -207,6 +208,9 @@ typedef struct {
|
||||
/* callback to L2CAP layer */
|
||||
void (*packet_handler)(uint8_t packet_type, uint8_t *packet, uint16_t size);
|
||||
|
||||
/* remote device db */
|
||||
remote_device_db_t *remote_device_db;
|
||||
|
||||
/* hci state machine */
|
||||
HCI_STATE state;
|
||||
uint8_t substate;
|
||||
|
@ -30,15 +30,21 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* interface to provide link key storage
|
||||
* interface to provide link key and remote name storage
|
||||
*/
|
||||
|
||||
#include <btstack/utils.h>
|
||||
|
||||
typedef struct {
|
||||
int (*get_link_key)(link_key_t *link_key, bd_addr_t *bd_addr);
|
||||
void (*put_link_key)(link_key_t *key, bd_addr_t *bd_addr);
|
||||
// link key
|
||||
int (*get_link_key)(bd_addr_t *bd_addr, link_key_t *link_key);
|
||||
void (*put_link_key)(bd_addr_t *bd_addr, link_key_t *key);
|
||||
void (*delete_link_key)(bd_addr_t *bd_addr);
|
||||
} link_key_db_t;
|
||||
|
||||
// remove name
|
||||
int (*get_name)(bd_addr_t *bd_addr, device_name_t *device_name);
|
||||
void (*put_name)(bd_addr_t *bd_addr, device_name_t *device_name);
|
||||
void (*delete_name)(bd_addr_t *bd_addr);
|
||||
} remote_device_db_t;
|
||||
|
||||
extern link_key_db_t link_key_db_iphone;
|
||||
extern remote_device_db_t remote_device_db_iphone;
|
@ -28,5 +28,26 @@
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
#include "link_key_db.h"
|
||||
#include "remote_device_db.h"
|
||||
|
||||
static int get_link_key(bd_addr_t *bd_addr, link_key_t *link_key) {
|
||||
return 0;
|
||||
}
|
||||
static void put_link_key(bd_addr_t *bd_addr, link_key_t *link_key){
|
||||
}
|
||||
static void delete_link_key(bd_addr_t *bd_addr){
|
||||
}
|
||||
|
||||
static int get_name(bd_addr_t *bd_addr, device_name_t *device_name) {
|
||||
return 0;
|
||||
}
|
||||
static void put_name(bd_addr_t *bd_addr, device_name_t *device_name){
|
||||
}
|
||||
static void delete_name(bd_addr_t *bd_addr){
|
||||
}
|
||||
|
||||
remote_device_db_t remote_device_db_iphone = {
|
||||
get_link_key, put_link_key, delete_link_key,
|
||||
get_name, put_name, delete_name
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user