├── Android.mk ├── data ├── network.conf ├── input.conf ├── blacklist.conf ├── auto_pairing.conf ├── audio.conf ├── main.conf ├── main.le.conf ├── main.nonsmartphone.conf └── main.nonsmartphone.le.conf ├── brfpatch ├── Android.mk └── brfpatch.c ├── brcm_patchram_plus ├── Android.mk └── brcm_patchram_plus.c ├── bluedroid ├── Android.mk ├── include │ └── bluedroid │ │ └── bluetooth.h └── bluetooth.c ├── tools ├── sock_shutdown_bug_l2cap.c ├── sock_shutdown_bug_tcp.c ├── sock_shutdown_bug_rfcomm.c ├── bttest.c ├── Android.mk ├── sock_shutdown_test.c ├── pipetest.c ├── asocket_test.c └── socktest.c ├── bluez-clean-headers └── bluetooth │ ├── hci_lib.h │ ├── sco.h │ ├── rfcomm.h │ ├── bluetooth.h │ └── l2cap.h └── CleanSpec.mk /Android.mk: -------------------------------------------------------------------------------- 1 | ifeq ($(BOARD_HAVE_BLUETOOTH),true) 2 | include $(all-subdir-makefiles) 3 | endif 4 | -------------------------------------------------------------------------------- /data/network.conf: -------------------------------------------------------------------------------- 1 | # Configuration file for the network service 2 | 3 | [General] 4 | 5 | # Disable link encryption: default=false 6 | #DisableSecurity=true 7 | -------------------------------------------------------------------------------- /data/input.conf: -------------------------------------------------------------------------------- 1 | # Configuration file for the input service 2 | 3 | # This section contains options which are not specific to any 4 | # particular interface 5 | [General] 6 | 7 | # Set idle timeout (in minutes) before the connection will 8 | # be disconnect (defaults to 0 for no timeout) 9 | #IdleTimeout=30 10 | -------------------------------------------------------------------------------- /brfpatch/Android.mk: -------------------------------------------------------------------------------- 1 | # Copyright 2007 The Android Open Source Project 2 | # 3 | # Utility to create Android bluetooth firmware from Texas Instruments .bts 4 | # scripts 5 | 6 | LOCAL_PATH:= $(call my-dir) 7 | include $(CLEAR_VARS) 8 | 9 | LOCAL_SRC_FILES := \ 10 | brfpatch.c 11 | 12 | LOCAL_MODULE := brfpatch 13 | 14 | include $(BUILD_HOST_EXECUTABLE) 15 | -------------------------------------------------------------------------------- /data/blacklist.conf: -------------------------------------------------------------------------------- 1 | // Do NOT change this file format without updating the parsing logic in 2 | // the modules that use this file (listed below): 3 | // android_bluetooth_ScoSocket.cpp 4 | 5 | // Module,Type,Value List,Parameter List, //Comment 6 | scoSocket:name,"MY-CAR",=ALL_ESCO_MASK;-ESCO_2EV5;-ESCO_3EV3;-ESCO_3EV5, // Infinity G35 7 | scoSocket:name,"Motorola HF850",=SCO_ESCO_MASK, // Motorola HF850 8 | -------------------------------------------------------------------------------- /brcm_patchram_plus/Android.mk: -------------------------------------------------------------------------------- 1 | ifeq ($(BOARD_HAVE_BLUETOOTH_BCM),true) 2 | 3 | LOCAL_PATH:= $(call my-dir) 4 | 5 | # 6 | # brcm_patchram_plus.c 7 | # 8 | 9 | include $(CLEAR_VARS) 10 | 11 | ifeq ($(TARGET_NEEDS_BLUETOOTH_INIT_DELAY),true) 12 | LOCAL_CFLAGS += -DBCM_INIT_DELAY 13 | endif 14 | 15 | ifeq ($(BOARD_HAVE_SAMSUNG_BLUETOOTH),true) 16 | LOCAL_CFLAGS += -DSAMSUNG_BLUETOOTH 17 | endif 18 | 19 | LOCAL_SRC_FILES := brcm_patchram_plus.c 20 | 21 | LOCAL_MODULE := brcm_patchram_plus 22 | 23 | LOCAL_SHARED_LIBRARIES := libcutils liblog 24 | 25 | LOCAL_C_FLAGS := \ 26 | -DANDROID 27 | 28 | include $(BUILD_EXECUTABLE) 29 | 30 | endif 31 | -------------------------------------------------------------------------------- /bluedroid/Android.mk: -------------------------------------------------------------------------------- 1 | # 2 | # libbluedroid 3 | # 4 | 5 | LOCAL_PATH:= $(call my-dir) 6 | 7 | include $(CLEAR_VARS) 8 | 9 | ifeq ($(TARGET_CUSTOM_BLUEDROID),) 10 | LOCAL_SRC_FILES := \ 11 | bluetooth.c 12 | else 13 | LOCAL_SRC_FILES := \ 14 | $(TARGET_CUSTOM_BLUEDROID) 15 | endif 16 | 17 | ifeq ($(BOARD_BLUETOOTH_DOES_NOT_USE_RFKILL),true) 18 | LOCAL_CFLAGS := $(LOCAL_CFLAGS) -DBLUETOOTH_DOES_NOT_USE_RFKILL 19 | endif 20 | 21 | ifeq ($(BOARD_BLUETOOTH_USES_HCIATTACH_PROPERTY),true) 22 | LOCAL_CFLAGS := $(LOCAL_CFLAGS) -DBLUETOOTH_HCIATTACH_USING_PROPERTY 23 | endif 24 | 25 | LOCAL_C_INCLUDES := \ 26 | $(LOCAL_PATH)/include \ 27 | system/bluetooth/bluez-clean-headers 28 | 29 | LOCAL_SHARED_LIBRARIES := \ 30 | libcutils \ 31 | liblog 32 | 33 | LOCAL_MODULE := libbluedroid 34 | 35 | include $(BUILD_SHARED_LIBRARY) 36 | -------------------------------------------------------------------------------- /tools/sock_shutdown_bug_l2cap.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2009 The Android Open Source Project 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | #include 24 | #include 25 | 26 | int main(int argc, char **argv) { 27 | int fd; 28 | int ret; 29 | long flags; 30 | struct sockaddr_l2 addr; 31 | 32 | addr.l2_family = AF_BLUETOOTH; 33 | str2ba("00:01:02:0A:0B:0C", &addr.l2_bdaddr); 34 | addr.l2_psm = htobs(1); 35 | 36 | fd = socket(PF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_L2CAP); 37 | flags = fcntl(fd, F_GETFL); 38 | fcntl(fd, F_SETFL, flags | O_NONBLOCK); 39 | 40 | connect(fd, (struct sockaddr *)&addr, sizeof(addr)); 41 | 42 | sleep(1); 43 | shutdown(fd, SHUT_RDWR); 44 | sleep(1); 45 | close(fd); 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /data/auto_pairing.conf: -------------------------------------------------------------------------------- 1 | // Do NOT change this file format without updating the parsing logic in 2 | // BluetoothService.java 3 | 4 | // This file contains information to prevent auto pairing with Bluetooth devices. 5 | // Blacklisting by vendor prefix address: 6 | // The following companies are included in the list below: 7 | // ALPS (lexus), Murata (Prius 2007, Nokia 616), TEMIC SDS (Porsche, Audi), 8 | // Parrot, Zhongshan General K-mate Electronics, Great Well 9 | // Electronics, Flaircomm Electronics, Jatty Electronics, Delphi, 10 | // Clarion, Novero, Denso (Lexus, Toyota), Johnson Controls (Acura), 11 | // Continental Automotive, Harman/Becker, Panasonic/Kyushu Ten, 12 | // BMW (Motorola PCS), Visteon, Peugeot, BMW (MINI10013) 13 | AddressBlacklist=00:02:C7,00:16:FE,00:19:C1,00:1B:FB,00:1E:3D,00:21:4F,00:23:06,00:24:33,00:A0:79,00:0E:6D,00:13:E0,00:21:E8,00:60:57,00:0E:9F,00:12:1C,00:18:91,00:18:96,00:13:04,00:16:FD,00:22:A0,00:0B:4C,00:60:6F,00:23:3D,00:C0:59,00:0A:30,00:1E:AE,00:1C:D7,00:80:F0,00:12:8A,00:09:93,00:80:37,00:26:7E 14 | 15 | // Blacklisting by Exact Name: 16 | ExactNameBlacklist=Motorola IHF1000,i.TechBlueBAND,X5 Stereo v1.3,KML_CAN 17 | 18 | // Blacklisting by Partial Name (if name starts with) 19 | PartialNameBlacklist=BMW,Audi,Parrot,Car 20 | 21 | // Fixed PIN keyboard blacklist. Keyboards should have variable PIN 22 | // The keyboards below have a fixed PIN of 0000, so we will auto pair. 23 | // Note the reverse logic in this case compared to other's in this file 24 | // where its a blacklist for not auto pairing. 25 | FixedPinZerosKeyboardBlacklist=00:0F:F6 26 | 27 | // Blacklisting by addition of the address during usage 28 | -------------------------------------------------------------------------------- /bluedroid/include/bluedroid/bluetooth.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef __BLUEDROID_BLUETOOTH_H__ 18 | #define __BLUEDROID_BLUETOOTH_H__ 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | #include 23 | 24 | /* Enable the bluetooth interface. 25 | * 26 | * Responsible for power on, bringing up HCI interface, and starting daemons. 27 | * Will block until the HCI interface and bluetooth daemons are ready to 28 | * use. 29 | * 30 | * Returns 0 on success, -ve on error */ 31 | int bt_enable(); 32 | 33 | /* Disable the bluetooth interface. 34 | * 35 | * Responsbile for stopping daemons, pulling down the HCI interface, and 36 | * powering down the chip. Will block until power down is complete, and it 37 | * is safe to immediately call enable(). 38 | * 39 | * Returns 0 on success, -ve on error */ 40 | int bt_disable(); 41 | 42 | /* Returns 1 if enabled, 0 if disabled, and -ve on error */ 43 | int bt_is_enabled(); 44 | 45 | int ba2str(const bdaddr_t *ba, char *str); 46 | int str2ba(const char *str, bdaddr_t *ba); 47 | 48 | #ifdef __cplusplus 49 | } 50 | #endif 51 | #endif //__BLUEDROID_BLUETOOTH_H__ 52 | -------------------------------------------------------------------------------- /tools/sock_shutdown_bug_tcp.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2009 The Android Open Source Project 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | int main(int argc, char **argv) { 26 | int fd; 27 | int ret; 28 | long flags; 29 | struct sockaddr_in addr; 30 | 31 | addr.sin_family = AF_INET; 32 | addr.sin_port = 12348; 33 | 34 | fd = socket(PF_INET, SOCK_STREAM, 0); 35 | 36 | ret = bind(fd, (struct sockaddr *)&addr, sizeof(addr)); 37 | if (ret < 0) { 38 | printf("%d errno %d %s\n", __LINE__, errno, strerror(errno)); 39 | } 40 | 41 | ret = listen(fd, 1); 42 | if (ret < 0) { 43 | printf("%d errno %d %s\n", __LINE__, errno, strerror(errno)); 44 | } 45 | 46 | sleep(2); 47 | 48 | close(fd); 49 | 50 | sleep(2); 51 | 52 | fd = socket(PF_INET, SOCK_STREAM, 0); 53 | 54 | ret = bind(fd, (struct sockaddr *)&addr, sizeof(addr)); 55 | if (ret < 0) { 56 | printf("%d errno %d %s\n", __LINE__, errno, strerror(errno)); 57 | } 58 | 59 | sleep(2000000000); 60 | 61 | return 0; 62 | } 63 | 64 | -------------------------------------------------------------------------------- /bluez-clean-headers/bluetooth/hci_lib.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | **************************************************************************** 3 | *** 4 | *** This header was automatically generated from a Bluez header 5 | *** of the same name, to make information necessary for userspace to 6 | *** call into the kernel available to Android. It contains only constants, 7 | *** structures, and macros generated from the original header, and thus, 8 | *** contains no copyrightable information. 9 | *** 10 | *** To edit the content of this header, modify the corresponding 11 | *** source file (e.g. under external/kernel-headers/original/) then 12 | *** run bionic/libc/kernel/tools/update_all.py 13 | *** 14 | *** Any manual change here will be lost the next time this script will 15 | *** be run. You've been warned! 16 | *** 17 | **************************************************************************** 18 | ****************************************************************************/ 19 | #ifndef __HCI_LIB_H 20 | #define __HCI_LIB_H 21 | #ifdef __cplusplus 22 | #endif 23 | /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ 24 | struct hci_request { 25 | uint16_t ogf; 26 | uint16_t ocf; 27 | int event; 28 | /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ 29 | void *cparam; 30 | int clen; 31 | void *rparam; 32 | int rlen; 33 | /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ 34 | }; 35 | struct hci_version { 36 | uint16_t manufacturer; 37 | uint8_t hci_ver; 38 | /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ 39 | uint16_t hci_rev; 40 | uint8_t lmp_ver; 41 | uint16_t lmp_subver; 42 | }; 43 | /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ 44 | #ifdef __cplusplus 45 | #endif 46 | #endif 47 | 48 | -------------------------------------------------------------------------------- /tools/sock_shutdown_bug_rfcomm.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2009 The Android Open Source Project 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | #include 25 | #include 26 | 27 | int main(int argc, char **argv) { 28 | int fd; 29 | int ret; 30 | long flags; 31 | struct sockaddr_rc addr; 32 | 33 | addr.rc_family = AF_BLUETOOTH; 34 | addr.rc_channel = 19; 35 | str2ba("00:17:E8:2C:A8:00", &addr.rc_bdaddr); 36 | 37 | fd = socket(PF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM); 38 | flags = fcntl(fd, F_GETFL); 39 | fcntl(fd, F_SETFL, flags | O_NONBLOCK); 40 | 41 | ret = connect(fd, (struct sockaddr *)&addr, sizeof(addr)); 42 | if (ret < 0) { 43 | printf("%d errno %d %s\n", __LINE__, errno, strerror(errno)); 44 | } 45 | 46 | sleep(2); 47 | shutdown(fd, SHUT_RDWR); 48 | 49 | 50 | fd = socket(PF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM); 51 | 52 | ret = connect(fd, (struct sockaddr *)&addr, sizeof(addr)); 53 | if (ret < 0) { 54 | printf("%d errno %d %s\n", __LINE__, errno, strerror(errno)); 55 | } 56 | 57 | sleep(2); 58 | 59 | shutdown(fd, SHUT_RDWR); 60 | 61 | sleep(2); 62 | return 0; 63 | } 64 | -------------------------------------------------------------------------------- /bluez-clean-headers/bluetooth/sco.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | **************************************************************************** 3 | *** 4 | *** This header was automatically generated from a Bluez header 5 | *** of the same name, to make information necessary for userspace to 6 | *** call into the kernel available to Android. It contains only constants, 7 | *** structures, and macros generated from the original header, and thus, 8 | *** contains no copyrightable information. 9 | *** 10 | *** To edit the content of this header, modify the corresponding 11 | *** source file (e.g. under external/kernel-headers/original/) then 12 | *** run bionic/libc/kernel/tools/update_all.py 13 | *** 14 | *** Any manual change here will be lost the next time this script will 15 | *** be run. You've been warned! 16 | *** 17 | **************************************************************************** 18 | ****************************************************************************/ 19 | #ifndef __SCO_H 20 | #define __SCO_H 21 | #ifdef __cplusplus 22 | #endif 23 | /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ 24 | #define SCO_DEFAULT_MTU 500 25 | #define SCO_DEFAULT_FLUSH_TO 0xFFFF 26 | #define SCO_CONN_TIMEOUT (HZ * 40) 27 | #define SCO_DISCONN_TIMEOUT (HZ * 2) 28 | /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ 29 | #define SCO_CONN_IDLE_TIMEOUT (HZ * 60) 30 | struct sockaddr_sco { 31 | sa_family_t sco_family; 32 | bdaddr_t sco_bdaddr; 33 | /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ 34 | uint16_t sco_pkt_type; 35 | }; 36 | #define SCO_OPTIONS 0x01 37 | struct sco_options { 38 | /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ 39 | uint16_t mtu; 40 | }; 41 | #define SCO_CONNINFO 0x02 42 | struct sco_conninfo { 43 | /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ 44 | uint16_t hci_handle; 45 | uint8_t dev_class[3]; 46 | }; 47 | #ifdef __cplusplus 48 | /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ 49 | #endif 50 | #endif 51 | 52 | -------------------------------------------------------------------------------- /tools/bttest.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2008 The Android Open Source Project 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | 17 | /** Bluedroid testing */ 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #include 26 | 27 | static int do_enable() { 28 | int ret; 29 | ret = bt_enable(); 30 | printf("= %d\n", ret); 31 | return ret; 32 | } 33 | 34 | static int do_disable() { 35 | int ret; 36 | ret = bt_disable(); 37 | printf("= %d\n", ret); 38 | return ret; 39 | } 40 | 41 | static int do_is_enabled() { 42 | int ret; 43 | ret = bt_is_enabled(); 44 | printf("= %d\n", ret); 45 | return ret; 46 | } 47 | 48 | struct { 49 | char *name; 50 | int (*ptr)(); 51 | } function_table[] = { 52 | {"enable", do_enable}, 53 | {"disable", do_disable}, 54 | {"is_enabled", do_is_enabled}, 55 | {NULL, NULL}, 56 | }; 57 | 58 | static void usage() { 59 | int i; 60 | 61 | printf("Usage:\n"); 62 | for (i = 0; function_table[i].name; i++) { 63 | printf("\tbttest %s\n", function_table[i].name); 64 | } 65 | } 66 | 67 | int main(int argc, char **argv) { 68 | int i; 69 | 70 | if (argc != 2) { 71 | usage(); 72 | return -1; 73 | } 74 | for (i = 0; function_table[i].name; i++) { 75 | if (!strcmp(argv[1], function_table[i].name)) { 76 | printf("%s\n", function_table[i].name); 77 | return (*function_table[i].ptr)(); 78 | } 79 | } 80 | usage(); 81 | return -1; 82 | } 83 | -------------------------------------------------------------------------------- /CleanSpec.mk: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2007 The Android Open Source Project 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | # If you don't need to do a full clean build but would like to touch 17 | # a file or delete some intermediate files, add a clean step to the end 18 | # of the list. These steps will only be run once, if they haven't been 19 | # run before. 20 | # 21 | # E.g.: 22 | # $(call add-clean-step, touch -c external/sqlite/sqlite3.h) 23 | # $(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/STATIC_LIBRARIES/libz_intermediates) 24 | # 25 | # Always use "touch -c" and "rm -f" or "rm -rf" to gracefully deal with 26 | # files that are missing or have been moved. 27 | # 28 | # Use $(PRODUCT_OUT) to get to the "out/target/product/blah/" directory. 29 | # Use $(OUT_DIR) to refer to the "out" directory. 30 | # 31 | # If you need to re-do something that's already mentioned, just copy 32 | # the command and add it to the bottom of the list. E.g., if a change 33 | # that you made last week required touching a file and a change you 34 | # made today requires touching the same file, just copy the old 35 | # touch step and add it to the end of the list. 36 | # 37 | # ************************************************ 38 | # NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST 39 | # ************************************************ 40 | 41 | # For example: 42 | #$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/APPS/AndroidTests_intermediates) 43 | #$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/JAVA_LIBRARIES/core_intermediates) 44 | #$(call add-clean-step, find $(OUT_DIR) -type f -name "IGTalkSession*" -print0 | xargs -0 rm -f) 45 | #$(call add-clean-step, rm -rf $(PRODUCT_OUT)/data/*) 46 | 47 | # ************************************************ 48 | # NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST 49 | # ************************************************ 50 | -------------------------------------------------------------------------------- /data/audio.conf: -------------------------------------------------------------------------------- 1 | # Configuration file for the audio service 2 | 3 | # This section contains options which are not specific to any 4 | # particular interface 5 | # NOTE: Enable=Sink means that bluetoothd exposes Sink interface for remote 6 | # devices, and the local device is a Source 7 | [General] 8 | Enable=Sink,Control 9 | Disable=Headset,Gateway,Source 10 | 11 | # Switch to master role for incoming connections (defaults to true) 12 | Master=false 13 | 14 | # If we want to disable support for specific services 15 | # Defaults to supporting all implemented services 16 | #Disable=Control,Source 17 | 18 | # SCO routing. Either PCM or HCI (in which case audio is routed to/from ALSA) 19 | # Defaults to HCI 20 | #SCORouting=PCM 21 | 22 | # Automatically connect both A2DP and HFP/HSP profiles for incoming 23 | # connections. Some headsets that support both profiles will only connect the 24 | # other one automatically so the default setting of true is usually a good 25 | # idea. 26 | #AutoConnect=true 27 | 28 | # Headset interface specific options (i.e. options which affect how the audio 29 | # service interacts with remote headset devices) 30 | #[Headset] 31 | 32 | # Set to true to support HFP (in addition to HSP only which is the default) 33 | # Defaults to false 34 | #HFP=true 35 | 36 | # Maximum number of connected HSP/HFP devices per adapter. Defaults to 1 37 | #MaxConnections=1 38 | 39 | # Set to true to enable use of fast connectable mode (faster page scanning) 40 | # for HFP when incomming call starts. Default settings are restored after 41 | # call is answered or rejected. Page scan interval is much shorter and page 42 | # scan type changed to interlaced. Such allows faster connection initiated 43 | # by a headset. 44 | FastConnectable=false 45 | 46 | # Just an example of potential config options for the other interfaces 47 | [A2DP] 48 | SBCSources=1 49 | MPEG12Sources=0 50 | 51 | [AVRCP] 52 | InputDeviceName=AVRCP 53 | # The Sony car stereo Ford is using under their brand as '6000 CD' has a 54 | # completely broken AVRCP 1.3 implementation. After recognizing AVRCP 1.3 TG 55 | # capabilities and exchanging a few PDUs, the car stereo disconnects and 56 | # reconnects BT, also resetting USB devices if connected to it. 57 | # To avoid that and allow at least HFP and A2DP to work, prevent any AVRCP 1.3 58 | # PDUs from being sent on those models - add the device to the black list. 59 | # Since 2012 Ford models have it fixed, removing the device from the list 60 | # will result in full functionality. 61 | MetaDataBlackList=Ford Audio 62 | -------------------------------------------------------------------------------- /data/main.conf: -------------------------------------------------------------------------------- 1 | [General] 2 | 3 | # List of plugins that should not be loaded on bluetoothd startup 4 | #DisablePlugins = network,input 5 | 6 | # Default adaper name 7 | # %h - substituted for hostname 8 | # %d - substituted for adapter id 9 | # %b - substituted for ro.product.brand 10 | # %m - substituted for ro.product.model 11 | # %n - substituted for ro.product.name 12 | Name = %m 13 | 14 | # Default device class. Only the major and minor device class bits are 15 | # considered. 16 | # Local device class 17 | # 0x400000 - Service class: Telephony 18 | # 0x000200 - Major class: Phone 19 | # 0x00000C - Minor class: Smart phone 20 | Class = 0x40020C 21 | 22 | # How long to stay in discoverable mode before going back to non-discoverable 23 | # The value is in seconds. Default is 180, i.e. 3 minutes. 24 | # 0 = disable timer, i.e. stay discoverable forever 25 | DiscoverableTimeout = 120 26 | 27 | # How long to stay in pairable mode before going back to non-discoverable 28 | # The value is in seconds. Default is 0. 29 | # 0 = disable timer, i.e. stay pairable forever 30 | PairableTimeout = 0 31 | 32 | # Use some other page timeout than the controller default one 33 | # which is 16384 (10 seconds). 34 | PageTimeout = 8192 35 | 36 | # Discover scheduler interval used in Adapter.DiscoverDevices 37 | # The value is in seconds. Defaults is 30. 38 | DiscoverSchedulerInterval = 30 39 | 40 | # What value should be assumed for the adapter Powered property when 41 | # SetProperty(Powered, ...) hasn't been called yet. Defaults to true 42 | InitiallyPowered = true 43 | 44 | # Remember the previously stored Powered state when initializing adapters 45 | RememberPowered = false 46 | 47 | # Use vendor, product and version information for DID profile support. 48 | # The values are separated by ":" and VID, PID and version. 49 | DeviceID = android:generic:1.5 50 | 51 | # Do reverse service discovery for previously unknown devices that connect to 52 | # us. This option is really only needed for qualification since the BITE tester 53 | # doesn't like us doing reverse SDP for some test cases (though there could in 54 | # theory be other useful purposes for this too). Defaults to true. 55 | ReverseServiceDiscovery = true 56 | 57 | # Enable name resolving after inquiry. Set it to 'false' if you don't need 58 | # remote devices name and want shorter discovery cycle. Defaults to 'true'. 59 | NameResolving = true 60 | 61 | # Enable runtime persistency of debug link keys. Default is false which 62 | # makes debug link keys valid only for the duration of the connection 63 | # that they were created for. 64 | DebugKeys = false 65 | 66 | # Enable Low Energy support if the dongle supports. Default is false. 67 | # Enable/Disable interleave discovery and attribute server over LE. 68 | EnableLE = false 69 | 70 | # Enable the GATT Attribute Server. Default is false, because it is only 71 | # useful for testing. Attribute server is not enabled over LE if EnableLE 72 | # is false. 73 | AttributeServer = false 74 | 75 | # The link policy for connections. By default it's set to 15(0x000f) which is 76 | # a bitwise OR of role switch(0x0001), hold mode(0x0002), sniff mode(0x0004) 77 | # and park state(0x0008) are all enabled. However, some devices have 78 | # connection stability issue or fail to setup SCO when the link is in park 79 | # state, which requires park state bit cleared. 80 | DefaultLinkPolicy = 7 81 | -------------------------------------------------------------------------------- /data/main.le.conf: -------------------------------------------------------------------------------- 1 | [General] 2 | 3 | # List of plugins that should not be loaded on bluetoothd startup 4 | #DisablePlugins = network,input 5 | 6 | # Default adaper name 7 | # %h - substituted for hostname 8 | # %d - substituted for adapter id 9 | # %b - substituted for ro.product.brand 10 | # %m - substituted for ro.product.model 11 | # %n - substituted for ro.product.name 12 | Name = %m 13 | 14 | # Default device class. Only the major and minor device class bits are 15 | # considered. 16 | # Local device class 17 | # 0x400000 - Service class: Telephony 18 | # 0x000200 - Major class: Phone 19 | # 0x00000C - Minor class: Smart phone 20 | Class = 0x40020C 21 | 22 | # How long to stay in discoverable mode before going back to non-discoverable 23 | # The value is in seconds. Default is 180, i.e. 3 minutes. 24 | # 0 = disable timer, i.e. stay discoverable forever 25 | DiscoverableTimeout = 120 26 | 27 | # How long to stay in pairable mode before going back to non-discoverable 28 | # The value is in seconds. Default is 0. 29 | # 0 = disable timer, i.e. stay pairable forever 30 | PairableTimeout = 0 31 | 32 | # Use some other page timeout than the controller default one 33 | # which is 16384 (10 seconds). 34 | PageTimeout = 8192 35 | 36 | # Discover scheduler interval used in Adapter.DiscoverDevices 37 | # The value is in seconds. Defaults is 30. 38 | DiscoverSchedulerInterval = 30 39 | 40 | # What value should be assumed for the adapter Powered property when 41 | # SetProperty(Powered, ...) hasn't been called yet. Defaults to true 42 | InitiallyPowered = true 43 | 44 | # Remember the previously stored Powered state when initializing adapters 45 | RememberPowered = false 46 | 47 | # Use vendor, product and version information for DID profile support. 48 | # The values are separated by ":" and VID, PID and version. 49 | DeviceID = android:generic:1.5 50 | 51 | # Do reverse service discovery for previously unknown devices that connect to 52 | # us. This option is really only needed for qualification since the BITE tester 53 | # doesn't like us doing reverse SDP for some test cases (though there could in 54 | # theory be other useful purposes for this too). Defaults to true. 55 | ReverseServiceDiscovery = true 56 | 57 | # Enable name resolving after inquiry. Set it to 'false' if you don't need 58 | # remote devices name and want shorter discovery cycle. Defaults to 'true'. 59 | NameResolving = true 60 | 61 | # Enable runtime persistency of debug link keys. Default is false which 62 | # makes debug link keys valid only for the duration of the connection 63 | # that they were created for. 64 | DebugKeys = false 65 | 66 | # Enable Low Energy support if the dongle supports. Default is false. 67 | # Enable/Disable interleave discovery and attribute server over LE. 68 | EnableLE = true 69 | 70 | # Enable the GATT Attribute Server. Default is false, because it is only 71 | # useful for testing. Attribute server is not enabled over LE if EnableLE 72 | # is false. 73 | AttributeServer = false 74 | 75 | # The link policy for connections. By default it's set to 15(0x000f) which is 76 | # a bitwise OR of role switch(0x0001), hold mode(0x0002), sniff mode(0x0004) 77 | # and park state(0x0008) are all enabled. However, some devices have 78 | # connection stability issue or fail to setup SCO when the link is in park 79 | # state, which requires park state bit cleared. 80 | DefaultLinkPolicy = 7 81 | -------------------------------------------------------------------------------- /data/main.nonsmartphone.conf: -------------------------------------------------------------------------------- 1 | [General] 2 | 3 | # List of plugins that should not be loaded on bluetoothd startup 4 | #DisablePlugins = network,input 5 | 6 | # Default adaper name 7 | # %h - substituted for hostname 8 | # %d - substituted for adapter id 9 | # %b - substituted for ro.product.brand 10 | # %m - substituted for ro.product.model 11 | # %n - substituted for ro.product.name 12 | Name = %m 13 | 14 | # Default device class. Only the major and minor device class bits are 15 | # considered. 16 | # Local device class 17 | # 0x0a0000 - Service class: Capturing (Microphone) + Networking 18 | # 0x000100 - Major class: Computer 19 | # 0x000010 - Minor class: Handheld 20 | Class = 0x0a0110 21 | 22 | # How long to stay in discoverable mode before going back to non-discoverable 23 | # The value is in seconds. Default is 180, i.e. 3 minutes. 24 | # 0 = disable timer, i.e. stay discoverable forever 25 | DiscoverableTimeout = 120 26 | 27 | # How long to stay in pairable mode before going back to non-discoverable 28 | # The value is in seconds. Default is 0. 29 | # 0 = disable timer, i.e. stay pairable forever 30 | PairableTimeout = 0 31 | 32 | # Use some other page timeout than the controller default one 33 | # which is 16384 (10 seconds). 34 | PageTimeout = 8192 35 | 36 | # Discover scheduler interval used in Adapter.DiscoverDevices 37 | # The value is in seconds. Defaults is 30. 38 | DiscoverSchedulerInterval = 30 39 | 40 | # What value should be assumed for the adapter Powered property when 41 | # SetProperty(Powered, ...) hasn't been called yet. Defaults to true 42 | InitiallyPowered = true 43 | 44 | # Remember the previously stored Powered state when initializing adapters 45 | RememberPowered = false 46 | 47 | # Use vendor, product and version information for DID profile support. 48 | # The values are separated by ":" and VID, PID and version. 49 | DeviceID = android:generic:1.5 50 | 51 | # Do reverse service discovery for previously unknown devices that connect to 52 | # us. This option is really only needed for qualification since the BITE tester 53 | # doesn't like us doing reverse SDP for some test cases (though there could in 54 | # theory be other useful purposes for this too). Defaults to true. 55 | ReverseServiceDiscovery = true 56 | 57 | # Enable name resolving after inquiry. Set it to 'false' if you don't need 58 | # remote devices name and want shorter discovery cycle. Defaults to 'true'. 59 | NameResolving = true 60 | 61 | # Enable runtime persistency of debug link keys. Default is false which 62 | # makes debug link keys valid only for the duration of the connection 63 | # that they were created for. 64 | DebugKeys = false 65 | 66 | # Enable Low Energy support if the dongle supports. Default is false. 67 | # Enable/Disable interleave discovery and attribute server over LE. 68 | EnableLE = false 69 | 70 | # Enable the GATT Attribute Server. Default is false, because it is only 71 | # useful for testing. Attribute server is not enabled over LE if EnableLE 72 | # is false. 73 | AttributeServer = false 74 | 75 | # The link policy for connections. By default it's set to 15(0x000f) which is 76 | # a bitwise OR of role switch(0x0001), hold mode(0x0002), sniff mode(0x0004) 77 | # and park state(0x0008) are all enabled. However, some devices have 78 | # connection stability issue or fail to setup SCO when the link is in park 79 | # state, which requires park state bit cleared. 80 | DefaultLinkPolicy = 7 81 | -------------------------------------------------------------------------------- /data/main.nonsmartphone.le.conf: -------------------------------------------------------------------------------- 1 | [General] 2 | 3 | # List of plugins that should not be loaded on bluetoothd startup 4 | #DisablePlugins = network,input 5 | 6 | # Default adaper name 7 | # %h - substituted for hostname 8 | # %d - substituted for adapter id 9 | # %b - substituted for ro.product.brand 10 | # %m - substituted for ro.product.model 11 | # %n - substituted for ro.product.name 12 | Name = %m 13 | 14 | # Default device class. Only the major and minor device class bits are 15 | # considered. 16 | # Local device class 17 | # 0x0a0000 - Service class: Capturing (Microphone) + Networking 18 | # 0x000100 - Major class: Computer 19 | # 0x00000C - Minor class: Handheld 20 | Class = 0x0a0110 21 | 22 | # How long to stay in discoverable mode before going back to non-discoverable 23 | # The value is in seconds. Default is 180, i.e. 3 minutes. 24 | # 0 = disable timer, i.e. stay discoverable forever 25 | DiscoverableTimeout = 120 26 | 27 | # How long to stay in pairable mode before going back to non-discoverable 28 | # The value is in seconds. Default is 0. 29 | # 0 = disable timer, i.e. stay pairable forever 30 | PairableTimeout = 0 31 | 32 | # Use some other page timeout than the controller default one 33 | # which is 16384 (10 seconds). 34 | PageTimeout = 8192 35 | 36 | # Discover scheduler interval used in Adapter.DiscoverDevices 37 | # The value is in seconds. Defaults is 30. 38 | DiscoverSchedulerInterval = 30 39 | 40 | # What value should be assumed for the adapter Powered property when 41 | # SetProperty(Powered, ...) hasn't been called yet. Defaults to true 42 | InitiallyPowered = true 43 | 44 | # Remember the previously stored Powered state when initializing adapters 45 | RememberPowered = false 46 | 47 | # Use vendor, product and version information for DID profile support. 48 | # The values are separated by ":" and VID, PID and version. 49 | DeviceID = android:generic:1.5 50 | 51 | # Do reverse service discovery for previously unknown devices that connect to 52 | # us. This option is really only needed for qualification since the BITE tester 53 | # doesn't like us doing reverse SDP for some test cases (though there could in 54 | # theory be other useful purposes for this too). Defaults to true. 55 | ReverseServiceDiscovery = true 56 | 57 | # Enable name resolving after inquiry. Set it to 'false' if you don't need 58 | # remote devices name and want shorter discovery cycle. Defaults to 'true'. 59 | NameResolving = true 60 | 61 | # Enable runtime persistency of debug link keys. Default is false which 62 | # makes debug link keys valid only for the duration of the connection 63 | # that they were created for. 64 | DebugKeys = false 65 | 66 | # Enable Low Energy support if the dongle supports. Default is false. 67 | # Enable/Disable interleave discovery and attribute server over LE. 68 | EnableLE = true 69 | 70 | # Enable the GATT Attribute Server. Default is false, because it is only 71 | # useful for testing. Attribute server is not enabled over LE if EnableLE 72 | # is false. 73 | AttributeServer = false 74 | 75 | # The link policy for connections. By default it's set to 15(0x000f) which is 76 | # a bitwise OR of role switch(0x0001), hold mode(0x0002), sniff mode(0x0004) 77 | # and park state(0x0008) are all enabled. However, some devices have 78 | # connection stability issue or fail to setup SCO when the link is in park 79 | # state, which requires park state bit cleared. 80 | DefaultLinkPolicy = 7 81 | -------------------------------------------------------------------------------- /tools/Android.mk: -------------------------------------------------------------------------------- 1 | BUILD_EXTRA_BT_TOOLS:=false 2 | 3 | LOCAL_PATH:= $(call my-dir) 4 | 5 | # 6 | # bttest 7 | # 8 | 9 | include $(CLEAR_VARS) 10 | 11 | LOCAL_SRC_FILES := bttest.c 12 | 13 | LOCAL_C_INCLUDES := \ 14 | $(LOCAL_PATH)/../bluedroid/include \ 15 | system/bluetooth/bluez-clean-headers 16 | 17 | LOCAL_SHARED_LIBRARIES := libbluedroid 18 | 19 | LOCAL_MODULE_PATH := $(TARGET_OUT_OPTIONAL_EXECUTABLES) 20 | LOCAL_MODULE_TAGS := eng 21 | LOCAL_MODULE := bttest 22 | 23 | include $(BUILD_EXECUTABLE) 24 | 25 | ifeq ($(BUILD_EXTRA_BT_TOOLS),true) 26 | 27 | # 28 | # socktest 29 | # 30 | 31 | include $(CLEAR_VARS) 32 | 33 | LOCAL_SRC_FILES := socktest.c 34 | 35 | LOCAL_C_INCLUDES := \ 36 | $(LOCAL_PATH)/../bluedroid/include \ 37 | $(LOCAL_PATH)/../bluez-clean-headers 38 | 39 | LOCAL_SHARED_LIBRARIES := libbluedroid 40 | 41 | LOCAL_MODULE_PATH := $(TARGET_OUT_OPTIONAL_EXECUTABLES) 42 | LOCAL_MODULE_TAGS := eng 43 | LOCAL_MODULE := socktest 44 | 45 | include $(BUILD_EXECUTABLE) 46 | 47 | # 48 | # asocket_test 49 | # 50 | 51 | include $(CLEAR_VARS) 52 | 53 | LOCAL_SRC_FILES := asocket_test.c 54 | 55 | LOCAL_C_INCLUDES := \ 56 | $(LOCAL_PATH)/../bluez-clean-headers 57 | 58 | LOCAL_SHARED_LIBRARIES := libcutils 59 | 60 | LOCAL_MODULE_PATH := $(TARGET_OUT_OPTIONAL_EXECUTABLES) 61 | LOCAL_MODULE_TAGS := eng 62 | LOCAL_MODULE := asocket_test 63 | 64 | include $(BUILD_EXECUTABLE) 65 | 66 | # 67 | # sock_shutdown_test 68 | # 69 | 70 | include $(CLEAR_VARS) 71 | 72 | LOCAL_SRC_FILES := sock_shutdown_test.c 73 | 74 | LOCAL_C_INCLUDES := \ 75 | $(LOCAL_PATH)/../bluez-clean-headers 76 | 77 | LOCAL_MODULE_PATH := $(TARGET_OUT_OPTIONAL_EXECUTABLES) 78 | LOCAL_MODULE_TAGS := eng 79 | LOCAL_MODULE := sock_shutdown_test 80 | 81 | include $(BUILD_EXECUTABLE) 82 | 83 | # 84 | # sock_shutdown_bug_l2cap 85 | # 86 | 87 | include $(CLEAR_VARS) 88 | 89 | LOCAL_SRC_FILES := sock_shutdown_bug_l2cap.c 90 | 91 | LOCAL_C_INCLUDES := \ 92 | $(LOCAL_PATH)/../bluez-clean-headers 93 | 94 | LOCAL_MODULE_PATH := $(TARGET_OUT_OPTIONAL_EXECUTABLES) 95 | LOCAL_MODULE_TAGS := eng 96 | LOCAL_MODULE := sock_shutdown_bug_l2cap 97 | 98 | LOCAL_SHARED_LIBRARIES := libbluetooth 99 | 100 | include $(BUILD_EXECUTABLE) 101 | 102 | # 103 | # sock_shutdown_bug_rfcomm 104 | # 105 | 106 | include $(CLEAR_VARS) 107 | 108 | LOCAL_SRC_FILES := sock_shutdown_bug_rfcomm.c 109 | 110 | LOCAL_C_INCLUDES := \ 111 | $(LOCAL_PATH)/../bluez-clean-headers 112 | 113 | LOCAL_MODULE_PATH := $(TARGET_OUT_OPTIONAL_EXECUTABLES) 114 | LOCAL_MODULE_TAGS := eng 115 | LOCAL_MODULE := sock_shutdown_bug_rfcomm 116 | 117 | LOCAL_SHARED_LIBRARIES := libbluetooth 118 | 119 | include $(BUILD_EXECUTABLE) 120 | 121 | # 122 | # sock_shutdown_bug_tcp 123 | # 124 | 125 | include $(CLEAR_VARS) 126 | 127 | LOCAL_SRC_FILES := sock_shutdown_bug_tcp.c 128 | 129 | LOCAL_MODULE_PATH := $(TARGET_OUT_OPTIONAL_EXECUTABLES) 130 | LOCAL_MODULE_TAGS := eng 131 | LOCAL_MODULE := sock_shutdown_bug_tcp 132 | 133 | LOCAL_SHARED_LIBRARIES := libbluetooth 134 | 135 | include $(BUILD_EXECUTABLE) 136 | # 137 | # pipetest 138 | # 139 | 140 | include $(CLEAR_VARS) 141 | 142 | LOCAL_SRC_FILES := pipetest.c 143 | 144 | LOCAL_MODULE_PATH := $(TARGET_OUT_OPTIONAL_EXECUTABLES) 145 | LOCAL_MODULE_TAGS := eng 146 | LOCAL_MODULE := pipetest 147 | 148 | include $(BUILD_EXECUTABLE) 149 | 150 | endif 151 | -------------------------------------------------------------------------------- /bluez-clean-headers/bluetooth/rfcomm.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | **************************************************************************** 3 | *** 4 | *** This header was automatically generated from a Bluez header 5 | *** of the same name, to make information necessary for userspace to 6 | *** call into the kernel available to Android. It contains only constants, 7 | *** structures, and macros generated from the original header, and thus, 8 | *** contains no copyrightable information. 9 | *** 10 | *** To edit the content of this header, modify the corresponding 11 | *** source file (e.g. under external/kernel-headers/original/) then 12 | *** run bionic/libc/kernel/tools/update_all.py 13 | *** 14 | *** Any manual change here will be lost the next time this script will 15 | *** be run. You've been warned! 16 | *** 17 | **************************************************************************** 18 | ****************************************************************************/ 19 | #ifndef __RFCOMM_H 20 | #define __RFCOMM_H 21 | #ifdef __cplusplus 22 | #endif 23 | /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ 24 | #include 25 | #define RFCOMM_DEFAULT_MTU 127 26 | #define RFCOMM_PSM 3 27 | struct sockaddr_rc { 28 | /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ 29 | sa_family_t rc_family; 30 | bdaddr_t rc_bdaddr; 31 | uint8_t rc_channel; 32 | }; 33 | /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ 34 | #define RFCOMM_CONNINFO 0x02 35 | struct rfcomm_conninfo { 36 | uint16_t hci_handle; 37 | uint8_t dev_class[3]; 38 | /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ 39 | }; 40 | #define RFCOMM_LM 0x03 41 | #define RFCOMM_LM_MASTER 0x0001 42 | #define RFCOMM_LM_AUTH 0x0002 43 | /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ 44 | #define RFCOMM_LM_ENCRYPT 0x0004 45 | #define RFCOMM_LM_TRUSTED 0x0008 46 | #define RFCOMM_LM_RELIABLE 0x0010 47 | #define RFCOMM_LM_SECURE 0x0020 48 | /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ 49 | #define RFCOMM_MAX_DEV 256 50 | #define RFCOMMCREATEDEV _IOW('R', 200, int) 51 | #define RFCOMMRELEASEDEV _IOW('R', 201, int) 52 | #define RFCOMMGETDEVLIST _IOR('R', 210, int) 53 | /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ 54 | #define RFCOMMGETDEVINFO _IOR('R', 211, int) 55 | struct rfcomm_dev_req { 56 | int16_t dev_id; 57 | uint32_t flags; 58 | /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ 59 | bdaddr_t src; 60 | bdaddr_t dst; 61 | uint8_t channel; 62 | }; 63 | /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ 64 | #define RFCOMM_REUSE_DLC 0 65 | #define RFCOMM_RELEASE_ONHUP 1 66 | #define RFCOMM_HANGUP_NOW 2 67 | #define RFCOMM_TTY_ATTACHED 3 68 | /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ 69 | struct rfcomm_dev_info { 70 | int16_t id; 71 | uint32_t flags; 72 | uint16_t state; 73 | /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ 74 | bdaddr_t src; 75 | bdaddr_t dst; 76 | uint8_t channel; 77 | }; 78 | /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ 79 | struct rfcomm_dev_list_req { 80 | uint16_t dev_num; 81 | struct rfcomm_dev_info dev_info[0]; 82 | }; 83 | /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ 84 | #ifdef __cplusplus 85 | #endif 86 | #endif 87 | 88 | -------------------------------------------------------------------------------- /bluez-clean-headers/bluetooth/bluetooth.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | **************************************************************************** 3 | *** 4 | *** This header was automatically generated from a Bluez header 5 | *** of the same name, to make information necessary for userspace to 6 | *** call into the kernel available to Android. It contains only constants, 7 | *** structures, and macros generated from the original header, and thus, 8 | *** contains no copyrightable information. 9 | *** 10 | *** To edit the content of this header, modify the corresponding 11 | *** source file (e.g. under external/kernel-headers/original/) then 12 | *** run bionic/libc/kernel/tools/update_all.py 13 | *** 14 | *** Any manual change here will be lost the next time this script will 15 | *** be run. You've been warned! 16 | *** 17 | **************************************************************************** 18 | ****************************************************************************/ 19 | #ifndef __BLUETOOTH_H 20 | #define __BLUETOOTH_H 21 | #ifdef __cplusplus 22 | #endif 23 | /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ 24 | #include 25 | #include 26 | #include 27 | #include 28 | /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ 29 | #include 30 | #ifndef AF_BLUETOOTH 31 | #define AF_BLUETOOTH 31 32 | #define PF_BLUETOOTH AF_BLUETOOTH 33 | /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ 34 | #endif 35 | #define BTPROTO_L2CAP 0 36 | #define BTPROTO_HCI 1 37 | #define BTPROTO_SCO 2 38 | /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ 39 | #define BTPROTO_RFCOMM 3 40 | #define BTPROTO_BNEP 4 41 | #define BTPROTO_CMTP 5 42 | #define BTPROTO_HIDP 6 43 | /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ 44 | #define BTPROTO_AVDTP 7 45 | #define SOL_HCI 0 46 | #define SOL_L2CAP 6 47 | #define SOL_SCO 17 48 | /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ 49 | #define SOL_RFCOMM 18 50 | #ifndef SOL_BLUETOOTH 51 | #define SOL_BLUETOOTH 274 52 | #endif 53 | /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ 54 | #define BT_SECURITY 4 55 | struct bt_security { 56 | uint8_t level; 57 | }; 58 | /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ 59 | #define BT_SECURITY_SDP 0 60 | #define BT_SECURITY_LOW 1 61 | #define BT_SECURITY_MEDIUM 2 62 | #define BT_SECURITY_HIGH 3 63 | /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ 64 | #define BT_DEFER_SETUP 7 65 | #define BT_FLUSHABLE 8 66 | #define BT_FLUSHABLE_OFF 0 67 | #define BT_FLUSHABLE_ON 1 68 | /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ 69 | #define BT_POWER 9 70 | struct bt_power { 71 | uint8_t force_active; 72 | }; 73 | /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ 74 | enum { 75 | BT_CONNECTED = 1, 76 | BT_OPEN, 77 | BT_BOUND, 78 | /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ 79 | BT_LISTEN, 80 | BT_CONNECT, 81 | BT_CONNECT2, 82 | BT_CONFIG, 83 | /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ 84 | BT_DISCONN, 85 | BT_CLOSED 86 | }; 87 | #if __BYTE_ORDER == __LITTLE_ENDIAN 88 | /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ 89 | #define htobs(d) (d) 90 | #define htobl(d) (d) 91 | #define btohs(d) (d) 92 | #define btohl(d) (d) 93 | /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ 94 | #elif __BYTE_ORDER == __BIG_ENDIAN 95 | #define htobs(d) bswap_16(d) 96 | #define htobl(d) bswap_32(d) 97 | #define btohs(d) bswap_16(d) 98 | /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ 99 | #define btohl(d) bswap_32(d) 100 | #else 101 | #error "Unknown byte order" 102 | #endif 103 | /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ 104 | #define bt_get_unaligned(ptr) ({ struct __attribute__((packed)) { typeof(*(ptr)) __v; } *__p = (void *) (ptr); __p->__v; }) 105 | #define bt_put_unaligned(val, ptr) do { struct __attribute__((packed)) { typeof(*(ptr)) __v; } *__p = (void *) (ptr); __p->__v = (val); } while(0) 106 | typedef struct { 107 | uint8_t b[6]; 108 | /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ 109 | } __attribute__((packed)) bdaddr_t; 110 | #define BDADDR_ANY (&(bdaddr_t) {{0, 0, 0, 0, 0, 0}}) 111 | #define BDADDR_ALL (&(bdaddr_t) {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff}}) 112 | #define BDADDR_LOCAL (&(bdaddr_t) {{0, 0, 0, 0xff, 0xff, 0xff}}) 113 | /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ 114 | #ifdef __cplusplus 115 | #endif 116 | #endif 117 | 118 | -------------------------------------------------------------------------------- /brfpatch/brfpatch.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2007, The Android Open Source Project 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | #define FAILIF(x, args...) do { \ 25 | if (x) { \ 26 | fprintf(stderr, ##args); \ 27 | exit(1); \ 28 | } \ 29 | } while(0) 30 | 31 | static void usage() { 32 | printf("Usage: brfpatch INPUT OUTPUT\n" 33 | "\n" 34 | "\tGenerates bluetooth firmware\n" 35 | "\n" 36 | "INPUT: Bluetooth script in ASCII format.\n" 37 | " For TI BRF chips this can be generated from .bts files using the TI Bluetooth\n" 38 | " script pad to save as .txt. This txt file can be used as input.\n" 39 | " Alternately, run strings on the .bts and manually edit to change decimal\n" 40 | " arguments into hex of the appropriate number of octets.\n" 41 | " FORMAT: Send_HCI_xxxx OPCODE DATA1 DATA2 DATA3 ...\n" 42 | " where OPCODE, DATA1 etc are one of:\n" 43 | " 0x12 (1 byte)\n" 44 | " 0x1234 (2 byte)\n" 45 | " 0x12345678 (4 byte)\n" 46 | " \"0123456789ABCDEF0123\" (multibyte)\n" 47 | " \"01:23:45:67:89:AB:CD:EF:01:23\" (multibyte)\n" 48 | "\n" 49 | "OUTPUT: Binary firmware\n" 50 | " FORMAT: 0x01 OPCODE DATA_LEN DATA\n"); 51 | exit(1); 52 | } 53 | 54 | static void dump_record(FILE *fpo, unsigned short opcode, unsigned char len, 55 | unsigned char *data) { 56 | 57 | unsigned char prefix = 0x01; // H4 UART command packet 58 | fwrite(&prefix, 1, 1, fpo); 59 | fwrite(&opcode, 2, 1, fpo); // opcode 60 | fwrite(&len, 1, 1, fpo); // data length 61 | fwrite(data, len, 1, fpo); // data 62 | } 63 | 64 | // advance beyond next whitespace. Return -1 if end of string reached 65 | static int advance(char **buf) { 66 | char *b = *buf; 67 | while (*b && !isspace(*b)) 68 | b++; 69 | while (*b && isspace(*b)) 70 | b++; 71 | *buf = b; 72 | if (!(*b)) 73 | return -1; 74 | return 0; 75 | } 76 | 77 | static void process_line(FILE *file_out, char *buf, char *buffer) { 78 | FAILIF(strncmp(buf, "Send_", 5) != 0, "Not expecting: %s\n", buffer); 79 | 80 | 81 | unsigned int opcode; 82 | 83 | FAILIF(advance(&buf), "Could not find opcode in: %s\n", buffer); 84 | FAILIF(sscanf(buf, "0x%04x\n", &opcode) != 1, 85 | "Could not find opcode in: %s\n", buffer); 86 | 87 | 88 | unsigned char data[1024]; 89 | unsigned char *dp = data; 90 | 91 | while (!advance(&buf)) { 92 | switch (*buf) { 93 | case '"': 94 | buf++; 95 | while (*buf != '"' && *buf != 0) { 96 | FAILIF(dp > data + sizeof(data), 97 | "Too much data: %s\n", buffer); 98 | FAILIF(sscanf(buf, "%02x", (unsigned int *)dp) != 1, 99 | "Error parsing (%d): %s\n", __LINE__, buffer); 100 | dp++; 101 | buf += 2; 102 | if (*buf == ':') 103 | buf++; 104 | } 105 | break; 106 | case '0': 107 | buf++; 108 | FAILIF(*buf != 'x', "Error parsing: %s\n", buffer); 109 | buf++; 110 | 111 | // find length of this piece of data 112 | char *end = buf; 113 | while (isalnum(*end)) 114 | end++; 115 | 116 | // switch on length 117 | switch ((unsigned int)end - (unsigned int)buf) { 118 | case 2: 119 | FAILIF(sscanf(buf, "%02x", (unsigned int *)dp) != 1, 120 | "Error parsing (%d): %s\n", __LINE__, buffer); 121 | buf += 2; 122 | dp += 1; 123 | break; 124 | case 4: 125 | FAILIF(sscanf(buf, "%04x", (unsigned int *)dp) != 1, 126 | "Error parsing (%d): %s\n", __LINE__, buffer); 127 | buf += 4; 128 | dp += 2; 129 | break; 130 | case 6: 131 | FAILIF(sscanf(buf, "%06x", (unsigned int *)dp) != 1, 132 | "Error parsing (%d): %s\n", __LINE__, buffer); 133 | buf += 6; 134 | dp += 3; 135 | break; 136 | case 8: 137 | FAILIF(sscanf(buf, "%08x", (unsigned int *)dp) != 1, 138 | "Error parsing (%d): %s\n", __LINE__, buffer); 139 | buf += 8; 140 | dp += 4; 141 | break; 142 | case 16: 143 | dp += 4; 144 | FAILIF(sscanf(buf, "%08x", (unsigned int *)dp) != 1, 145 | "Error parsing (%d): %s\n", __LINE__, buffer); 146 | buf += 8; 147 | dp -= 4; 148 | FAILIF(sscanf(buf, "%08x", (unsigned int *)dp) != 1, 149 | "Error parsing (%d): %s\n", __LINE__, buffer); 150 | buf += 8; 151 | dp += 8; 152 | break; 153 | default: 154 | FAILIF(1, "Error parsing (%d): %s\n", __LINE__, buffer); 155 | } 156 | break; 157 | default: 158 | FAILIF(1, "Error parsing (%d): %s\n", __LINE__, buffer); 159 | } 160 | } 161 | 162 | dump_record(file_out, opcode, dp - data, data); 163 | } 164 | 165 | 166 | int main(int argc, char **argv) { 167 | 168 | if (argc != 3) 169 | usage(); 170 | 171 | FILE *file_in = fopen(argv[1], "r"); 172 | FAILIF(!file_in, "Could not open %s: %s\n", argv[1], strerror(errno)); 173 | 174 | FILE *file_out = fopen(argv[2], "w+"); 175 | FAILIF(!file_out, "Could not open %s: %s\n", argv[2], strerror(errno)); 176 | 177 | char buffer[1024]; 178 | char *buf; 179 | 180 | while (fgets(buffer, 1024, file_in) != NULL) { 181 | buf = buffer; 182 | while (*buf && isspace(*buf)) 183 | buf++; 184 | switch (*buf) { 185 | case 'S': 186 | process_line(file_out, buf, buffer); 187 | break; 188 | case 'W': // Wait_HCI_Command... meta-data, not needed 189 | case '#': 190 | case 0: 191 | continue; 192 | default: 193 | FAILIF(1, "Don't know what to do with: %s\n", buffer); 194 | } 195 | } 196 | 197 | fclose(file_in); 198 | fclose(file_out); 199 | 200 | return 0; 201 | } 202 | -------------------------------------------------------------------------------- /bluez-clean-headers/bluetooth/l2cap.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | **************************************************************************** 3 | *** 4 | *** This header was automatically generated from a Bluez header 5 | *** of the same name, to make information necessary for userspace to 6 | *** call into the kernel available to Android. It contains only constants, 7 | *** structures, and macros generated from the original header, and thus, 8 | *** contains no copyrightable information. 9 | *** 10 | *** To edit the content of this header, modify the corresponding 11 | *** source file (e.g. under external/kernel-headers/original/) then 12 | *** run bionic/libc/kernel/tools/update_all.py 13 | *** 14 | *** Any manual change here will be lost the next time this script will 15 | *** be run. You've been warned! 16 | *** 17 | **************************************************************************** 18 | ****************************************************************************/ 19 | #ifndef __L2CAP_H 20 | #define __L2CAP_H 21 | #ifdef __cplusplus 22 | #endif 23 | /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ 24 | #include 25 | #define L2CAP_DEFAULT_MTU 672 26 | #define L2CAP_DEFAULT_FLUSH_TO 0xFFFF 27 | struct sockaddr_l2 { 28 | /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ 29 | sa_family_t l2_family; 30 | unsigned short l2_psm; 31 | bdaddr_t l2_bdaddr; 32 | unsigned short l2_cid; 33 | /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ 34 | }; 35 | #define L2CAP_OPTIONS 0x01 36 | struct l2cap_options { 37 | uint16_t omtu; 38 | /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ 39 | uint16_t imtu; 40 | uint16_t flush_to; 41 | uint8_t mode; 42 | uint8_t fcs; 43 | /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ 44 | uint8_t max_tx; 45 | uint16_t txwin_size; 46 | }; 47 | #define L2CAP_CONNINFO 0x02 48 | /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ 49 | struct l2cap_conninfo { 50 | uint16_t hci_handle; 51 | uint8_t dev_class[3]; 52 | }; 53 | /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ 54 | #define L2CAP_LM 0x03 55 | #define L2CAP_LM_MASTER 0x0001 56 | #define L2CAP_LM_AUTH 0x0002 57 | #define L2CAP_LM_ENCRYPT 0x0004 58 | /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ 59 | #define L2CAP_LM_TRUSTED 0x0008 60 | #define L2CAP_LM_RELIABLE 0x0010 61 | #define L2CAP_LM_SECURE 0x0020 62 | #define L2CAP_COMMAND_REJ 0x01 63 | /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ 64 | #define L2CAP_CONN_REQ 0x02 65 | #define L2CAP_CONN_RSP 0x03 66 | #define L2CAP_CONF_REQ 0x04 67 | #define L2CAP_CONF_RSP 0x05 68 | /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ 69 | #define L2CAP_DISCONN_REQ 0x06 70 | #define L2CAP_DISCONN_RSP 0x07 71 | #define L2CAP_ECHO_REQ 0x08 72 | #define L2CAP_ECHO_RSP 0x09 73 | /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ 74 | #define L2CAP_INFO_REQ 0x0a 75 | #define L2CAP_INFO_RSP 0x0b 76 | typedef struct { 77 | uint16_t len; 78 | /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ 79 | uint16_t cid; 80 | } __attribute__ ((packed)) l2cap_hdr; 81 | #define L2CAP_HDR_SIZE 4 82 | typedef struct { 83 | /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ 84 | uint8_t code; 85 | uint8_t ident; 86 | uint16_t len; 87 | } __attribute__ ((packed)) l2cap_cmd_hdr; 88 | /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ 89 | #define L2CAP_CMD_HDR_SIZE 4 90 | typedef struct { 91 | uint16_t reason; 92 | } __attribute__ ((packed)) l2cap_cmd_rej; 93 | /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ 94 | #define L2CAP_CMD_REJ_SIZE 2 95 | typedef struct { 96 | uint16_t psm; 97 | uint16_t scid; 98 | /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ 99 | } __attribute__ ((packed)) l2cap_conn_req; 100 | #define L2CAP_CONN_REQ_SIZE 4 101 | typedef struct { 102 | uint16_t dcid; 103 | /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ 104 | uint16_t scid; 105 | uint16_t result; 106 | uint16_t status; 107 | } __attribute__ ((packed)) l2cap_conn_rsp; 108 | /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ 109 | #define L2CAP_CONN_RSP_SIZE 8 110 | #define L2CAP_CR_SUCCESS 0x0000 111 | #define L2CAP_CR_PEND 0x0001 112 | #define L2CAP_CR_BAD_PSM 0x0002 113 | /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ 114 | #define L2CAP_CR_SEC_BLOCK 0x0003 115 | #define L2CAP_CR_NO_MEM 0x0004 116 | #define L2CAP_CS_NO_INFO 0x0000 117 | #define L2CAP_CS_AUTHEN_PEND 0x0001 118 | /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ 119 | #define L2CAP_CS_AUTHOR_PEND 0x0002 120 | typedef struct { 121 | uint16_t dcid; 122 | uint16_t flags; 123 | /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ 124 | uint8_t data[0]; 125 | } __attribute__ ((packed)) l2cap_conf_req; 126 | #define L2CAP_CONF_REQ_SIZE 4 127 | typedef struct { 128 | /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ 129 | uint16_t scid; 130 | uint16_t flags; 131 | uint16_t result; 132 | uint8_t data[0]; 133 | /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ 134 | } __attribute__ ((packed)) l2cap_conf_rsp; 135 | #define L2CAP_CONF_RSP_SIZE 6 136 | #define L2CAP_CONF_SUCCESS 0x0000 137 | #define L2CAP_CONF_UNACCEPT 0x0001 138 | /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ 139 | #define L2CAP_CONF_REJECT 0x0002 140 | #define L2CAP_CONF_UNKNOWN 0x0003 141 | typedef struct { 142 | uint8_t type; 143 | /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ 144 | uint8_t len; 145 | uint8_t val[0]; 146 | } __attribute__ ((packed)) l2cap_conf_opt; 147 | #define L2CAP_CONF_OPT_SIZE 2 148 | /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ 149 | #define L2CAP_CONF_MTU 0x01 150 | #define L2CAP_CONF_FLUSH_TO 0x02 151 | #define L2CAP_CONF_QOS 0x03 152 | #define L2CAP_CONF_RFC 0x04 153 | /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ 154 | #define L2CAP_CONF_FCS 0x05 155 | #define L2CAP_CONF_MAX_SIZE 22 156 | #define L2CAP_MODE_BASIC 0x00 157 | #define L2CAP_MODE_RETRANS 0x01 158 | /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ 159 | #define L2CAP_MODE_FLOWCTL 0x02 160 | #define L2CAP_MODE_ERTM 0x03 161 | #define L2CAP_MODE_STREAMING 0x04 162 | typedef struct { 163 | /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ 164 | uint16_t dcid; 165 | uint16_t scid; 166 | } __attribute__ ((packed)) l2cap_disconn_req; 167 | #define L2CAP_DISCONN_REQ_SIZE 4 168 | /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ 169 | typedef struct { 170 | uint16_t dcid; 171 | uint16_t scid; 172 | } __attribute__ ((packed)) l2cap_disconn_rsp; 173 | /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ 174 | #define L2CAP_DISCONN_RSP_SIZE 4 175 | typedef struct { 176 | uint16_t type; 177 | } __attribute__ ((packed)) l2cap_info_req; 178 | /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ 179 | #define L2CAP_INFO_REQ_SIZE 2 180 | typedef struct { 181 | uint16_t type; 182 | uint16_t result; 183 | /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ 184 | uint8_t data[0]; 185 | } __attribute__ ((packed)) l2cap_info_rsp; 186 | #define L2CAP_INFO_RSP_SIZE 4 187 | #define L2CAP_IT_CL_MTU 0x0001 188 | /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ 189 | #define L2CAP_IT_FEAT_MASK 0x0002 190 | #define L2CAP_IR_SUCCESS 0x0000 191 | #define L2CAP_IR_NOTSUPP 0x0001 192 | #ifdef __cplusplus 193 | /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ 194 | #endif 195 | #endif 196 | 197 | -------------------------------------------------------------------------------- /bluedroid/bluetooth.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #define LOG_TAG "bluedroid" 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #include 28 | #include 29 | 30 | #include 31 | #include 32 | #include 33 | 34 | #include 35 | 36 | #ifndef HCI_DEV_ID 37 | #define HCI_DEV_ID 0 38 | #endif 39 | 40 | #define HCID_STOP_DELAY_USEC 500000 41 | 42 | #define MIN(x,y) (((x)<(y))?(x):(y)) 43 | 44 | 45 | static int rfkill_id = -1; 46 | static char *rfkill_state_path = NULL; 47 | 48 | #ifndef BLUETOOTH_DOES_NOT_USE_RFKILL 49 | static int init_rfkill() { 50 | char path[64]; 51 | char buf[16]; 52 | int fd; 53 | int sz; 54 | int id; 55 | for (id = 0; ; id++) { 56 | snprintf(path, sizeof(path), "/sys/class/rfkill/rfkill%d/type", id); 57 | fd = open(path, O_RDONLY); 58 | if (fd < 0) { 59 | ALOGW("open(%s) failed: %s (%d)\n", path, strerror(errno), errno); 60 | return -1; 61 | } 62 | sz = read(fd, &buf, sizeof(buf)); 63 | close(fd); 64 | if (sz >= 9 && memcmp(buf, "bluetooth", 9) == 0) { 65 | rfkill_id = id; 66 | break; 67 | } 68 | } 69 | 70 | asprintf(&rfkill_state_path, "/sys/class/rfkill/rfkill%d/state", rfkill_id); 71 | return 0; 72 | } 73 | 74 | static int check_bluetooth_power() { 75 | int sz; 76 | int fd = -1; 77 | int ret = -1; 78 | char buffer; 79 | 80 | if (rfkill_id == -1) { 81 | if (init_rfkill()) goto out; 82 | } 83 | 84 | fd = open(rfkill_state_path, O_RDONLY); 85 | if (fd < 0) { 86 | ALOGE("open(%s) failed: %s (%d)", rfkill_state_path, strerror(errno), 87 | errno); 88 | goto out; 89 | } 90 | sz = read(fd, &buffer, 1); 91 | if (sz != 1) { 92 | ALOGE("read(%s) failed: %s (%d)", rfkill_state_path, strerror(errno), 93 | errno); 94 | goto out; 95 | } 96 | 97 | switch (buffer) { 98 | case '1': 99 | ret = 1; 100 | break; 101 | case '0': 102 | ret = 0; 103 | break; 104 | } 105 | 106 | out: 107 | if (fd >= 0) close(fd); 108 | return ret; 109 | } 110 | 111 | static int set_bluetooth_power(int on) { 112 | int sz; 113 | int fd = -1; 114 | int ret = -1; 115 | const char buffer = (on ? '1' : '0'); 116 | 117 | if (rfkill_id == -1) { 118 | if (init_rfkill()) goto out; 119 | } 120 | 121 | fd = open(rfkill_state_path, O_WRONLY); 122 | if (fd < 0) { 123 | ALOGE("open(%s) for write failed: %s (%d)", rfkill_state_path, 124 | strerror(errno), errno); 125 | goto out; 126 | } 127 | sz = write(fd, &buffer, 1); 128 | if (sz < 0) { 129 | ALOGE("write(%s) failed: %s (%d)", rfkill_state_path, strerror(errno), 130 | errno); 131 | goto out; 132 | } 133 | ret = 0; 134 | 135 | out: 136 | if (fd >= 0) close(fd); 137 | return ret; 138 | } 139 | #endif 140 | 141 | static inline int create_hci_sock() { 142 | int sk = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI); 143 | if (sk < 0) { 144 | ALOGE("Failed to create bluetooth hci socket: %s (%d)", 145 | strerror(errno), errno); 146 | } 147 | return sk; 148 | } 149 | 150 | int bt_enable() { 151 | ALOGV(__FUNCTION__); 152 | 153 | int ret = -1; 154 | int hci_sock = -1; 155 | int attempt; 156 | 157 | #ifndef BLUETOOTH_DOES_NOT_USE_RFKILL 158 | if (set_bluetooth_power(1) < 0) goto out; 159 | #endif 160 | 161 | #ifndef BLUETOOTH_HCIATTACH_USING_PROPERTY 162 | ALOGI("Starting hciattach daemon"); 163 | if (property_set("ctl.start", "hciattach") < 0) 164 | #else 165 | ALOGI("Enable hci tranport"); 166 | if (property_set("bluetooth.hciattach", "true") < 0) 167 | #endif 168 | { 169 | ALOGE("Failed to start hciattach"); 170 | #ifndef BLUETOOTH_DOES_NOT_USE_RFKILL 171 | set_bluetooth_power(0); 172 | #endif 173 | goto out; 174 | } 175 | 176 | // Try for 10 seconds, this can only succeed once hciattach has sent the 177 | // firmware and then turned on hci device via HCIUARTSETPROTO ioctl 178 | for (attempt = 100; attempt > 0; attempt--) { 179 | hci_sock = create_hci_sock(); 180 | if (hci_sock < 0) goto out; 181 | 182 | ret = ioctl(hci_sock, HCIDEVUP, HCI_DEV_ID); 183 | 184 | if (!ret) { 185 | break; 186 | } else if (errno == EALREADY) { 187 | ALOGW("Bluetoothd already started, unexpectedly!"); 188 | break; 189 | } 190 | 191 | ALOGI("%s: ioctl(%d, HCIDEVUP, HCI_DEV_ID) failed: %s (%d)", 192 | __FUNCTION__, hci_sock, strerror(errno), errno); 193 | 194 | close(hci_sock); 195 | usleep(100 * 1000); // 100 ms retry delay 196 | } 197 | if (attempt == 0) { 198 | ALOGE("%s: Timeout waiting for HCI device to come up, error- %d, ", 199 | __FUNCTION__, ret); 200 | if (property_set("ctl.stop", "hciattach") < 0) { 201 | ALOGE("Error stopping hciattach"); 202 | } 203 | #ifndef BLUETOOTH_DOES_NOT_USE_RFKILL 204 | set_bluetooth_power(0); 205 | #endif 206 | goto out; 207 | } 208 | 209 | ALOGI("Starting bluetoothd deamon"); 210 | if (property_set("ctl.start", "bluetoothd") < 0) { 211 | ALOGE("Failed to start bluetoothd"); 212 | #ifndef BLUETOOTH_DOES_NOT_USE_RFKILL 213 | set_bluetooth_power(0); 214 | #endif 215 | goto out; 216 | } 217 | 218 | ret = 0; 219 | 220 | out: 221 | if (hci_sock >= 0) close(hci_sock); 222 | return ret; 223 | } 224 | 225 | int bt_disable() { 226 | ALOGV(__FUNCTION__); 227 | 228 | int ret = -1; 229 | int hci_sock = -1; 230 | 231 | ALOGI("Stopping bluetoothd deamon"); 232 | if (property_set("ctl.stop", "bluetoothd") < 0) { 233 | ALOGE("Error stopping bluetoothd"); 234 | goto out; 235 | } 236 | usleep(HCID_STOP_DELAY_USEC); 237 | 238 | hci_sock = create_hci_sock(); 239 | if (hci_sock < 0) goto out; 240 | ioctl(hci_sock, HCIDEVDOWN, HCI_DEV_ID); 241 | 242 | #ifndef BLUETOOTH_HCIATTACH_USING_PROPERTY 243 | ALOGI("Stopping hciattach deamon"); 244 | if (property_set("ctl.stop", "hciattach") < 0) 245 | #else 246 | ALOGI("Disable hci tranport"); 247 | if (property_set("bluetooth.hciattach", "false") < 0) 248 | #endif 249 | { 250 | ALOGE("Error stopping hciattach"); 251 | goto out; 252 | } 253 | 254 | #ifndef BLUETOOTH_DOES_NOT_USE_RFKILL 255 | if (set_bluetooth_power(0) < 0) { 256 | goto out; 257 | } 258 | #endif 259 | ret = 0; 260 | 261 | out: 262 | if (hci_sock >= 0) close(hci_sock); 263 | return ret; 264 | } 265 | 266 | int bt_is_enabled() { 267 | ALOGV(__FUNCTION__); 268 | 269 | int hci_sock = -1; 270 | int ret = -1; 271 | struct hci_dev_info dev_info; 272 | 273 | 274 | #ifndef BLUETOOTH_DOES_NOT_USE_RFKILL 275 | // Check power first 276 | ret = check_bluetooth_power(); 277 | if (ret == -1 || ret == 0) goto out; 278 | #endif 279 | 280 | ret = -1; 281 | 282 | // Power is on, now check if the HCI interface is up 283 | hci_sock = create_hci_sock(); 284 | if (hci_sock < 0) goto out; 285 | 286 | dev_info.dev_id = HCI_DEV_ID; 287 | if (ioctl(hci_sock, HCIGETDEVINFO, (void *)&dev_info) < 0) { 288 | ret = 0; 289 | goto out; 290 | } 291 | 292 | if (dev_info.flags & (1 << (HCI_UP & 31))) { 293 | ret = 1; 294 | } else { 295 | ret = 0; 296 | } 297 | 298 | out: 299 | if (hci_sock >= 0) close(hci_sock); 300 | return ret; 301 | } 302 | 303 | int ba2str(const bdaddr_t *ba, char *str) { 304 | return sprintf(str, "%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X", 305 | ba->b[5], ba->b[4], ba->b[3], ba->b[2], ba->b[1], ba->b[0]); 306 | } 307 | 308 | int str2ba(const char *str, bdaddr_t *ba) { 309 | int i; 310 | for (i = 5; i >= 0; i--) { 311 | ba->b[i] = (uint8_t) strtoul(str, (char **) &str, 16); 312 | str++; 313 | } 314 | return 0; 315 | } 316 | -------------------------------------------------------------------------------- /tools/sock_shutdown_test.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2009 The Android Open Source Project 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | 17 | /** testing behavior of shutdown() */ 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | enum sock_type { 42 | UNIX = 0, 43 | RFCOMM, 44 | SCO, 45 | L2CAP, 46 | TCP, 47 | }; 48 | 49 | struct thread_args { 50 | int fd; 51 | int type; 52 | int delay; 53 | }; 54 | 55 | struct sockaddr_un local_addr_un = {AF_UNIX, "/tmp/foo"}; 56 | struct sockaddr_rc local_addr_rc = {AF_BLUETOOTH, *BDADDR_ANY, 4}; 57 | struct sockaddr_sco local_addr_sco = {AF_BLUETOOTH, *BDADDR_LOCAL}; 58 | struct sockaddr_l2 local_addr_l2 = {AF_BLUETOOTH, htobs(0x1001), *BDADDR_ANY, 0}; 59 | struct sockaddr_in local_addr_in = {AF_INET, 9999, {0}, {0}}; 60 | 61 | struct sockaddr_un remote_addr_un ; 62 | struct sockaddr_rc remote_addr_rc ; 63 | struct sockaddr_sco remote_addr_sco ; 64 | struct sockaddr_l2 remote_addr_l2 ; 65 | struct sockaddr_in remote_addr_in ; 66 | 67 | static int _socket(int type) { 68 | int ret; 69 | int family = -1; 70 | int typ = -1; 71 | int protocol = -1; 72 | 73 | switch (type) { 74 | case UNIX: 75 | family = PF_UNIX; 76 | typ = SOCK_STREAM; 77 | protocol = 0; 78 | break; 79 | case RFCOMM: 80 | family = PF_BLUETOOTH; 81 | typ = SOCK_STREAM; 82 | protocol = BTPROTO_RFCOMM; 83 | break; 84 | case SCO: 85 | family = PF_BLUETOOTH; 86 | typ = SOCK_SEQPACKET; 87 | protocol = BTPROTO_SCO; 88 | break; 89 | case L2CAP: 90 | family = PF_BLUETOOTH; 91 | typ = SOCK_SEQPACKET; 92 | protocol = BTPROTO_L2CAP; 93 | break; 94 | case TCP: 95 | family = PF_INET; 96 | typ = SOCK_STREAM; 97 | protocol = 0; 98 | break; 99 | } 100 | 101 | printf("%d: socket()\n", gettid()); 102 | ret = socket(family, typ, protocol); 103 | printf("%d: socket() = %d\n", gettid(), ret); 104 | if (ret < 0) printf("\terr %d (%s)\n", errno, strerror(errno)); 105 | 106 | return ret; 107 | } 108 | 109 | static int _close(int fd) { 110 | int ret; 111 | 112 | printf("%d: close(%d)\n", gettid(), fd); 113 | ret = close(fd); 114 | printf("%d: close(%d) = %d\n", gettid(), fd, ret); 115 | if (ret < 0) printf("\terr %d (%s)\n", errno, strerror(errno)); 116 | 117 | return ret; 118 | } 119 | 120 | static int _bind(int fd, int type) { 121 | int len = 0; 122 | int ret; 123 | struct sockaddr *addr = NULL; 124 | 125 | switch (type) { 126 | case UNIX: 127 | unlink(local_addr_un.sun_path); 128 | addr = (struct sockaddr *) &local_addr_un; 129 | len = sizeof(local_addr_un); 130 | break; 131 | case RFCOMM: 132 | addr = (struct sockaddr *) &local_addr_rc; 133 | len = sizeof(local_addr_rc); 134 | break; 135 | case SCO: 136 | addr = (struct sockaddr *) &local_addr_sco; 137 | len = sizeof(local_addr_sco); 138 | break; 139 | case L2CAP: 140 | addr = (struct sockaddr *) &local_addr_l2; 141 | len = sizeof(local_addr_l2); 142 | break; 143 | case TCP: 144 | addr = (struct sockaddr *) &local_addr_in; 145 | len = sizeof(local_addr_in); 146 | break; 147 | } 148 | 149 | printf("%d: bind(%d)\n", gettid(), fd); 150 | ret = bind(fd, addr, len); 151 | printf("%d: bind(%d) = %d\n", gettid(), fd, ret); 152 | if (ret < 0) printf("\terr %d (%s)\n", errno, strerror(errno)); 153 | 154 | return ret; 155 | } 156 | 157 | static int _listen(int fd, int type) { 158 | int ret; 159 | 160 | printf("%d: listen(%d)\n", gettid(), fd); 161 | ret = listen(fd, 1); 162 | printf("%d: listen(%d) = %d\n", gettid(), fd, ret); 163 | if (ret < 0) printf("\terr %d (%s)\n", errno, strerror(errno)); 164 | 165 | return ret; 166 | } 167 | 168 | static int _accept(int fd, int type) { 169 | int ret; 170 | int len; 171 | struct sockaddr *addr = NULL; 172 | 173 | switch (type) { 174 | case UNIX: 175 | addr = (struct sockaddr *) &remote_addr_un; 176 | len = sizeof(remote_addr_un); 177 | break; 178 | case RFCOMM: 179 | addr = (struct sockaddr *) &remote_addr_rc; 180 | len = sizeof(remote_addr_rc); 181 | break; 182 | case SCO: 183 | addr = (struct sockaddr *) &remote_addr_sco; 184 | len = sizeof(remote_addr_sco); 185 | break; 186 | case L2CAP: 187 | addr = (struct sockaddr *) &remote_addr_l2; 188 | len = sizeof(remote_addr_l2); 189 | break; 190 | case TCP: 191 | addr = (struct sockaddr *) &remote_addr_in; 192 | len = sizeof(remote_addr_in); 193 | break; 194 | } 195 | 196 | printf("%d: accept(%d)\n", gettid(), fd); 197 | ret = accept(fd, addr, &len); 198 | printf("%d: accept(%d) = %d\n", gettid(), fd, ret); 199 | if (ret < 0) printf("\terr %d (%s)\n", errno, strerror(errno)); 200 | else { 201 | printf("\tlen = %d\n", len); 202 | } 203 | 204 | return ret; 205 | } 206 | 207 | static int _shutdown(int fd, int how) { 208 | int ret; 209 | 210 | printf("%d: shutdown(%d)\n", gettid(), fd); 211 | ret = shutdown(fd, how); 212 | printf("%d: shutdown(%d) = %d\n", gettid(), fd, ret); 213 | if (ret < 0) printf("\terr %d (%s)\n", errno, strerror(errno)); 214 | 215 | return ret; 216 | } 217 | 218 | static void thread_accept(struct thread_args *args) { 219 | printf("%d: START\n", gettid()); 220 | sleep(args->delay); 221 | _accept(args->fd, args->type); 222 | printf("%d: END\n", gettid()); 223 | } 224 | 225 | static int do_accept_shutdown(int type) { 226 | int fd; 227 | pthread_t thread; 228 | struct thread_args args = {-1, type, 0}; 229 | 230 | fd = _socket(type); 231 | if (fd < 0) goto error; 232 | 233 | if (_bind(fd, type) < 0) goto error; 234 | 235 | if (_listen(fd, type) < 0) goto error; 236 | 237 | args.fd = fd; 238 | pthread_create(&thread, NULL, (void *)thread_accept, (void *)&args); 239 | 240 | sleep(2); 241 | _shutdown(fd, SHUT_RDWR); 242 | 243 | pthread_join(thread, NULL); 244 | 245 | _close(fd); 246 | 247 | return 0; 248 | 249 | error: 250 | return -1; 251 | } 252 | 253 | struct { 254 | char *name; 255 | int (*ptr)(int); 256 | } action_table[] = { 257 | {"accept_shutdown", do_accept_shutdown}, 258 | {NULL, NULL}, 259 | }; 260 | 261 | struct { 262 | char *name; 263 | enum sock_type type; 264 | } type_table[] = { 265 | {"unix", UNIX}, 266 | {"rfcomm", RFCOMM}, 267 | {"sco", SCO}, 268 | {"l2cap", L2CAP}, 269 | {"tcp", TCP}, 270 | {NULL, -1}, 271 | }; 272 | 273 | static void usage() { 274 | int i; 275 | 276 | printf("sock_shutdown_test TYPE ACTION\n"); 277 | printf("\nTYPE:\n"); 278 | for (i = 0; type_table[i].name; i++) { 279 | printf("\t%s\n", type_table[i].name); 280 | } 281 | printf("\nACTION:\n"); 282 | for (i = 0; action_table[i].name; i++) { 283 | printf("\t%s\n", action_table[i].name); 284 | } 285 | } 286 | 287 | int main(int argc, char **argv) { 288 | int i; 289 | int type = -1; 290 | 291 | if (argc != 3) { 292 | usage(); 293 | return -1; 294 | } 295 | for (i = 0; type_table[i].name; i++) { 296 | if (!strcmp(argv[1], type_table[i].name)) { 297 | type = type_table[i].type; 298 | break; 299 | } 300 | } 301 | if (type == -1) { 302 | usage(); 303 | return -1; 304 | } 305 | for (i = 0; action_table[i].name; i++) { 306 | if (!strcmp(argv[2], action_table[i].name)) { 307 | printf("TYPE = %s ACTION = %s\n", type_table[type].name, 308 | action_table[i].name); 309 | return (*action_table[i].ptr)(type); 310 | } 311 | } 312 | usage(); 313 | return -1; 314 | } 315 | -------------------------------------------------------------------------------- /tools/pipetest.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /* Helper to test linux pipe's */ 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | static void print_events(int events) { 28 | if (events & POLLIN) printf("POLLIN "); 29 | if (events & POLLPRI) printf("POLLPRI "); 30 | if (events & POLLOUT) printf("POLLOUT "); 31 | if (events & POLLERR) printf("POLLERR "); 32 | if (events & POLLHUP) printf("POLLHUP "); 33 | if (events & POLLNVAL) printf("POLLNVAL "); 34 | printf("\n"); 35 | } 36 | 37 | static int _socketpair(int fd[2]) { 38 | int ret; 39 | printf("%d: socketpair()\n", gettid()); 40 | ret = socketpair(AF_UNIX, SOCK_STREAM, 0, fd); 41 | printf("%d: socketpair() = %d\n", gettid(), ret); 42 | if (ret) printf("\terr %d (%s)\n", errno, strerror(errno)); 43 | return ret; 44 | } 45 | 46 | static int _close(int fd) { 47 | int ret; 48 | printf("%d: close(%d)\n", gettid(), fd); 49 | ret = close(fd); 50 | printf("%d: close(%d) = %d\n", gettid(), fd, ret); 51 | if (ret) printf("\terr %d (%s)\n", errno, strerror(errno)); 52 | return ret; 53 | } 54 | 55 | static int _poll(struct pollfd *ufds, nfds_t nfds, int timeout) { 56 | int ret; 57 | unsigned int i; 58 | printf("%d: poll()\n", gettid()); 59 | ret = poll(ufds, nfds, timeout); 60 | printf("%d: poll() = %d\n", gettid(), ret); 61 | if (ret < 0) printf("\terr %d (%s)\n", errno, strerror(errno)); 62 | if (ret > 0) { 63 | for (i=0; i 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | #include "cutils/abort_socket.h" 42 | 43 | enum sock_type { 44 | UNIX = 0, 45 | RFCOMM, 46 | SCO, 47 | L2CAP, 48 | TCP, 49 | }; 50 | 51 | struct thread_args { 52 | int fd; 53 | int type; 54 | int delay; 55 | }; 56 | 57 | struct sockaddr_un local_addr_un = {AF_UNIX, "/data/foo"}; 58 | struct sockaddr_rc local_addr_rc = {AF_BLUETOOTH, *BDADDR_ANY, 4}; 59 | struct sockaddr_sco local_addr_sco = {AF_BLUETOOTH, *BDADDR_LOCAL}; 60 | struct sockaddr_l2 local_addr_l2 = {AF_BLUETOOTH, htobs(0x1001), *BDADDR_ANY, 0}; 61 | struct sockaddr_in local_addr_in = {AF_INET, 9999, {0}, {0}}; 62 | 63 | struct sockaddr_un remote_addr_un ; 64 | struct sockaddr_rc remote_addr_rc ; 65 | struct sockaddr_sco remote_addr_sco ; 66 | struct sockaddr_l2 remote_addr_l2 ; 67 | struct sockaddr_in remote_addr_in ; 68 | 69 | static void print_events(int events) { 70 | if (events & POLLIN) printf("POLLIN "); 71 | if (events & POLLPRI) printf("POLLPRI "); 72 | if (events & POLLOUT) printf("POLLOUT "); 73 | if (events & POLLERR) printf("POLLERR "); 74 | if (events & POLLHUP) printf("POLLHUP "); 75 | if (events & POLLNVAL) printf("POLLNVAL "); 76 | printf("\n"); 77 | } 78 | 79 | static void print_fds(struct pollfd *ufds, nfds_t nfds) { 80 | unsigned int i; 81 | for (i=0; i 0) { 308 | for (i=0; idelay); 320 | _close(args->fd, args->type); 321 | printf("%d: END\n", gettid()); 322 | } 323 | 324 | static void thread_poll(void *args) { 325 | int fd = (int)args; 326 | struct pollfd pfd; 327 | printf("%d: START\n", gettid()); 328 | pfd.fd = fd; 329 | pfd.events = 0; 330 | _poll(&pfd, 1, -1); 331 | printf("%d: END\n", gettid()); 332 | } 333 | 334 | static void thread_read(void *args) { 335 | int fd = (int)args; 336 | printf("%d: START\n", gettid()); 337 | _read(fd); 338 | printf("%d: END\n", gettid()); 339 | } 340 | 341 | static void thread_pollin(void *args) { 342 | int fd = (int)args; 343 | struct pollfd pfd; 344 | printf("%d: START\n", gettid()); 345 | pfd.fd = fd; 346 | pfd.events = POLLIN; 347 | _poll(&pfd, 1, -1); 348 | printf("%d: END\n", gettid()); 349 | } 350 | 351 | static void thread_shutdown(int fd) { 352 | printf("%d: START\n", gettid()); 353 | sleep(4); 354 | _shutdown(fd, SHUT_RDWR); 355 | printf("%d: END\n", gettid()); 356 | } 357 | 358 | static void thread_accept(struct thread_args *args) { 359 | printf("%d: START\n", gettid()); 360 | sleep(args->delay); 361 | _accept(args->fd, args->type); 362 | printf("%d: END\n", gettid()); 363 | } 364 | 365 | static void thread_connect(struct thread_args *args) { 366 | printf("%d: START\n", gettid()); 367 | sleep(args->delay); 368 | _connect(args->fd, args->type); 369 | printf("%d: END\n", gettid()); 370 | } 371 | 372 | static void thread_delay_close_write(struct thread_args *args) { 373 | printf("%d: START\n", gettid()); 374 | sleep(args->delay); 375 | _close(args->fd, args->type); 376 | sleep(args->delay); 377 | _write(args->fd, args->type); 378 | printf("%d: END\n", gettid()); 379 | } 380 | 381 | static void thread_accept_write(struct thread_args *args) { 382 | printf("%d: START\n", gettid()); 383 | sleep(args->delay); 384 | _accept(args->fd, args->type); 385 | sleep(args->delay); 386 | _write(args->fd, args->type); 387 | printf("%d: END\n", gettid()); 388 | } 389 | 390 | static void thread_delay_connect(struct thread_args *args) { 391 | printf("%d: START\n", gettid()); 392 | sleep(args->delay); 393 | args->fd = _socket(args->type); 394 | _connect(args->fd, args->type); 395 | printf("%d: END\n", gettid()); 396 | } 397 | 398 | static int do_accept_accept_accept(int type) { 399 | int fd; 400 | 401 | fd = _socket(type); 402 | if (fd < 0) goto error; 403 | 404 | if (_bind(fd, type) < 0) goto error; 405 | 406 | if (_listen(fd, type) < 0) goto error; 407 | 408 | while (1) { 409 | _accept(fd, type); 410 | } 411 | 412 | return 0; 413 | 414 | error: 415 | return -1; 416 | } 417 | 418 | static int do_accept_and_close(int type) { 419 | int fd; 420 | pthread_t thread; 421 | struct thread_args args = {-1, type, 1}; 422 | 423 | fd = _socket(type); 424 | if (fd < 0) goto error; 425 | 426 | if (_bind(fd, type) < 0) goto error; 427 | 428 | if (_listen(fd, type) < 0) goto error; 429 | 430 | args.fd = fd; 431 | pthread_create(&thread, NULL, (void *)thread_delay_close, (void *)&args); 432 | 433 | _accept(fd, type); 434 | 435 | pthread_join(thread, NULL); 436 | 437 | return 0; 438 | 439 | error: 440 | return -1; 441 | } 442 | 443 | static int do_accept_shutdown(int type) { 444 | int fd; 445 | pthread_t thread; 446 | struct thread_args args = {-1, type, 0}; 447 | 448 | fd = _socket(type); 449 | if (fd < 0) goto error; 450 | 451 | if (_bind(fd, type) < 0) goto error; 452 | 453 | if (_listen(fd, type) < 0) goto error; 454 | 455 | args.fd = fd; 456 | pthread_create(&thread, NULL, (void *)thread_accept, (void *)&args); 457 | 458 | sleep(4); 459 | _shutdown(fd, SHUT_RDWR); 460 | 461 | pthread_join(thread, NULL); 462 | 463 | _close(fd, type); 464 | 465 | return 0; 466 | 467 | error: 468 | return -1; 469 | } 470 | 471 | static int do_connect_shutdown(int type) { 472 | int fd; 473 | pthread_t thread; 474 | struct thread_args args = {-1, type, 0}; 475 | 476 | fd = _socket(type); 477 | if (fd < 0) goto error; 478 | 479 | args.fd = fd; 480 | pthread_create(&thread, NULL, (void *)thread_connect, (void *)&args); 481 | 482 | sleep(4); 483 | _shutdown(fd, SHUT_RDWR); 484 | 485 | pthread_join(thread, NULL); 486 | 487 | _close(fd, type); 488 | 489 | return 0; 490 | 491 | error: 492 | return -1; 493 | } 494 | 495 | // accept in one thread. close then write in another 496 | static int do_accept_close_write(int type) { 497 | int fd; 498 | pthread_t thread; 499 | struct thread_args args = {-1, type, 1}; 500 | 501 | fd = _socket(type); 502 | if (fd < 0) goto error; 503 | 504 | if (_bind(fd, type) < 0) goto error; 505 | 506 | if (_listen(fd, type) < 0) goto error; 507 | 508 | args.fd = fd; 509 | pthread_create(&thread, NULL, (void *)thread_delay_close_write, (void *)&args); 510 | 511 | _accept(fd, type); 512 | 513 | pthread_join(thread, NULL); 514 | 515 | return 0; 516 | 517 | error: 518 | return -1; 519 | } 520 | 521 | static int do_poll_poll_poll_shutdown(int type) { 522 | const int MAX_T = 32; 523 | int fd; 524 | pthread_t t[MAX_T]; 525 | int i; 526 | 527 | fd = _socket(type); 528 | 529 | for (i=0; i 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | #include 38 | #include 39 | #include 40 | #include 41 | 42 | enum sock_type { 43 | UNIX = 0, 44 | RFCOMM, 45 | SCO, 46 | L2CAP, 47 | TCP, 48 | }; 49 | 50 | struct thread_args { 51 | int fd; 52 | int type; 53 | int delay; 54 | }; 55 | 56 | struct sockaddr_un local_addr_un = {AF_UNIX, "/data/foo"}; 57 | struct sockaddr_rc local_addr_rc = {AF_BLUETOOTH, *BDADDR_ANY, 4}; 58 | struct sockaddr_sco local_addr_sco = {AF_BLUETOOTH, *BDADDR_LOCAL}; 59 | struct sockaddr_l2 local_addr_l2 = {AF_BLUETOOTH, htobs(0x1001), *BDADDR_ANY, 0}; 60 | struct sockaddr_in local_addr_in = {AF_INET, 9999, {0}, {0}}; 61 | 62 | struct sockaddr_un remote_addr_un ; 63 | struct sockaddr_rc remote_addr_rc ; 64 | struct sockaddr_sco remote_addr_sco ; 65 | struct sockaddr_l2 remote_addr_l2 ; 66 | struct sockaddr_in remote_addr_in ; 67 | 68 | static void print_events(int events) { 69 | if (events & POLLIN) printf("POLLIN "); 70 | if (events & POLLPRI) printf("POLLPRI "); 71 | if (events & POLLOUT) printf("POLLOUT "); 72 | if (events & POLLERR) printf("POLLERR "); 73 | if (events & POLLHUP) printf("POLLHUP "); 74 | if (events & POLLNVAL) printf("POLLNVAL "); 75 | printf("\n"); 76 | } 77 | 78 | static void print_fds(struct pollfd *ufds, nfds_t nfds) { 79 | unsigned int i; 80 | for (i=0; i 0) { 322 | for (i=0; idelay); 334 | _close(args->fd, args->type); 335 | printf("%ld: END\n", pthread_self()); 336 | } 337 | 338 | static void thread_poll(void *args) { 339 | int fd = (int)args; 340 | struct pollfd pfd; 341 | printf("%ld: START\n", pthread_self()); 342 | pfd.fd = fd; 343 | pfd.events = 0; 344 | _poll(&pfd, 1, -1); 345 | printf("%ld: END\n", pthread_self()); 346 | } 347 | 348 | static void thread_read(void *args) { 349 | int fd = (int)args; 350 | printf("%ld: START\n", pthread_self()); 351 | _read(fd); 352 | printf("%ld: END\n", pthread_self()); 353 | } 354 | 355 | static void thread_pollin(void *args) { 356 | int fd = (int)args; 357 | struct pollfd pfd; 358 | printf("%ld: START\n", pthread_self()); 359 | pfd.fd = fd; 360 | pfd.events = POLLIN; 361 | _poll(&pfd, 1, -1); 362 | printf("%ld: END\n", pthread_self()); 363 | } 364 | 365 | static void thread_shutdown(int fd) { 366 | printf("%ld: START\n", pthread_self()); 367 | sleep(4); 368 | _shutdown(fd, SHUT_RDWR); 369 | printf("%ld: END\n", pthread_self()); 370 | } 371 | 372 | static void thread_accept(struct thread_args *args) { 373 | printf("%ld: START\n", pthread_self()); 374 | sleep(args->delay); 375 | _accept(args->fd, args->type); 376 | printf("%ld: END\n", pthread_self()); 377 | } 378 | 379 | static void thread_connect(struct thread_args *args) { 380 | printf("%ld: START\n", pthread_self()); 381 | sleep(args->delay); 382 | _connect(args->fd, args->type); 383 | printf("%ld: END\n", pthread_self()); 384 | } 385 | 386 | static void thread_delay_close_write(struct thread_args *args) { 387 | printf("%ld: START\n", pthread_self()); 388 | sleep(args->delay); 389 | _close(args->fd, args->type); 390 | sleep(args->delay); 391 | _write(args->fd, args->type); 392 | printf("%ld: END\n", pthread_self()); 393 | } 394 | 395 | static void thread_accept_write(struct thread_args *args) { 396 | printf("%ld: START\n", pthread_self()); 397 | sleep(args->delay); 398 | _accept(args->fd, args->type); 399 | sleep(args->delay); 400 | _write(args->fd, args->type); 401 | printf("%ld: END\n", pthread_self()); 402 | } 403 | 404 | static void thread_delay_connect(struct thread_args *args) { 405 | printf("%ld: START\n", pthread_self()); 406 | sleep(args->delay); 407 | args->fd = _socket(args->type); 408 | _connect(args->fd, args->type); 409 | printf("%ld: END\n", pthread_self()); 410 | } 411 | 412 | static int do_accept_accept_accept(int type) { 413 | int fd; 414 | 415 | fd = _socket(type); 416 | if (fd < 0) goto error; 417 | 418 | if (_bind(fd, type) < 0) goto error; 419 | 420 | if (_listen(fd, type) < 0) goto error; 421 | 422 | while (1) { 423 | _accept(fd, type); 424 | } 425 | 426 | return 0; 427 | 428 | error: 429 | return -1; 430 | } 431 | 432 | static int do_accept_and_close(int type) { 433 | int fd; 434 | pthread_t thread; 435 | struct thread_args args = {-1, type, 1}; 436 | 437 | fd = _socket(type); 438 | if (fd < 0) goto error; 439 | 440 | if (_bind(fd, type) < 0) goto error; 441 | 442 | if (_listen(fd, type) < 0) goto error; 443 | 444 | args.fd = fd; 445 | pthread_create(&thread, NULL, (void *)thread_delay_close, (void *)&args); 446 | 447 | _accept(fd, type); 448 | 449 | pthread_join(thread, NULL); 450 | 451 | return 0; 452 | 453 | error: 454 | return -1; 455 | } 456 | 457 | static int do_accept_shutdown(int type) { 458 | int fd; 459 | pthread_t thread; 460 | struct thread_args args = {-1, type, 0}; 461 | 462 | fd = _socket(type); 463 | if (fd < 0) goto error; 464 | 465 | if (_bind(fd, type) < 0) goto error; 466 | 467 | if (_listen(fd, type) < 0) goto error; 468 | 469 | args.fd = fd; 470 | pthread_create(&thread, NULL, (void *)thread_accept, (void *)&args); 471 | 472 | sleep(4); 473 | _shutdown(fd, SHUT_RDWR); 474 | 475 | pthread_join(thread, NULL); 476 | 477 | _close(fd, type); 478 | 479 | return 0; 480 | 481 | error: 482 | return -1; 483 | } 484 | 485 | static int do_connect_shutdown(int type) { 486 | int fd; 487 | pthread_t thread; 488 | struct thread_args args = {-1, type, 0}; 489 | 490 | fd = _socket(type); 491 | if (fd < 0) goto error; 492 | 493 | args.fd = fd; 494 | pthread_create(&thread, NULL, (void *)thread_connect, (void *)&args); 495 | 496 | sleep(4); 497 | _shutdown(fd, SHUT_RDWR); 498 | 499 | pthread_join(thread, NULL); 500 | 501 | _close(fd, type); 502 | 503 | return 0; 504 | 505 | error: 506 | return -1; 507 | } 508 | 509 | static int do_connectnb_shutdown(int type) { 510 | int fd; 511 | int flags; 512 | pthread_t thread; 513 | struct thread_args args = {-1, type, 0}; 514 | 515 | 516 | fd = _socket(type); 517 | if (fd < 0) goto error; 518 | 519 | flags = fcntl(fd, F_GETFL); 520 | if (flags == -1) 521 | return -1; 522 | if (fcntl(fd, F_SETFL, flags | O_NONBLOCK)) 523 | return -1; 524 | 525 | _connect(fd, type); 526 | 527 | sleep(1); 528 | _shutdown(fd, SHUT_RDWR); 529 | 530 | sleep(2); 531 | 532 | _close(fd, type); 533 | 534 | return 0; 535 | 536 | error: 537 | return -1; 538 | } 539 | 540 | static int do_connectnb_close(int type) { 541 | int fd; 542 | pthread_t thread; 543 | struct thread_args args = {-1, type, 0}; 544 | int flags; 545 | 546 | fd = _socket(type); 547 | if (fd < 0) goto error; 548 | 549 | flags = fcntl(fd, F_GETFL); 550 | if (flags == -1) 551 | return -1; 552 | if (fcntl(fd, F_SETFL, flags | O_NONBLOCK)) 553 | return -1; 554 | 555 | _connect(fd, type); 556 | 557 | sleep(2); 558 | 559 | _close(fd, type); 560 | 561 | return 0; 562 | 563 | error: 564 | return -1; 565 | } 566 | 567 | // accept in one thread. close then write in another 568 | static int do_accept_close_write(int type) { 569 | int fd; 570 | pthread_t thread; 571 | struct thread_args args = {-1, type, 1}; 572 | 573 | fd = _socket(type); 574 | if (fd < 0) goto error; 575 | 576 | if (_bind(fd, type) < 0) goto error; 577 | 578 | if (_listen(fd, type) < 0) goto error; 579 | 580 | args.fd = fd; 581 | pthread_create(&thread, NULL, (void *)thread_delay_close_write, (void *)&args); 582 | 583 | _accept(fd, type); 584 | 585 | pthread_join(thread, NULL); 586 | 587 | return 0; 588 | 589 | error: 590 | return -1; 591 | } 592 | 593 | static int do_poll_poll_poll_shutdown(int type) { 594 | const int MAX_T = 32; 595 | int fd; 596 | pthread_t t[MAX_T]; 597 | int i; 598 | 599 | fd = _socket(type); 600 | 601 | for (i=0; i to print a debug log 29 | ** <--patchram patchram_file> 30 | ** <--baudrate baud_rate> 31 | ** <--bd_addr bd_address> 32 | ** <--enable_lpm> 33 | ** <--enable_hci> 34 | ** <--use_baudrate_for_download> 35 | ** <--scopcm=sco_routing,pcm_interface_rate,frame_type, 36 | ** sync_mode,clock_mode,lsb_first,fill_bits, 37 | ** fill_method,fill_num,right_justify> 38 | ** 39 | ** Where 40 | ** 41 | ** sco_routing is 0 for PCM, 1 for Transport, 42 | ** 2 for Codec and 3 for I2S, 43 | ** 44 | ** pcm_interface_rate is 0 for 128KBps, 1 for 45 | ** 256 KBps, 2 for 512KBps, 3 for 1024KBps, 46 | ** and 4 for 2048Kbps, 47 | ** 48 | ** frame_type is 0 for short and 1 for long, 49 | ** 50 | ** sync_mode is 0 for slave and 1 for master, 51 | ** 52 | ** clock_mode is 0 for slabe and 1 for master, 53 | ** 54 | ** lsb_first is 0 for false aand 1 for true, 55 | ** 56 | ** fill_bits is the value in decimal for unused bits, 57 | ** 58 | ** fill_method is 0 for 0's and 1 for 1's, 2 for 59 | ** signed and 3 for programmable, 60 | ** 61 | ** fill_num is the number or bits to fill, 62 | ** 63 | ** right_justify is 0 for false and 1 for true 64 | ** 65 | ** <--i2s=i2s_enable,is_master,sample_rate,clock_rate> 66 | ** 67 | ** Where 68 | ** 69 | ** i2s_enable is 0 for disable and 1 for enable, 70 | ** 71 | ** is_master is 0 for slave and 1 for master, 72 | ** 73 | ** sample_rate is 0 for 8KHz, 1 for 16Khz and 74 | ** 2 for 4 KHz, 75 | ** 76 | ** clock_rate is 0 for 128KHz, 1 for 256KHz, 3 for 77 | ** 1024 KHz and 4 for 2048 KHz. 78 | ** 79 | ** <--no2bytes skips waiting for two byte confirmation 80 | ** before starting patchram download. Newer chips 81 | ** do not generate these two bytes.> 82 | ** <--tosleep=number of microsseconds to sleep before 83 | ** patchram download begins.> 84 | ** uart_device_name 85 | ** 86 | ** For example: 87 | ** 88 | ** brcm_patchram_plus -d --patchram \ 89 | ** BCM2045B2_002.002.011.0348.0349.hcd /dev/ttyHS0 90 | ** 91 | ** It will return 0 for success and a number greater than 0 92 | ** for any errors. 93 | ** 94 | ** For Android, this program invoked using a 95 | ** "system(2)" call from the beginning of the bt_enable 96 | ** function inside the file 97 | ** system/bluetooth/bluedroid/bluetooth.c. 98 | ** 99 | ** If the Android system property "ro.bt.bcm_bdaddr_path" is 100 | ** set, then the bd_addr will be read from this path. 101 | ** This is overridden by --bd_addr on the command line. 102 | ** 103 | ******************************************************************************/ 104 | 105 | // TODO: Integrate BCM support into Bluez hciattach 106 | 107 | #include 108 | #include 109 | #include 110 | 111 | #include 112 | #include 113 | #include 114 | 115 | #include 116 | 117 | #ifdef ANDROID 118 | #include 119 | #else 120 | #include 121 | #include 122 | #include 123 | #endif 124 | 125 | #include 126 | #include 127 | 128 | #ifdef ANDROID 129 | #include 130 | #define LOG_TAG "brcm_patchram_plus" 131 | #include 132 | #undef printf 133 | #define printf ALOGD 134 | #undef fprintf 135 | #define fprintf(x, ...) \ 136 | { if(x==stderr) ALOGE(__VA_ARGS__); else fprintf(x, __VA_ARGS__); } 137 | 138 | #endif //ANDROID 139 | 140 | #ifndef N_HCI 141 | #define N_HCI 15 142 | #endif 143 | 144 | #define HCIUARTSETPROTO _IOW('U', 200, int) 145 | #define HCIUARTGETPROTO _IOR('U', 201, int) 146 | #define HCIUARTGETDEVICE _IOR('U', 202, int) 147 | 148 | #define HCI_UART_H4 0 149 | #define HCI_UART_BCSP 1 150 | #define HCI_UART_3WIRE 2 151 | #define HCI_UART_H4DS 3 152 | #define HCI_UART_LL 4 153 | 154 | typedef unsigned char uchar; 155 | 156 | int uart_fd = -1; 157 | int hcdfile_fd = -1; 158 | int termios_baudrate = 0; 159 | int bdaddr_flag = 0; 160 | int enable_lpm = 0; 161 | int enable_hci = 0; 162 | int use_baudrate_for_download = 0; 163 | int debug = 0; 164 | int scopcm = 0; 165 | int i2s = 0; 166 | int no2bytes = 0; 167 | int tosleep = 0; 168 | 169 | struct termios termios; 170 | uchar buffer[1024]; 171 | 172 | uchar hci_reset[] = { 0x01, 0x03, 0x0c, 0x00 }; 173 | 174 | uchar hci_download_minidriver[] = { 0x01, 0x2e, 0xfc, 0x00 }; 175 | 176 | uchar hci_update_baud_rate[] = { 0x01, 0x18, 0xfc, 0x06, 0x00, 0x00, 177 | 0x00, 0x00, 0x00, 0x00 }; 178 | 179 | uchar hci_write_bd_addr[] = { 0x01, 0x01, 0xfc, 0x06, 180 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; 181 | 182 | uchar hci_write_sleep_mode[] = { 0x01, 0x27, 0xfc, 0x0c, 183 | 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 184 | 0x00, 0x00 }; 185 | 186 | uchar hci_write_sco_pcm_int[] = 187 | { 0x01, 0x1C, 0xFC, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00 }; 188 | 189 | uchar hci_write_pcm_data_format[] = 190 | { 0x01, 0x1e, 0xFC, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00 }; 191 | 192 | uchar hci_write_i2spcm_interface_param[] = 193 | { 0x01, 0x6d, 0xFC, 0x04, 0x00, 0x00, 0x00, 0x00 }; 194 | 195 | #ifdef SAMSUNG_BLUETOOTH 196 | char* get_samsung_bluetooth_type() 197 | { 198 | char buf[10]; 199 | int fd = open("/data/.cid.info", O_RDONLY); 200 | if (fd < 0) { 201 | fprintf(stderr, "couldn't open file /data/.cid.info for reading\n"); 202 | return NULL; 203 | } 204 | 205 | if (read(fd, buf, sizeof(buf)) < 0) { 206 | close(fd); 207 | return NULL; 208 | } 209 | 210 | close(fd); 211 | 212 | if (strncmp(buf, "murata", 6) == 0) 213 | return "_murata"; 214 | 215 | if (strncmp(buf, "semcove", 7) == 0) 216 | return "_semcove"; 217 | 218 | if (strncmp(buf, "semcosh", 7) == 0) 219 | return "_semcosh"; 220 | 221 | return NULL; 222 | } 223 | #endif 224 | 225 | int 226 | parse_patchram(char *optarg) 227 | { 228 | char *p; 229 | 230 | if (!(p = strrchr(optarg, '.'))) { 231 | fprintf(stderr, "file %s not an HCD file\n", optarg); 232 | exit(3); 233 | } 234 | 235 | p++; 236 | 237 | if (strcasecmp("hcd", p) != 0) { 238 | fprintf(stderr, "file %s not an HCD file\n", optarg); 239 | exit(4); 240 | } 241 | 242 | #ifdef SAMSUNG_BLUETOOTH 243 | char optarg2[256]; 244 | char* type = get_samsung_bluetooth_type(); 245 | char* fext = ".hcd"; 246 | 247 | if (type != NULL) { 248 | memset(optarg2, 0, 256); 249 | strncpy(optarg2, optarg, strlen(optarg) - 4); 250 | strcpy(optarg2 + strlen(optarg2), type); 251 | strcpy(optarg2 + strlen(optarg2), fext); 252 | optarg = optarg2; 253 | fprintf(stderr, "using %s as hcdfile\n", optarg); 254 | } 255 | #endif 256 | 257 | if ((hcdfile_fd = open(optarg, O_RDONLY)) == -1) { 258 | fprintf(stderr, "file %s could not be opened, error %d\n", optarg, errno); 259 | exit(5); 260 | } 261 | 262 | return(0); 263 | } 264 | 265 | void 266 | BRCM_encode_baud_rate(uint baud_rate, uchar *encoded_baud) 267 | { 268 | if(baud_rate == 0 || encoded_baud == NULL) { 269 | fprintf(stderr, "Baudrate not supported!"); 270 | return; 271 | } 272 | 273 | encoded_baud[3] = (uchar)(baud_rate >> 24); 274 | encoded_baud[2] = (uchar)(baud_rate >> 16); 275 | encoded_baud[1] = (uchar)(baud_rate >> 8); 276 | encoded_baud[0] = (uchar)(baud_rate & 0xFF); 277 | } 278 | 279 | typedef struct { 280 | int baud_rate; 281 | int termios_value; 282 | } tBaudRates; 283 | 284 | tBaudRates baud_rates[] = { 285 | { 115200, B115200 }, 286 | { 230400, B230400 }, 287 | { 460800, B460800 }, 288 | { 500000, B500000 }, 289 | { 576000, B576000 }, 290 | { 921600, B921600 }, 291 | { 1000000, B1000000 }, 292 | { 1152000, B1152000 }, 293 | { 1500000, B1500000 }, 294 | { 2000000, B2000000 }, 295 | { 2500000, B2500000 }, 296 | { 3000000, B3000000 }, 297 | #ifndef __CYGWIN__ 298 | { 3500000, B3500000 }, 299 | { 4000000, B4000000 } 300 | #endif 301 | }; 302 | 303 | int 304 | validate_baudrate(int baud_rate, int *value) 305 | { 306 | unsigned int i; 307 | 308 | for (i = 0; i < (sizeof(baud_rates) / sizeof(tBaudRates)); i++) { 309 | if (baud_rates[i].baud_rate == baud_rate) { 310 | *value = baud_rates[i].termios_value; 311 | return(1); 312 | } 313 | } 314 | 315 | return(0); 316 | } 317 | 318 | int 319 | parse_baudrate(char *optarg) 320 | { 321 | int baudrate = atoi(optarg); 322 | 323 | if (validate_baudrate(baudrate, &termios_baudrate)) { 324 | BRCM_encode_baud_rate(baudrate, &hci_update_baud_rate[6]); 325 | } 326 | 327 | return(0); 328 | } 329 | 330 | int 331 | parse_bdaddr(char *optarg) 332 | { 333 | int bd_addr[6]; 334 | int i; 335 | 336 | sscanf(optarg, "%02X:%02X:%02X:%02X:%02X:%02X", 337 | &bd_addr[5], &bd_addr[4], &bd_addr[3], 338 | &bd_addr[2], &bd_addr[1], &bd_addr[0]); 339 | 340 | for (i = 0; i < 6; i++) { 341 | hci_write_bd_addr[4 + i] = bd_addr[i]; 342 | } 343 | 344 | bdaddr_flag = 1; 345 | 346 | return(0); 347 | } 348 | 349 | int 350 | parse_enable_lpm(char *optarg) 351 | { 352 | enable_lpm = 1; 353 | return(0); 354 | } 355 | 356 | int 357 | parse_use_baudrate_for_download(char *optarg) 358 | { 359 | use_baudrate_for_download = 1; 360 | return(0); 361 | } 362 | 363 | int 364 | parse_enable_hci(char *optarg) 365 | { 366 | enable_hci = 1; 367 | return(0); 368 | } 369 | 370 | int 371 | parse_scopcm(char *optarg) 372 | { 373 | int param[10]; 374 | int ret; 375 | int i; 376 | 377 | ret = sscanf(optarg, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", 378 | ¶m[0], ¶m[1], ¶m[2], ¶m[3], ¶m[4], 379 | ¶m[5], ¶m[6], ¶m[7], ¶m[8], ¶m[9]); 380 | 381 | if (ret != 10) { 382 | return(1); 383 | } 384 | 385 | scopcm = 1; 386 | 387 | for (i = 0; i < 5; i++) { 388 | hci_write_sco_pcm_int[4 + i] = param[i]; 389 | } 390 | 391 | for (i = 0; i < 5; i++) { 392 | hci_write_pcm_data_format[4 + i] = param[5 + i]; 393 | } 394 | 395 | return(0); 396 | } 397 | 398 | int 399 | parse_i2s(char *optarg) 400 | { 401 | int param[4]; 402 | int ret; 403 | int i; 404 | 405 | ret = sscanf(optarg, "%d,%d,%d,%d", ¶m[0], ¶m[1], ¶m[2], 406 | ¶m[3]); 407 | 408 | if (ret != 4) { 409 | return(1); 410 | } 411 | 412 | i2s = 1; 413 | 414 | for (i = 0; i < 4; i++) { 415 | hci_write_i2spcm_interface_param[4 + i] = param[i]; 416 | } 417 | 418 | return(0); 419 | } 420 | 421 | int 422 | parse_no2bytes(char *optarg) 423 | { 424 | no2bytes = 1; 425 | return(0); 426 | } 427 | 428 | int 429 | parse_tosleep(char *optarg) 430 | { 431 | tosleep = atoi(optarg); 432 | 433 | if (tosleep <= 0) { 434 | return(1); 435 | } 436 | 437 | return(0); 438 | } 439 | 440 | void 441 | usage(char *argv0) 442 | { 443 | printf("Usage %s:\n", argv0); 444 | printf("\t<-d> to print a debug log\n"); 445 | printf("\t<--patchram patchram_file>\n"); 446 | printf("\t<--baudrate baud_rate>\n"); 447 | printf("\t<--bd_addr bd_address>\n"); 448 | printf("\t<--enable_lpm>\n"); 449 | printf("\t<--enable_hci>\n"); 450 | printf("\t<--use_baudrate_for_download> - Uses the\n"); 451 | printf("\t\tbaudrate for downloading the firmware\n"); 452 | printf("\t<--scopcm=sco_routing,pcm_interface_rate,frame_type,\n"); 453 | printf("\t\tsync_mode,clock_mode,lsb_first,fill_bits,\n"); 454 | printf("\t\tfill_method,fill_num,right_justify>\n"); 455 | printf("\n\t\tWhere\n"); 456 | printf("\n\t\tsco_routing is 0 for PCM, 1 for Transport,\n"); 457 | printf("\t\t2 for Codec and 3 for I2S,\n"); 458 | printf("\n\t\tpcm_interface_rate is 0 for 128KBps, 1 for\n"); 459 | printf("\t\t256 KBps, 2 for 512KBps, 3 for 1024KBps,\n"); 460 | printf("\t\tand 4 for 2048Kbps,\n"); 461 | printf("\n\t\tframe_type is 0 for short and 1 for long,\n"); 462 | printf("\t\tsync_mode is 0 for slave and 1 for master,\n"); 463 | printf("\n\t\tclock_mode is 0 for slabe and 1 for master,\n"); 464 | printf("\n\t\tlsb_first is 0 for false aand 1 for true,\n"); 465 | printf("\n\t\tfill_bits is the value in decimal for unused bits,\n"); 466 | printf("\n\t\tfill_method is 0 for 0's and 1 for 1's, 2 for\n"); 467 | printf("\t\tsigned and 3 for programmable,\n"); 468 | printf("\n\t\tfill_num is the number or bits to fill,\n"); 469 | printf("\n\t\tright_justify is 0 for false and 1 for true\n"); 470 | printf("\n\t<--i2s=i2s_enable,is_master,sample_rate,clock_rate>\n"); 471 | printf("\n\t\tWhere\n"); 472 | printf("\n\t\ti2s_enable is 0 for disable and 1 for enable,\n"); 473 | printf("\n\t\tis_master is 0 for slave and 1 for master,\n"); 474 | printf("\n\t\tsample_rate is 0 for 8KHz, 1 for 16Khz and\n"); 475 | printf("\t\t2 for 4 KHz,\n"); 476 | printf("\n\t\tclock_rate is 0 for 128KHz, 1 for 256KHz, 3 for\n"); 477 | printf("\t\t1024 KHz and 4 for 2048 KHz.\n\n"); 478 | printf("\t<--no2bytes skips waiting for two byte confirmation\n"); 479 | printf("\t\tbefore starting patchram download. Newer chips\n"); 480 | printf("\t\tdo not generate these two bytes.>\n"); 481 | printf("\t<--tosleep=microseconds>\n"); 482 | printf("\tuart_device_name\n"); 483 | } 484 | 485 | int 486 | parse_cmd_line(int argc, char **argv) 487 | { 488 | int c; 489 | int ret = 0; 490 | 491 | typedef int (*PFI)(); 492 | 493 | PFI parse[] = { parse_patchram, parse_baudrate, 494 | parse_bdaddr, parse_enable_lpm, parse_enable_hci, 495 | parse_use_baudrate_for_download, 496 | parse_scopcm, parse_i2s, parse_no2bytes, parse_tosleep}; 497 | 498 | while (1) { 499 | int this_option_optind = optind ? optind : 1; 500 | int option_index = 0; 501 | 502 | static struct option long_options[] = { 503 | {"patchram", 1, 0, 0}, 504 | {"baudrate", 1, 0, 0}, 505 | {"bd_addr", 1, 0, 0}, 506 | {"enable_lpm", 0, 0, 0}, 507 | {"enable_hci", 0, 0, 0}, 508 | {"use_baudrate_for_download", 0, 0, 0}, 509 | {"scopcm", 1, 0, 0}, 510 | {"i2s", 1, 0, 0}, 511 | {"no2bytes", 0, 0, 0}, 512 | {"tosleep", 1, 0, 0}, 513 | {0, 0, 0, 0} 514 | }; 515 | 516 | c = getopt_long_only (argc, argv, "d", long_options, 517 | &option_index); 518 | 519 | if (c == -1) { 520 | break; 521 | } 522 | 523 | switch (c) { 524 | case 0: 525 | if (debug) { 526 | printf ("option %s", 527 | long_options[option_index].name); 528 | if (optarg) 529 | printf (" with arg %s", optarg); 530 | printf ("\n"); 531 | } 532 | 533 | ret = (*parse[option_index])(optarg); 534 | 535 | break; 536 | case 'd': 537 | debug = 1; 538 | break; 539 | 540 | case '?': 541 | //nobreak 542 | default: 543 | usage(argv[0]); 544 | break; 545 | } 546 | 547 | if (ret) { 548 | usage(argv[0]); 549 | break; 550 | } 551 | } 552 | 553 | if (ret) { 554 | return(1); 555 | } 556 | 557 | if (optind < argc) { 558 | if (debug) 559 | printf ("%s \n", argv[optind]); 560 | if ((uart_fd = open(argv[optind], O_RDWR | O_NOCTTY)) == -1) { 561 | fprintf(stderr, "port %s could not be opened, error %d\n", 562 | argv[optind], errno); 563 | } 564 | } 565 | 566 | return(0); 567 | } 568 | 569 | void 570 | init_uart() 571 | { 572 | #ifdef BCM_INIT_DELAY 573 | usleep(150*1000); 574 | #endif 575 | tcflush(uart_fd, TCIOFLUSH); 576 | tcgetattr(uart_fd, &termios); 577 | 578 | #ifndef __CYGWIN__ 579 | cfmakeraw(&termios); 580 | #else 581 | termios.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP 582 | | INLCR | IGNCR | ICRNL | IXON); 583 | termios.c_oflag &= ~OPOST; 584 | termios.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN); 585 | termios.c_cflag &= ~(CSIZE | PARENB); 586 | termios.c_cflag |= CS8; 587 | #endif 588 | 589 | termios.c_cflag |= CRTSCTS; 590 | tcsetattr(uart_fd, TCSANOW, &termios); 591 | tcflush(uart_fd, TCIOFLUSH); 592 | tcsetattr(uart_fd, TCSANOW, &termios); 593 | tcflush(uart_fd, TCIOFLUSH); 594 | tcflush(uart_fd, TCIOFLUSH); 595 | cfsetospeed(&termios, B115200); 596 | cfsetispeed(&termios, B115200); 597 | tcsetattr(uart_fd, TCSANOW, &termios); 598 | } 599 | 600 | void 601 | dump(uchar *out, int len) 602 | { 603 | int i; 604 | 605 | for (i = 0; i < len; i++) { 606 | if (i && !(i % 16)) { 607 | fprintf(stderr, "\n"); 608 | } 609 | 610 | fprintf(stderr, "%02x ", out[i]); 611 | } 612 | 613 | fprintf(stderr, "\n"); 614 | } 615 | 616 | void 617 | read_event(int fd, uchar *buffer) 618 | { 619 | int i = 0; 620 | int len = 3; 621 | int count; 622 | 623 | while ((count = read(fd, &buffer[i], len)) < len) { 624 | i += count; 625 | len -= count; 626 | } 627 | 628 | i += count; 629 | len = buffer[2]; 630 | 631 | while ((count = read(fd, &buffer[i], len)) < len) { 632 | i += count; 633 | len -= count; 634 | } 635 | 636 | if (debug) { 637 | count += i; 638 | 639 | fprintf(stderr, "received %d\n", count); 640 | dump(buffer, count); 641 | } 642 | } 643 | 644 | void 645 | hci_send_cmd(uchar *buf, int len) 646 | { 647 | if (debug) { 648 | fprintf(stderr, "writing\n"); 649 | dump(buf, len); 650 | } 651 | 652 | write(uart_fd, buf, len); 653 | } 654 | 655 | void 656 | expired(int sig) 657 | { 658 | hci_send_cmd(hci_reset, sizeof(hci_reset)); 659 | alarm(4); 660 | } 661 | 662 | void 663 | proc_reset() 664 | { 665 | signal(SIGALRM, expired); 666 | 667 | 668 | hci_send_cmd(hci_reset, sizeof(hci_reset)); 669 | 670 | alarm(4); 671 | 672 | read_event(uart_fd, buffer); 673 | 674 | alarm(0); 675 | } 676 | 677 | void 678 | proc_patchram() 679 | { 680 | int len; 681 | 682 | hci_send_cmd(hci_download_minidriver, sizeof(hci_download_minidriver)); 683 | 684 | read_event(uart_fd, buffer); 685 | 686 | if (!no2bytes) { 687 | read(uart_fd, &buffer[0], 2); 688 | } 689 | 690 | if (tosleep) { 691 | usleep(tosleep); 692 | } 693 | 694 | while (read(hcdfile_fd, &buffer[1], 3)) { 695 | buffer[0] = 0x01; 696 | 697 | len = buffer[3]; 698 | 699 | read(hcdfile_fd, &buffer[4], len); 700 | 701 | hci_send_cmd(buffer, len + 4); 702 | 703 | read_event(uart_fd, buffer); 704 | } 705 | 706 | if (use_baudrate_for_download) { 707 | cfsetospeed(&termios, B115200); 708 | cfsetispeed(&termios, B115200); 709 | tcsetattr(uart_fd, TCSANOW, &termios); 710 | } 711 | proc_reset(); 712 | } 713 | 714 | void 715 | proc_baudrate() 716 | { 717 | hci_send_cmd(hci_update_baud_rate, sizeof(hci_update_baud_rate)); 718 | 719 | read_event(uart_fd, buffer); 720 | 721 | cfsetospeed(&termios, termios_baudrate); 722 | cfsetispeed(&termios, termios_baudrate); 723 | tcsetattr(uart_fd, TCSANOW, &termios); 724 | 725 | if (debug) { 726 | fprintf(stderr, "Done setting baudrate\n"); 727 | } 728 | } 729 | 730 | void 731 | proc_bdaddr() 732 | { 733 | hci_send_cmd(hci_write_bd_addr, sizeof(hci_write_bd_addr)); 734 | 735 | read_event(uart_fd, buffer); 736 | } 737 | 738 | void 739 | proc_enable_lpm() 740 | { 741 | hci_send_cmd(hci_write_sleep_mode, sizeof(hci_write_sleep_mode)); 742 | 743 | read_event(uart_fd, buffer); 744 | } 745 | 746 | void 747 | proc_scopcm() 748 | { 749 | hci_send_cmd(hci_write_sco_pcm_int, 750 | sizeof(hci_write_sco_pcm_int)); 751 | 752 | read_event(uart_fd, buffer); 753 | 754 | hci_send_cmd(hci_write_pcm_data_format, 755 | sizeof(hci_write_pcm_data_format)); 756 | 757 | read_event(uart_fd, buffer); 758 | } 759 | 760 | void 761 | proc_i2s() 762 | { 763 | hci_send_cmd(hci_write_i2spcm_interface_param, 764 | sizeof(hci_write_i2spcm_interface_param)); 765 | 766 | read_event(uart_fd, buffer); 767 | } 768 | 769 | void 770 | proc_enable_hci() 771 | { 772 | int i = N_HCI; 773 | int proto = HCI_UART_H4; 774 | if (ioctl(uart_fd, TIOCSETD, &i) < 0) { 775 | fprintf(stderr, "Can't set line discipline\n"); 776 | return; 777 | } 778 | 779 | if (ioctl(uart_fd, HCIUARTSETPROTO, proto) < 0) { 780 | fprintf(stderr, "Can't set hci protocol\n"); 781 | return; 782 | } 783 | fprintf(stderr, "Done setting line discpline\n"); 784 | return; 785 | } 786 | 787 | #ifdef ANDROID 788 | void 789 | read_default_bdaddr() 790 | { 791 | int sz; 792 | int fd; 793 | 794 | char path[PROPERTY_VALUE_MAX]; 795 | 796 | char bdaddr[18]; 797 | int len = 17; 798 | memset(bdaddr, 0, (len + 1) * sizeof(char)); 799 | 800 | property_get("ro.bt.bdaddr_path", path, ""); 801 | if (path[0] == 0) 802 | return; 803 | 804 | fd = open(path, O_RDONLY); 805 | if (fd < 0) { 806 | fprintf(stderr, "open(%s) failed: %s (%d)", path, strerror(errno), 807 | errno); 808 | return; 809 | } 810 | 811 | sz = read(fd, bdaddr, len); 812 | if (sz < 0) { 813 | fprintf(stderr, "read(%s) failed: %s (%d)", path, strerror(errno), 814 | errno); 815 | close(fd); 816 | return; 817 | } else if (sz != len) { 818 | fprintf(stderr, "read(%s) unexpected size %d", path, sz); 819 | close(fd); 820 | return; 821 | } 822 | 823 | if (debug) { 824 | printf("Read default bdaddr of %s\n", bdaddr); 825 | } 826 | 827 | parse_bdaddr(bdaddr); 828 | } 829 | #endif 830 | 831 | 832 | int 833 | main (int argc, char **argv) 834 | { 835 | #ifdef ANDROID 836 | read_default_bdaddr(); 837 | #endif 838 | 839 | if (parse_cmd_line(argc, argv)) { 840 | exit(1); 841 | } 842 | 843 | if (uart_fd < 0) { 844 | exit(2); 845 | } 846 | 847 | init_uart(); 848 | 849 | proc_reset(); 850 | 851 | if (use_baudrate_for_download) { 852 | if (termios_baudrate) { 853 | proc_baudrate(); 854 | } 855 | } 856 | 857 | if (hcdfile_fd > 0) { 858 | proc_patchram(); 859 | } 860 | 861 | if (termios_baudrate) { 862 | proc_baudrate(); 863 | } 864 | 865 | if (bdaddr_flag) { 866 | proc_bdaddr(); 867 | } 868 | 869 | if (enable_lpm) { 870 | proc_enable_lpm(); 871 | } 872 | 873 | if (scopcm) { 874 | proc_scopcm(); 875 | } 876 | 877 | if (i2s) { 878 | proc_i2s(); 879 | } 880 | 881 | if (enable_hci) { 882 | proc_enable_hci(); 883 | 884 | while (1) { 885 | sleep(UINT_MAX); 886 | } 887 | } 888 | 889 | exit(0); 890 | } 891 | --------------------------------------------------------------------------------