From 6772a24cc3574cd4fc859bc9b827453b93835ec7 Mon Sep 17 00:00:00 2001 From: "matthias.ringwald" Date: Sat, 5 Dec 2009 18:55:41 +0000 Subject: [PATCH] don't send hci_link_key_request_negative_reply on HCI_EVENT_LINK_KEY_REQUEST automatically --- TODO.txt | 13 +- example/rfcomm.c | 6 + project.xcodeproj/project.pbxproj | 342 +++++++++++++++++++++++++++++- src/hci.c | 109 +++++----- 4 files changed, 405 insertions(+), 65 deletions(-) diff --git a/TODO.txt b/TODO.txt index 1131d38f0..7a8e3f33c 100644 --- a/TODO.txt +++ b/TODO.txt @@ -3,10 +3,11 @@ 2009-11-08: Release 0.1 NEXT: -- figure out how to add BTstack logo to Cydia repository list -- sign BTstack repository -- figure out how to receive iPhone System Power IONotifications (in BTdaemon) to detect, - when phone gets locked +- implement rest of L2CAP state machine + - incoming connections + - list of supported PSM + - commands and events- +- figure out how to receive iPhone System Power IONotifications (in BTdaemon) to detect, when phone gets locked - some trick - use Cocoa run loop for background app? - see iPhone imsomnia project at http://code.google.com/p/iphone-insomnia/ @@ -14,10 +15,6 @@ NEXT: - would be nice, if we could get woken up by Bluetooth data - create - add timeouts to cocoa run loop -- implement rest of L2CAP state machine - - incoming connections - - list of supported PSM - - commands and events - RFCOMM implementation - use switch on RFCOMM control field in rfcomm.c packet handler - CocoaTouch User Interface Components diff --git a/example/rfcomm.c b/example/rfcomm.c index 581dc6d45..a578f2d2a 100644 --- a/example/rfcomm.c +++ b/example/rfcomm.c @@ -286,6 +286,12 @@ void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint bt_send_cmd(&hci_write_local_name, "BTstack-Test"); } break; + + case HCI_EVENT_LINK_KEY_REQUEST: + // link key request + bt_flip_addr(event_addr, &packet[2]); + bt_send_cmd(&hci_link_key_request_negative_reply, &event_addr); + break; case HCI_EVENT_PIN_CODE_REQUEST: // inform about pin code request diff --git a/project.xcodeproj/project.pbxproj b/project.xcodeproj/project.pbxproj index 81b707c74..c6ebc0b10 100644 --- a/project.xcodeproj/project.pbxproj +++ b/project.xcodeproj/project.pbxproj @@ -28,12 +28,35 @@ 9C7ECB840FCC85650085DAC5 /* bt_control_iphone.c in Sources */ = {isa = PBXBuildFile; fileRef = 9C7ECB820FCC85650085DAC5 /* bt_control_iphone.c */; }; 9C7ECBB50FCC95DD0085DAC5 /* hci_dump.c in Sources */ = {isa = PBXBuildFile; fileRef = 9C7ECBB40FCC95DD0085DAC5 /* hci_dump.c */; }; 9C88500E0FBF6702004980E4 /* l2cap.c in Sources */ = {isa = PBXBuildFile; fileRef = 9C88500C0FBF6702004980E4 /* l2cap.c */; }; + 9C88A1E010C7DE310003DF36 /* BTDevice.o in Frameworks */ = {isa = PBXBuildFile; fileRef = 9C88A1AE10C7DE310003DF36 /* BTDevice.o */; }; + 9C88A1E110C7DE310003DF36 /* BTInquiryViewController.o in Frameworks */ = {isa = PBXBuildFile; fileRef = 9C88A1AF10C7DE310003DF36 /* BTInquiryViewController.o */; }; + 9C88A1E210C7DE310003DF36 /* main.o in Frameworks */ = {isa = PBXBuildFile; fileRef = 9C88A1B110C7DE310003DF36 /* main.o */; }; + 9C88A1E310C7DE310003DF36 /* BTDevice.o in Frameworks */ = {isa = PBXBuildFile; fileRef = 9C88A1BF10C7DE310003DF36 /* BTDevice.o */; }; + 9C88A1E410C7DE310003DF36 /* BTInquiryViewController.o in Frameworks */ = {isa = PBXBuildFile; fileRef = 9C88A1C010C7DE310003DF36 /* BTInquiryViewController.o */; }; + 9C88A1E510C7DE310003DF36 /* BTInquiryViewController.o~$ in Frameworks */ = {isa = PBXBuildFile; fileRef = 9C88A1C110C7DE310003DF36 /* BTInquiryViewController.o~$ */; }; + 9C88A1E610C7DE310003DF36 /* BTstackCocoaAppDelegate.o in Frameworks */ = {isa = PBXBuildFile; fileRef = 9C88A1C510C7DE310003DF36 /* BTstackCocoaAppDelegate.o */; }; + 9C88A1E710C7DE310003DF36 /* BTstackCocoaAppDelegate.o~$ in Frameworks */ = {isa = PBXBuildFile; fileRef = 9C88A1C610C7DE310003DF36 /* BTstackCocoaAppDelegate.o~$ */; }; + 9C88A1E810C7DE310003DF36 /* main.o in Frameworks */ = {isa = PBXBuildFile; fileRef = 9C88A1C810C7DE310003DF36 /* main.o */; }; + 9C88A1E910C7DE310003DF36 /* BTDevice.m in Sources */ = {isa = PBXBuildFile; fileRef = 9C88A1DB10C7DE310003DF36 /* BTDevice.m */; }; + 9C88A1EA10C7DE310003DF36 /* BTInquiryViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 9C88A1DC10C7DE310003DF36 /* BTInquiryViewController.m */; }; + 9C88A1EB10C7DE310003DF36 /* BTstackCocoaAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 9C88A1DE10C7DE310003DF36 /* BTstackCocoaAppDelegate.m */; }; + 9C88A1EC10C7DE310003DF36 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 9C88A1DF10C7DE310003DF36 /* main.m */; }; 9CC813A20FFC0774002816F9 /* btstack.c in Sources */ = {isa = PBXBuildFile; fileRef = 9CC813A10FFC0774002816F9 /* btstack.c */; }; 9CC813A50FFC0A51002816F9 /* daemon.c in Sources */ = {isa = PBXBuildFile; fileRef = 9CC813A40FFC0A51002816F9 /* daemon.c */; }; 9CCE6CEA1025BD0000FCE9F4 /* hci.c in Sources */ = {isa = PBXBuildFile; fileRef = 9C46FC340FA906F700ABEF05 /* hci.c */; }; 9CEB4F17107AAAEF00DD5720 /* run_loop_posix.c in Sources */ = {isa = PBXBuildFile; fileRef = 9CEB4DAC10753BE600DD5720 /* run_loop_posix.c */; }; /* End PBXBuildFile section */ +/* Begin PBXContainerItemProxy section */ + 9C88A1F310C7DE320003DF36 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 9C88A18D10C7DE310003DF36 /* BTstackCocoa.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = 1D6058910D05DD3D006BFB54; + remoteInfo = BTstackCocoa; + }; +/* End PBXContainerItemProxy section */ + /* Begin PBXCopyFilesBuildPhase section */ 8DD76FAF0486AB0100D96B5E /* CopyFiles */ = { isa = PBXCopyFilesBuildPhase; @@ -56,7 +79,6 @@ 9C00F87210191130008DAB17 /* l2cap_signaling.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = l2cap_signaling.c; path = src/l2cap_signaling.c; sourceTree = ""; }; 9C04B825107D1CED002A63D0 /* run_loop.c */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.c.c; name = run_loop.c; path = src/run_loop.c; sourceTree = ""; }; 9C04B879107D2BA7002A63D0 /* CoreFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreFoundation.framework; path = /System/Library/Frameworks/CoreFoundation.framework; sourceTree = ""; }; - 9C04BD3110826575002A63D0 /* logo.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = logo.png; path = resources/logo.png; sourceTree = ""; }; 9C18015B108BAA7200824BE7 /* libusb-1.0.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = "libusb-1.0.dylib"; path = "/usr/local/lib/libusb-1.0.dylib"; sourceTree = ""; }; 9C1813F71042FCCA00C68F09 /* mitm.c */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.c.c; name = mitm.c; path = example/mitm.c; sourceTree = ""; }; 9C2071F210014D3200A07EA4 /* hci_transport_usb.c */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.c.c; name = hci_transport_usb.c; path = src/hci_transport_usb.c; sourceTree = ""; }; @@ -92,6 +114,70 @@ 9C7ECBB40FCC95DD0085DAC5 /* hci_dump.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = hci_dump.c; path = src/hci_dump.c; sourceTree = ""; }; 9C88500C0FBF6702004980E4 /* l2cap.c */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.c.c; name = l2cap.c; path = src/l2cap.c; sourceTree = ""; }; 9C88500D0FBF6702004980E4 /* l2cap.h */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.c.h; name = l2cap.h; path = src/l2cap.h; sourceTree = ""; }; + 9C88A18C10C7DE310003DF36 /* BTstackCocoa-Info.plist */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = text.plist.xml; path = "BTstackCocoa-Info.plist"; sourceTree = ""; }; + 9C88A18D10C7DE310003DF36 /* BTstackCocoa.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; path = BTstackCocoa.xcodeproj; sourceTree = ""; }; + 9C88A19010C7DE310003DF36 /* BTstackCocoa_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.c.h; path = BTstackCocoa_Prefix.pch; sourceTree = ""; }; + 9C88A19410C7DE310003DF36 /* categories.pbxbtree */ = {isa = PBXFileReference; lastKnownFileType = file; path = categories.pbxbtree; sourceTree = ""; }; + 9C88A19510C7DE310003DF36 /* cdecls.pbxbtree */ = {isa = PBXFileReference; lastKnownFileType = file; path = cdecls.pbxbtree; sourceTree = ""; }; + 9C88A19610C7DE310003DF36 /* decls.pbxbtree */ = {isa = PBXFileReference; lastKnownFileType = file; path = decls.pbxbtree; sourceTree = ""; }; + 9C88A19710C7DE310003DF36 /* files.pbxbtree */ = {isa = PBXFileReference; lastKnownFileType = file; path = files.pbxbtree; sourceTree = ""; }; + 9C88A19810C7DE310003DF36 /* imports.pbxbtree */ = {isa = PBXFileReference; lastKnownFileType = file; path = imports.pbxbtree; sourceTree = ""; }; + 9C88A19910C7DE310003DF36 /* pbxindex.header */ = {isa = PBXFileReference; lastKnownFileType = file; path = pbxindex.header; sourceTree = ""; }; + 9C88A19A10C7DE310003DF36 /* protocols.pbxbtree */ = {isa = PBXFileReference; lastKnownFileType = file; path = protocols.pbxbtree; sourceTree = ""; }; + 9C88A19B10C7DE310003DF36 /* refs.pbxbtree */ = {isa = PBXFileReference; lastKnownFileType = file; path = refs.pbxbtree; sourceTree = ""; }; + 9C88A19D10C7DE310003DF36 /* control */ = {isa = PBXFileReference; lastKnownFileType = file; path = control; sourceTree = ""; }; + 9C88A19E10C7DE310003DF36 /* strings */ = {isa = PBXFileReference; lastKnownFileType = file; path = strings; sourceTree = ""; }; + 9C88A19F10C7DE310003DF36 /* subclasses.pbxbtree */ = {isa = PBXFileReference; lastKnownFileType = file; path = subclasses.pbxbtree; sourceTree = ""; }; + 9C88A1A010C7DE310003DF36 /* symbols0.pbxsymbols */ = {isa = PBXFileReference; lastKnownFileType = file; path = symbols0.pbxsymbols; sourceTree = ""; }; + 9C88A1A310C7DE310003DF36 /* BTstackCocoa-all-target-headers.hmap */ = {isa = PBXFileReference; lastKnownFileType = file; path = "BTstackCocoa-all-target-headers.hmap"; sourceTree = ""; }; + 9C88A1A410C7DE310003DF36 /* BTstackCocoa-generated-files.hmap */ = {isa = PBXFileReference; lastKnownFileType = file; path = "BTstackCocoa-generated-files.hmap"; sourceTree = ""; }; + 9C88A1A510C7DE310003DF36 /* BTstackCocoa-own-target-headers.hmap */ = {isa = PBXFileReference; lastKnownFileType = file; path = "BTstackCocoa-own-target-headers.hmap"; sourceTree = ""; }; + 9C88A1A610C7DE310003DF36 /* BTstackCocoa-project-headers.hmap */ = {isa = PBXFileReference; lastKnownFileType = file; path = "BTstackCocoa-project-headers.hmap"; sourceTree = ""; }; + 9C88A1A710C7DE310003DF36 /* BTstackCocoa.dep */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = text; path = BTstackCocoa.dep; sourceTree = ""; }; + 9C88A1A810C7DE310003DF36 /* BTstackCocoa.hmap */ = {isa = PBXFileReference; lastKnownFileType = file; path = BTstackCocoa.hmap; sourceTree = ""; }; + 9C88A1A910C7DE310003DF36 /* BTstackCocoa~.dep */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = text; path = "BTstackCocoa~.dep"; sourceTree = ""; }; + 9C88A1AA10C7DE310003DF36 /* build-state.dat */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = text; path = "build-state.dat"; sourceTree = ""; }; + 9C88A1AB10C7DE310003DF36 /* build-state~.dat */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = text; path = "build-state~.dat"; sourceTree = ""; }; + 9C88A1AE10C7DE310003DF36 /* BTDevice.o */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.objfile"; path = BTDevice.o; sourceTree = ""; }; + 9C88A1AF10C7DE310003DF36 /* BTInquiryViewController.o */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.objfile"; path = BTInquiryViewController.o; sourceTree = ""; }; + 9C88A1B010C7DE310003DF36 /* BTstackCocoa.LinkFileList */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = text; path = BTstackCocoa.LinkFileList; sourceTree = ""; }; + 9C88A1B110C7DE310003DF36 /* main.o */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.objfile"; path = main.o; sourceTree = ""; }; + 9C88A1B410C7DE310003DF36 /* BTstackCocoa-all-target-headers.hmap */ = {isa = PBXFileReference; lastKnownFileType = file; path = "BTstackCocoa-all-target-headers.hmap"; sourceTree = ""; }; + 9C88A1B510C7DE310003DF36 /* BTstackCocoa-generated-files.hmap */ = {isa = PBXFileReference; lastKnownFileType = file; path = "BTstackCocoa-generated-files.hmap"; sourceTree = ""; }; + 9C88A1B610C7DE310003DF36 /* BTstackCocoa-own-target-headers.hmap */ = {isa = PBXFileReference; lastKnownFileType = file; path = "BTstackCocoa-own-target-headers.hmap"; sourceTree = ""; }; + 9C88A1B710C7DE310003DF36 /* BTstackCocoa-project-headers.hmap */ = {isa = PBXFileReference; lastKnownFileType = file; path = "BTstackCocoa-project-headers.hmap"; sourceTree = ""; }; + 9C88A1B810C7DE310003DF36 /* BTstackCocoa.dep */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = text; path = BTstackCocoa.dep; sourceTree = ""; }; + 9C88A1B910C7DE310003DF36 /* BTstackCocoa.hmap */ = {isa = PBXFileReference; lastKnownFileType = file; path = BTstackCocoa.hmap; sourceTree = ""; }; + 9C88A1BA10C7DE310003DF36 /* BTstackCocoa~.dep */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = text; path = "BTstackCocoa~.dep"; sourceTree = ""; }; + 9C88A1BB10C7DE310003DF36 /* build-state.dat */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = text; path = "build-state.dat"; sourceTree = ""; }; + 9C88A1BC10C7DE310003DF36 /* build-state~.dat */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = text; path = "build-state~.dat"; sourceTree = ""; }; + 9C88A1BF10C7DE310003DF36 /* BTDevice.o */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.objfile"; path = BTDevice.o; sourceTree = ""; }; + 9C88A1C010C7DE310003DF36 /* BTInquiryViewController.o */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.objfile"; path = BTInquiryViewController.o; sourceTree = ""; }; + 9C88A1C110C7DE310003DF36 /* BTInquiryViewController.o~$ */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.objfile"; path = "BTInquiryViewController.o~$"; sourceTree = ""; }; + 9C88A1C210C7DE310003DF36 /* BTInquiryViewController.o~> */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = text; path = "BTInquiryViewController.o~>"; sourceTree = ""; }; + 9C88A1C310C7DE310003DF36 /* BTInquiryViewController.o~? */ = {isa = PBXFileReference; lastKnownFileType = file; path = "BTInquiryViewController.o~?"; sourceTree = ""; }; + 9C88A1C410C7DE310003DF36 /* BTstackCocoa.LinkFileList */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = text; path = BTstackCocoa.LinkFileList; sourceTree = ""; }; + 9C88A1C510C7DE310003DF36 /* BTstackCocoaAppDelegate.o */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.objfile"; path = BTstackCocoaAppDelegate.o; sourceTree = ""; }; + 9C88A1C610C7DE310003DF36 /* BTstackCocoaAppDelegate.o~$ */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.objfile"; path = "BTstackCocoaAppDelegate.o~$"; sourceTree = ""; }; + 9C88A1C710C7DE310003DF36 /* BTstackCocoaAppDelegate.o~> */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = text; path = "BTstackCocoaAppDelegate.o~>"; sourceTree = ""; }; + 9C88A1C810C7DE310003DF36 /* main.o */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.objfile"; path = main.o; sourceTree = ""; }; + 9C88A1CA10C7DE310003DF36 /* BTstackCocoa.app */ = {isa = PBXFileReference; lastKnownFileType = wrapper.application; path = BTstackCocoa.app; sourceTree = ""; }; + 9C88A1CB10C7DE310003DF36 /* BTstackCocoa.app.dSYM */ = {isa = PBXFileReference; lastKnownFileType = wrapper.dsym; path = BTstackCocoa.app.dSYM; sourceTree = ""; }; + 9C88A1CD10C7DE310003DF36 /* BTstackCocoa.app */ = {isa = PBXFileReference; lastKnownFileType = wrapper.application; path = BTstackCocoa.app; sourceTree = ""; }; + 9C88A1CE10C7DE310003DF36 /* BTstackCocoa.app.dSYM */ = {isa = PBXFileReference; lastKnownFileType = wrapper.dsym; path = BTstackCocoa.app.dSYM; sourceTree = ""; }; + 9C88A1D010C7DE310003DF36 /* bluetooth.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = bluetooth.png; sourceTree = ""; }; + 9C88A1D110C7DE310003DF36 /* computer.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = computer.png; sourceTree = ""; }; + 9C88A1D210C7DE310003DF36 /* keyboard.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = keyboard.png; sourceTree = ""; }; + 9C88A1D310C7DE310003DF36 /* LICENSE.txt */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = text; path = LICENSE.txt; sourceTree = ""; }; + 9C88A1D410C7DE310003DF36 /* smartphone.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = smartphone.png; sourceTree = ""; }; + 9C88A1D510C7DE310003DF36 /* Untitled.txt */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = text; path = Untitled.txt; sourceTree = ""; }; + 9C88A1D810C7DE310003DF36 /* BTDevice.h */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.c.h; path = BTDevice.h; sourceTree = ""; }; + 9C88A1D910C7DE310003DF36 /* BTInquiryViewController.h */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.c.h; path = BTInquiryViewController.h; sourceTree = ""; }; + 9C88A1DB10C7DE310003DF36 /* BTDevice.m */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.c.objc; path = BTDevice.m; sourceTree = ""; }; + 9C88A1DC10C7DE310003DF36 /* BTInquiryViewController.m */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.c.objc; path = BTInquiryViewController.m; sourceTree = ""; }; + 9C88A1DD10C7DE310003DF36 /* BTstackCocoaAppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.c.h; path = BTstackCocoaAppDelegate.h; sourceTree = ""; }; + 9C88A1DE10C7DE310003DF36 /* BTstackCocoaAppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.c.objc; path = BTstackCocoaAppDelegate.m; sourceTree = ""; }; + 9C88A1DF10C7DE310003DF36 /* main.m */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 9C994B8E106BEEB700C70311 /* rfcomm.c */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.c.c; name = rfcomm.c; path = example/rfcomm.c; sourceTree = ""; }; 9CA3C0900FB8B3C4005F48DE /* TODO.txt */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = text; path = TODO.txt; sourceTree = ""; }; 9CAA573610A5D87400D0E1A9 /* inquiry.c */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.c.c; name = inquiry.c; path = example/inquiry.c; sourceTree = ""; }; @@ -117,6 +203,15 @@ files = ( 9C04B87A107D2BA7002A63D0 /* CoreFoundation.framework in Frameworks */, 9C18015C108BAA7200824BE7 /* libusb-1.0.dylib in Frameworks */, + 9C88A1E010C7DE310003DF36 /* BTDevice.o in Frameworks */, + 9C88A1E110C7DE310003DF36 /* BTInquiryViewController.o in Frameworks */, + 9C88A1E210C7DE310003DF36 /* main.o in Frameworks */, + 9C88A1E310C7DE310003DF36 /* BTDevice.o in Frameworks */, + 9C88A1E410C7DE310003DF36 /* BTInquiryViewController.o in Frameworks */, + 9C88A1E510C7DE310003DF36 /* BTInquiryViewController.o~$ in Frameworks */, + 9C88A1E610C7DE310003DF36 /* BTstackCocoaAppDelegate.o in Frameworks */, + 9C88A1E710C7DE310003DF36 /* BTstackCocoaAppDelegate.o~$ in Frameworks */, + 9C88A1E810C7DE310003DF36 /* main.o in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -138,6 +233,7 @@ 9C77E4AD10634E3100F39DCF /* 3rdparty */, 9C78A049103C671D003B2950 /* Resources */, 9C7B5B81100D04520065D87E /* Example */, + 9C88A18B10C7DE300003DF36 /* CocoaTouch */, 08FB7795FE84155DC02AAC07 /* Source */, 9C77E2751060322300F39DCF /* SpringBoardAccess */, C6A0FF2B0290797F04C91782 /* Documentation */, @@ -223,7 +319,6 @@ 9C78A049103C671D003B2950 /* Resources */ = { isa = PBXGroup; children = ( - 9C04BD3110826575002A63D0 /* logo.png */, 9C78A0BB103C9DEE003B2950 /* ch.ringwald.BTstack.plist */, 9C78A04A103C6734003B2950 /* Default_BTstack.png */, 9C78A04B103C6734003B2950 /* Default_BTstackActive.png */, @@ -244,6 +339,229 @@ name = Example; sourceTree = ""; }; + 9C88A18B10C7DE300003DF36 /* CocoaTouch */ = { + isa = PBXGroup; + children = ( + 9C88A18C10C7DE310003DF36 /* BTstackCocoa-Info.plist */, + 9C88A18D10C7DE310003DF36 /* BTstackCocoa.xcodeproj */, + 9C88A19010C7DE310003DF36 /* BTstackCocoa_Prefix.pch */, + 9C88A19110C7DE310003DF36 /* build */, + 9C88A1CF10C7DE310003DF36 /* icons */, + 9C88A1D610C7DE310003DF36 /* include */, + 9C88A1DA10C7DE310003DF36 /* src */, + ); + path = CocoaTouch; + sourceTree = ""; + }; + 9C88A18E10C7DE310003DF36 /* Products */ = { + isa = PBXGroup; + children = ( + 9C88A1F410C7DE320003DF36 /* BTstackCocoa.app */, + ); + name = Products; + sourceTree = ""; + }; + 9C88A19110C7DE310003DF36 /* build */ = { + isa = PBXGroup; + children = ( + 9C88A19210C7DE310003DF36 /* BTstackCocoa.build */, + 9C88A1C910C7DE310003DF36 /* Debug-iphoneos */, + 9C88A1CC10C7DE310003DF36 /* Debug-iphonesimulator */, + ); + path = build; + sourceTree = ""; + }; + 9C88A19210C7DE310003DF36 /* BTstackCocoa.build */ = { + isa = PBXGroup; + children = ( + 9C88A19310C7DE310003DF36 /* BTstackCocoa.pbxindex */, + 9C88A1A110C7DE310003DF36 /* Debug-iphoneos */, + 9C88A1B210C7DE310003DF36 /* Debug-iphonesimulator */, + ); + path = BTstackCocoa.build; + sourceTree = ""; + }; + 9C88A19310C7DE310003DF36 /* BTstackCocoa.pbxindex */ = { + isa = PBXGroup; + children = ( + 9C88A19410C7DE310003DF36 /* categories.pbxbtree */, + 9C88A19510C7DE310003DF36 /* cdecls.pbxbtree */, + 9C88A19610C7DE310003DF36 /* decls.pbxbtree */, + 9C88A19710C7DE310003DF36 /* files.pbxbtree */, + 9C88A19810C7DE310003DF36 /* imports.pbxbtree */, + 9C88A19910C7DE310003DF36 /* pbxindex.header */, + 9C88A19A10C7DE310003DF36 /* protocols.pbxbtree */, + 9C88A19B10C7DE310003DF36 /* refs.pbxbtree */, + 9C88A19C10C7DE310003DF36 /* strings.pbxstrings */, + 9C88A19F10C7DE310003DF36 /* subclasses.pbxbtree */, + 9C88A1A010C7DE310003DF36 /* symbols0.pbxsymbols */, + ); + path = BTstackCocoa.pbxindex; + sourceTree = ""; + }; + 9C88A19C10C7DE310003DF36 /* strings.pbxstrings */ = { + isa = PBXGroup; + children = ( + 9C88A19D10C7DE310003DF36 /* control */, + 9C88A19E10C7DE310003DF36 /* strings */, + ); + path = strings.pbxstrings; + sourceTree = ""; + }; + 9C88A1A110C7DE310003DF36 /* Debug-iphoneos */ = { + isa = PBXGroup; + children = ( + 9C88A1A210C7DE310003DF36 /* BTstackCocoa.build */, + ); + path = "Debug-iphoneos"; + sourceTree = ""; + }; + 9C88A1A210C7DE310003DF36 /* BTstackCocoa.build */ = { + isa = PBXGroup; + children = ( + 9C88A1A310C7DE310003DF36 /* BTstackCocoa-all-target-headers.hmap */, + 9C88A1A410C7DE310003DF36 /* BTstackCocoa-generated-files.hmap */, + 9C88A1A510C7DE310003DF36 /* BTstackCocoa-own-target-headers.hmap */, + 9C88A1A610C7DE310003DF36 /* BTstackCocoa-project-headers.hmap */, + 9C88A1A710C7DE310003DF36 /* BTstackCocoa.dep */, + 9C88A1A810C7DE310003DF36 /* BTstackCocoa.hmap */, + 9C88A1A910C7DE310003DF36 /* BTstackCocoa~.dep */, + 9C88A1AA10C7DE310003DF36 /* build-state.dat */, + 9C88A1AB10C7DE310003DF36 /* build-state~.dat */, + 9C88A1AC10C7DE310003DF36 /* Objects-normal */, + ); + path = BTstackCocoa.build; + sourceTree = ""; + }; + 9C88A1AC10C7DE310003DF36 /* Objects-normal */ = { + isa = PBXGroup; + children = ( + 9C88A1AD10C7DE310003DF36 /* armv6 */, + ); + path = "Objects-normal"; + sourceTree = ""; + }; + 9C88A1AD10C7DE310003DF36 /* armv6 */ = { + isa = PBXGroup; + children = ( + 9C88A1AE10C7DE310003DF36 /* BTDevice.o */, + 9C88A1AF10C7DE310003DF36 /* BTInquiryViewController.o */, + 9C88A1B010C7DE310003DF36 /* BTstackCocoa.LinkFileList */, + 9C88A1B110C7DE310003DF36 /* main.o */, + ); + path = armv6; + sourceTree = ""; + }; + 9C88A1B210C7DE310003DF36 /* Debug-iphonesimulator */ = { + isa = PBXGroup; + children = ( + 9C88A1B310C7DE310003DF36 /* BTstackCocoa.build */, + ); + path = "Debug-iphonesimulator"; + sourceTree = ""; + }; + 9C88A1B310C7DE310003DF36 /* BTstackCocoa.build */ = { + isa = PBXGroup; + children = ( + 9C88A1B410C7DE310003DF36 /* BTstackCocoa-all-target-headers.hmap */, + 9C88A1B510C7DE310003DF36 /* BTstackCocoa-generated-files.hmap */, + 9C88A1B610C7DE310003DF36 /* BTstackCocoa-own-target-headers.hmap */, + 9C88A1B710C7DE310003DF36 /* BTstackCocoa-project-headers.hmap */, + 9C88A1B810C7DE310003DF36 /* BTstackCocoa.dep */, + 9C88A1B910C7DE310003DF36 /* BTstackCocoa.hmap */, + 9C88A1BA10C7DE310003DF36 /* BTstackCocoa~.dep */, + 9C88A1BB10C7DE310003DF36 /* build-state.dat */, + 9C88A1BC10C7DE310003DF36 /* build-state~.dat */, + 9C88A1BD10C7DE310003DF36 /* Objects-normal */, + ); + path = BTstackCocoa.build; + sourceTree = ""; + }; + 9C88A1BD10C7DE310003DF36 /* Objects-normal */ = { + isa = PBXGroup; + children = ( + 9C88A1BE10C7DE310003DF36 /* i386 */, + ); + path = "Objects-normal"; + sourceTree = ""; + }; + 9C88A1BE10C7DE310003DF36 /* i386 */ = { + isa = PBXGroup; + children = ( + 9C88A1BF10C7DE310003DF36 /* BTDevice.o */, + 9C88A1C010C7DE310003DF36 /* BTInquiryViewController.o */, + 9C88A1C110C7DE310003DF36 /* BTInquiryViewController.o~$ */, + 9C88A1C210C7DE310003DF36 /* BTInquiryViewController.o~> */, + 9C88A1C310C7DE310003DF36 /* BTInquiryViewController.o~? */, + 9C88A1C410C7DE310003DF36 /* BTstackCocoa.LinkFileList */, + 9C88A1C510C7DE310003DF36 /* BTstackCocoaAppDelegate.o */, + 9C88A1C610C7DE310003DF36 /* BTstackCocoaAppDelegate.o~$ */, + 9C88A1C710C7DE310003DF36 /* BTstackCocoaAppDelegate.o~> */, + 9C88A1C810C7DE310003DF36 /* main.o */, + ); + path = i386; + sourceTree = ""; + }; + 9C88A1C910C7DE310003DF36 /* Debug-iphoneos */ = { + isa = PBXGroup; + children = ( + 9C88A1CA10C7DE310003DF36 /* BTstackCocoa.app */, + 9C88A1CB10C7DE310003DF36 /* BTstackCocoa.app.dSYM */, + ); + path = "Debug-iphoneos"; + sourceTree = ""; + }; + 9C88A1CC10C7DE310003DF36 /* Debug-iphonesimulator */ = { + isa = PBXGroup; + children = ( + 9C88A1CD10C7DE310003DF36 /* BTstackCocoa.app */, + 9C88A1CE10C7DE310003DF36 /* BTstackCocoa.app.dSYM */, + ); + path = "Debug-iphonesimulator"; + sourceTree = ""; + }; + 9C88A1CF10C7DE310003DF36 /* icons */ = { + isa = PBXGroup; + children = ( + 9C88A1D010C7DE310003DF36 /* bluetooth.png */, + 9C88A1D110C7DE310003DF36 /* computer.png */, + 9C88A1D210C7DE310003DF36 /* keyboard.png */, + 9C88A1D310C7DE310003DF36 /* LICENSE.txt */, + 9C88A1D410C7DE310003DF36 /* smartphone.png */, + 9C88A1D510C7DE310003DF36 /* Untitled.txt */, + ); + path = icons; + sourceTree = ""; + }; + 9C88A1D610C7DE310003DF36 /* include */ = { + isa = PBXGroup; + children = ( + 9C88A1D710C7DE310003DF36 /* BTstack */, + ); + path = include; + sourceTree = ""; + }; + 9C88A1D710C7DE310003DF36 /* BTstack */ = { + isa = PBXGroup; + children = ( + 9C88A1D810C7DE310003DF36 /* BTDevice.h */, + 9C88A1D910C7DE310003DF36 /* BTInquiryViewController.h */, + ); + path = BTstack; + sourceTree = ""; + }; + 9C88A1DA10C7DE310003DF36 /* src */ = { + isa = PBXGroup; + children = ( + 9C88A1DB10C7DE310003DF36 /* BTDevice.m */, + 9C88A1DC10C7DE310003DF36 /* BTInquiryViewController.m */, + 9C88A1DD10C7DE310003DF36 /* BTstackCocoaAppDelegate.h */, + 9C88A1DE10C7DE310003DF36 /* BTstackCocoaAppDelegate.m */, + 9C88A1DF10C7DE310003DF36 /* main.m */, + ); + path = src; + sourceTree = ""; + }; 9CEB4B7510715DC200DD5720 /* include */ = { isa = PBXGroup; children = ( @@ -310,6 +628,12 @@ hasScannedForEncodings = 1; mainGroup = 08FB7794FE84155DC02AAC07 /* project */; projectDirPath = ""; + projectReferences = ( + { + ProductGroup = 9C88A18E10C7DE310003DF36 /* Products */; + ProjectRef = 9C88A18D10C7DE310003DF36 /* BTstackCocoa.xcodeproj */; + }, + ); projectRoot = ""; targets = ( 8DD76FA90486AB0100D96B5E /* BTdaemon */, @@ -318,6 +642,16 @@ }; /* End PBXProject section */ +/* Begin PBXReferenceProxy section */ + 9C88A1F410C7DE320003DF36 /* BTstackCocoa.app */ = { + isa = PBXReferenceProxy; + fileType = wrapper.application; + path = BTstackCocoa.app; + remoteRef = 9C88A1F310C7DE320003DF36 /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; +/* End PBXReferenceProxy section */ + /* Begin PBXSourcesBuildPhase section */ 8DD76FAB0486AB0100D96B5E /* Sources */ = { isa = PBXSourcesBuildPhase; @@ -340,6 +674,10 @@ 9CEB4F17107AAAEF00DD5720 /* run_loop_posix.c in Sources */, 9C04B826107D1CED002A63D0 /* run_loop.c in Sources */, 9C04B876107D2B7C002A63D0 /* run_loop_cocoa.m in Sources */, + 9C88A1E910C7DE310003DF36 /* BTDevice.m in Sources */, + 9C88A1EA10C7DE310003DF36 /* BTInquiryViewController.m in Sources */, + 9C88A1EB10C7DE310003DF36 /* BTstackCocoaAppDelegate.m in Sources */, + 9C88A1EC10C7DE310003DF36 /* main.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/src/hci.c b/src/hci.c index 564ae61c0..06fcbbdc8 100644 --- a/src/hci.c +++ b/src/hci.c @@ -175,56 +175,62 @@ static void event_handler(uint8_t *packet, int size){ bd_addr_t addr; hci_con_handle_t handle; - // Get Num_HCI_Command_Packets - if (packet[0] == HCI_EVENT_COMMAND_COMPLETE || - packet[0] == HCI_EVENT_COMMAND_STATUS){ - hci_stack.num_cmd_packets = packet[2]; + switch (packet[0]) { + + case HCI_EVENT_COMMAND_COMPLETE: + case HCI_EVENT_COMMAND_STATUS: + // Get Num_HCI_Command_Packets + hci_stack.num_cmd_packets = packet[2]; + break; + + case HCI_EVENT_CONNECTION_COMPLETE: + // Connection management + bt_flip_addr(addr, &packet[5]); + printf("Connection_complete (status=%u)", packet[2]); print_bd_addr(addr); printf("\n"); + hci_connection_t * conn = connection_for_address(addr); + if (conn) { + if (!packet[2]){ + conn->state = OPEN; + conn->con_handle = READ_BT_16(packet, 3); + conn->flags = 0; + + gettimeofday(&conn->timestamp, NULL); + run_loop_set_timer(&conn->timeout, HCI_CONNECTION_TIMEOUT_MS); + run_loop_add_timer(&conn->timeout); + + printf("New connection: handle %u, ", conn->con_handle); + print_bd_addr( conn->address ); + printf("\n"); + + hci_emit_nr_connections_changed(); + } else { + // connection failed, remove entry + linked_list_remove(&hci_stack.connections, (linked_item_t *) conn); + free( conn ); + } + } + break; + + case HCI_EVENT_DISCONNECTION_COMPLETE: + if (!packet[2]){ + handle = READ_BT_16(packet, 3); + hci_connection_t * conn = connection_for_handle(handle); + if (conn) { + printf("Connection closed: handle %u, ", conn->con_handle); + print_bd_addr( conn->address ); + printf("\n"); + run_loop_remove_timer(&conn->timeout); + linked_list_remove(&hci_stack.connections, (linked_item_t *) conn); + free( conn ); + hci_emit_nr_connections_changed(); + } + } + break; + + default: + break; } - // Connection management - if (packet[0] == HCI_EVENT_CONNECTION_COMPLETE) { - bt_flip_addr(addr, &packet[5]); - printf("Connection_complete (status=%u)", packet[2]); print_bd_addr(addr); printf("\n"); - hci_connection_t * conn = connection_for_address(addr); - if (conn) { - if (!packet[2]){ - conn->state = OPEN; - conn->con_handle = READ_BT_16(packet, 3); - conn->flags = 0; - - gettimeofday(&conn->timestamp, NULL); - run_loop_set_timer(&conn->timeout, HCI_CONNECTION_TIMEOUT_MS); - run_loop_add_timer(&conn->timeout); - - printf("New connection: handle %u, ", conn->con_handle); - print_bd_addr( conn->address ); - printf("\n"); - - hci_emit_nr_connections_changed(); - } else { - // connection failed, remove entry - linked_list_remove(&hci_stack.connections, (linked_item_t *) conn); - free( conn ); - } - } - } - - if (packet[0] == HCI_EVENT_DISCONNECTION_COMPLETE) { - if (!packet[2]){ - handle = READ_BT_16(packet, 3); - hci_connection_t * conn = connection_for_handle(handle); - if (conn) { - printf("Connection closed: handle %u, ", conn->con_handle); - print_bd_addr( conn->address ); - printf("\n"); - run_loop_remove_timer(&conn->timeout); - linked_list_remove(&hci_stack.connections, (linked_item_t *) conn); - free( conn ); - hci_emit_nr_connections_changed(); - } - } - } - // handle BT initialization if (hci_stack.state == HCI_STATE_INITIALIZING){ // handle H4 synchronization loss on restart @@ -239,13 +245,6 @@ static void event_handler(uint8_t *packet, int size){ } } } - - // link key request - if (packet[0] == HCI_EVENT_LINK_KEY_REQUEST){ - bt_flip_addr(addr, &packet[2]); - hci_send_cmd(&hci_link_key_request_negative_reply, &addr); - return; - } hci_stack.event_packet_handler(packet, size);