Environment:
- Jailbroken iPhone 2.2.1
- XCode 3.1
Any time I try to open any of the BT devices on my phone, open is returning with -1.
I have logged in as root on my phone and executed chmod 7777 on each BT device under /dev with success.
Does anyone else have any ideas?
ls -l produces 'crwsrwsrwt' for all devices.
Full disclosure, I'm not a Unix pro.
Thanks, Will
Comment #1
Posted on Aug 30, 2009 by Happy RhinoOkay, I executed ps -ef and noticed that /user/sbin/BTServer is running, I'm assuming that this process is accessing the devices. How are others able to access the devices if they are already open by another process?
I have BlueTooth turned off.
Thanks, Will
Comment #2
Posted on Aug 31, 2009 by Swift OxHi William
As you have figured out, only one Bluetooth Stack can have access to the physical Bluetooth chipset. Even if you disable Bluetooth, BTserver might still have the device open. You can try reboot after turning Bluetooth off in the Settings. This should do the trick. I will add code to detect and at least give a warning.
In general, I rarely use Bluetooth tethering or play iPhone-2-iPhone games, and don't have (I didn't see) an Made for iPhone Bluetooth device yet, so the original stack is turned off, to save energy on my phone.
Comment #3
Posted on Aug 31, 2009 by Happy RhinoWhat is the preferred method of shutting down bluetooth?
I stumbled across a webpage detailing how to power down bluetooth, but will this free the devices?
Comment #4
Posted on Aug 31, 2009 by Swift OxHi again
although I have no problems enable Apple's Bluetooth, I recommend the following:
In /System/Library/LaunchDaemons/com.apple.BTServer.plist:
Change the value of the Disabled from to and do a "killall BTServer" as root. No chance for BTServer to survive, and you can enable it easily again.
I'll look into this, but won't find time in the next 2 weeks. If anybody knows how SBPrefs or BossPrefs disable Bluetooth, I'd be interested to hear and build upon their steps.
Matthias
Comment #5
Posted on Aug 31, 2009 by Helpful CamelSBSettings do it like:
CFPreferencesSetAppValue("bluetooth-network", value, "com.apple.preferences.network"); CFPreferencesAppSynchronize("com.apple.preferences.network");
Comment #6
Posted on Aug 31, 2009 by Helpful Camelvalue is of course CFBoolean..
Comment #7
Posted on Aug 31, 2009 by Swift Oxthanks frederik! that's standard Apple preferences code. :) do you know if this requires root permissions? Anyway, we can still have a script which setuid root to toggle.
Comment #8
Posted on Aug 31, 2009 by Swift Oxone more comment: BTServer running in not harmful. I just check that it is running. Then, I've enabled Bluetooth with the Settings.app. After some discovery, I've disabled it again. Then, I've started the example/test and it did work on the first try. On my iPhone 3G with 3.0, there's no additional requirement besides turning Bluetooth off. Probably there is another problem at your side Will, it shouldn't be the BTServer. Would be interesting to pin that down.
Comment #9
Posted on Sep 1, 2009 by Helpful CamelI don't think it requires root considering it's a standard documented call.
Comment #10
Posted on Sep 1, 2009 by Helpful CamelThe CFPreferencesSetAppValue probably only flips the switch inside the settings-pane. It's actually setPowered and setEnabled from the BluetoothManager-framework that does the work!
http://ericasadun.com/iPhoneDocs/_bluetooth_manager_8h-source.html
Comment #11
Posted on Sep 1, 2009 by Helpful Camel(I noticed they got called from SBSettings aswell) (Sorry for spam ;)
Comment #12
Posted on Sep 1, 2009 by Happy RhinoOkay.
So I've gotten BTServer to not run through setting its plist file. I've executed chmod 777 btreset and it looks like the file is available for everyone.
Whenever I attempt to open btreset, I receive a Permission Denied error when obtaining strerror.
Any thoughts.
Comment #13
Posted on Sep 1, 2009 by Swift OxHello William.
Are your trying to run BTdaemon from this project? BTdaemon does not use /dev/btreset or /dev/btwake. On the iPhone it uses the BlueTool command to setup everything. We use /dev/tty.bluetooth to talk to the BlueTooth chip.
Matthias
Comment #14
Posted on Sep 1, 2009 by Happy RhinoI just got the BTdaemon code to build correctly this evening.
Is there a function call or API I can make to test the /dev/tty.bluetooth device?
Since I can step through the daemon code, is it possible to make a call immediately after the setup function calls to verify all devices are open?
Thanks, Will
Comment #15
Posted on Sep 1, 2009 by Helpful CamelHi William, try running the testcode in example/, it will connect to the daemon which will connect to the device.
Comment #16
Posted on Sep 1, 2009 by Swift OxHi Will
I'm not sure I do understand you correctly, but if you've got BTdaemon to build and can step trough, you can add
hci_power_control(HCI_POWER_ON)
right before the call to run_loop_execute() in daemon.c. It will soon pass by iphone_on() which uses BlueTool to setup everything before it opens the serial port in h4_open() of hci_transport_h4.c
Comment #17
Posted on Sep 2, 2009 by Happy RhinoOkay.
Something is really funky with my phone.
In the function: iphone_on, my device can't open a process to the BlueTool.
When I fire up terminal on my phone I can run the BlueTool and execute commands, but when I step through the program in XCode nothing doing.
I feel like flinging this thing against the wall!
Comment #18
Posted on Sep 2, 2009 by Happy RhinoI'm starting to think that my phone is have jailbroken.
When iphone_on attempts to open the BlueTool process, errno is Operation Not Permitted.
Any ideas?
Comment #19
Posted on Sep 2, 2009 by Swift OxHi William
what do you mean by "my phone is have jailbroken". For the record, BTstack only works on an jailbroken phone.
I've put the [btstack.ringwald.ch/btstack-test-20090902-iphone current version of the test app and BTdaemon] online. Can you expand the zip, copy the files to your iPhone, sign them with ldid and try these? Use 2 session in MobileTerminal. Start the BTdaemon in the first and the test in the second.
By this, we can make sure that your running the same code as us.
Comment #20
Posted on Sep 2, 2009 by Swift Oxlink again: http://btstack.ringwald.ch/btstack-test-20090902-iphone.zip
Comment #21
Posted on Sep 3, 2009 by Happy RhinoOkay, my phone appears to be fully jailbroken.
I'm seriously close, I was able to execute your version of BTdaemon and the test program on my phone.
Didn't do anything because I could rebuild it with my wife's Wiimote controller.
My only problem at this moment is getting everything to build.
I had to update the make file and change IOkit to IOKit for one of the build steps.
I'm getting a lot of unresolved external symbols.
Here's the output when I run make, bootstrap and configure run successfully.
william-mapps-powerbook-g4-15:btstack-read-only willmapp$ make
Making all in src
gcc -DPACKAGE_NAME=\"BTstack\" -DPACKAGE_TARNAME=\"btstack\" -DPACKAGE_VERSION=\"0.1\" -
DPACKAGE_STRING=\"BTstack\ 0.1\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -
DPACKAGE=\"BTstack\" -DVERSION=\"0.1\" -I. -g -O2 -MT bt_control_iphone.o -MD -MP -MF
.deps/bt_control_iphone.Tpo -c -o bt_control_iphone.o bt_control_iphone.c
mv -f .deps/bt_control_iphone.Tpo .deps/bt_control_iphone.Po
gcc -DPACKAGE_NAME=\"BTstack\" -DPACKAGE_TARNAME=\"btstack\" -DPACKAGE_VERSION=\"0.1\" -
DPACKAGE_STRING=\"BTstack\ 0.1\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -
DPACKAGE=\"BTstack\" -DVERSION=\"0.1\" -I. -g -O2 -MT daemon.o -MD -MP -MF .deps/daemon.Tpo -
c -o daemon.o daemon.c
mv -f .deps/daemon.Tpo .deps/daemon.Po
gcc -DPACKAGE_NAME=\"BTstack\" -DPACKAGE_TARNAME=\"btstack\" -DPACKAGE_VERSION=\"0.1\" -
DPACKAGE_STRING=\"BTstack\ 0.1\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -
DPACKAGE=\"BTstack\" -DVERSION=\"0.1\" -I. -g -O2 -MT platform_iphone.o -MD -MP -MF
.deps/platform_iphone.Tpo -c -o platform_iphone.o platform_iphone.m
mv -f .deps/platform_iphone.Tpo .deps/platform_iphone.Po
gcc -DPACKAGE_NAME=\"BTstack\" -DPACKAGE_TARNAME=\"btstack\" -DPACKAGE_VERSION=\"0.1\" -
DPACKAGE_STRING=\"BTstack\ 0.1\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -
DPACKAGE=\"BTstack\" -DVERSION=\"0.1\" -I. -g -O2 -MT socket_connection.o -MD -MP -MF
.deps/socket_connection.Tpo -c -o socket_connection.o socket_connection.c
mv -f .deps/socket_connection.Tpo .deps/socket_connection.Po
gcc -g -O2 -o BTdaemon bt_control_iphone.o daemon.o hci.o hci_cmds.o hci_dump.o hci_transport_h4.o
l2cap.o l2cap_signaling.o platform_iphone.o linked_list.o run_loop.o socket_connection.o utils.o
ld warning: in hci.o, file is not of required architecture
ld warning: in hci_cmds.o, file is not of required architecture
ld warning: in hci_dump.o, file is not of required architecture
ld warning: in hci_transport_h4.o, file is not of required architecture
ld warning: in l2cap.o, file is not of required architecture
ld warning: in l2cap_signaling.o, file is not of required architecture
ld warning: in linked_list.o, file is not of required architecture
ld warning: in run_loop.o, file is not of required architecture
ld warning: in utils.o, file is not of required architecture
Undefined symbols:
"_hci_dump_open", referenced from:
_main in daemon.o
"_linked_list_add", referenced from:
_socket_connection_register_new_connection in socket_connection.o
"_bt_flip_addr", referenced from:
_daemon_client_handler in daemon.o
"_hci_power_control", referenced from:
_daemon_no_connections_timeout in daemon.o
_daemon_client_handler in daemon.o
_daemon_sigint_handler in daemon.o
"_hci_init", referenced from:
_main in daemon.o
"_l2cap_register_event_packet_handler", referenced from:
_main in daemon.o
"_run_loop_set_timer", referenced from:
_daemon_client_handler in daemon.o
"_run_loop_remove_timer", referenced from:
_daemon_client_handler in daemon.o
"_linked_list_remove", referenced from:
_socket_connection_free_connection in socket_connection.o
"_linked_item_get_user", referenced from:
_socket_connection_hci_process in socket_connection.o
_socket_connection_send_packet_all in socket_connection.o
"_bt_store_16", referenced from:
_socket_connection_send_packet in socket_connection.o
_socket_connection_send_packet in socket_connection.o
_socket_connection_send_packet in socket_connection.o
"_l2cap_send_internal", referenced from:
_daemon_client_handler in daemon.o
"_l2cap_init", referenced from:
_main in daemon.o
"_run_loop_remove_data_source", referenced from:
_socket_connection_free_connection in socket_connection.o
_socket_connection_close_tcp in socket_connection.o
_socket_connection_close_unix in socket_connection.o
"_l2cap_disconnect_internal", referenced from:
_daemon_client_handler in daemon.o
"_l2cap_close_channels_for_connection", referenced from:
_daemon_client_handler in daemon.o
"_hci_send_cmd_packet", referenced from:
_daemon_client_handler in daemon.o
"_l2cap_set_capture_connection", referenced from:
_daemon_client_handler in daemon.o
_daemon_client_handler in daemon.o
"_run_loop_add_data_source", referenced from:
_socket_connection_register_new_connection in socket_connection.o
_socket_connection_create_tcp in socket_connection.o
_socket_connection_create_unix in socket_connection.o
"_l2cap_create_channel_internal", referenced from:
_daemon_client_handler in daemon.o
"_hci_transport_h4_instance", referenced from:
_main in daemon.o
"_hci_send_acl_packet", referenced from:
_daemon_client_handler in daemon.o
"_run_loop_execute", referenced from:
_main in daemon.o
"_run_loop_add_timer", referenced from:
_daemon_client_handler in daemon.o
"_hci_dump_packet", referenced from:
_daemon_client_handler in daemon.o
"_linked_item_set_user", referenced from:
_socket_connection_register_new_connection in socket_connection.o
_socket_connection_register_new_connection in socket_connection.o
"_hci_emit_state", referenced from:
_daemon_client_handler in daemon.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
make[1]: * [BTdaemon] Error 1
make: * [all-recursive] Error 1
william-mapps-powerbook-g4-15:btstack-read-only willmapp$
Comment #22
Posted on Sep 3, 2009 by Happy RhinoWoo-Hoo!
Got it to build!
Missed the switch -target=iphone.
Doh! I feel like such a noob.
Okay, I'm onto poking through the HCI now. Is there a function for listing surrounding bluetooth devices?
Matthias, thanks for all of your help.
Comment #23
Posted on Sep 11, 2009 by Swift OxHi Will
the errors in comment 21 stem from the fact that you did have object files for different architectures (run "make clean" to fix this).
Anyway, to do an inquiry, you sent the HCI Inquiry command:
bt_send_cmd(&hci_inquiry, HCI_INQUIRY_LAP, 15, 0);
You will get the results asynchronously in your event handler. See src/mitm.c for some sample code.
All commands can be found in src/hci_cmds.c, it also lists the required parameters, also see the Bluetooth specification for further details.
Comment #24
Posted on Sep 22, 2009 by Swift Ox(No comment was entered for this change.)
Status: Fixed
Labels:
Type-Defect
Priority-Medium