diff options
author | Pawit Pornkitprasan <p.pawit@gmail.com> | 2011-07-24 16:42:11 +0700 |
---|---|---|
committer | Pawit Pornkitprasan <p.pawit@gmail.com> | 2011-07-24 17:24:34 +0700 |
commit | a8fb4a0032db58633914c3c2e3150aef28146a0b (patch) | |
tree | c9ddd5790ec024d0cf744acb82fc7fb1b0292524 | |
parent | b1d56f678126fc1b6c8c4d768c2d0c0507a1ee02 (diff) | |
download | device_samsung_aries-common-a8fb4a0032db58633914c3c2e3150aef28146a0b.zip device_samsung_aries-common-a8fb4a0032db58633914c3c2e3150aef28146a0b.tar.gz device_samsung_aries-common-a8fb4a0032db58633914c3c2e3150aef28146a0b.tar.bz2 |
Enable proper bluetooth MAC address on aries devices (1/5)
The approach here is to used bdaddr_read.c to read the
MAC address (it's in a different format than ro.bt.bdaddr_path
accepts) at /efs/imei/bt.txt and write it to /data/bdaddr and
set ro.bt.bdaddr_path there. This approach was used with
device/lge/thunderg and bdaddr_read.c was adapted from there.
Change-Id: Ide75a0d6074506cc93b9c11af667f62e7460faa2
-rw-r--r-- | bdaddr_read/Android.mk | 28 | ||||
-rw-r--r-- | bdaddr_read/bdaddr_read.c | 54 | ||||
-rw-r--r-- | init.aries.rc | 11 |
3 files changed, 90 insertions, 3 deletions
diff --git a/bdaddr_read/Android.mk b/bdaddr_read/Android.mk new file mode 100644 index 0000000..46f95cd --- /dev/null +++ b/bdaddr_read/Android.mk @@ -0,0 +1,28 @@ +# Copyright (C) 2010 Ricardo Cerqueira +# Copyright (C) 2011 Pawit Pornkitprasan +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +LOCAL_PATH:= $(call my-dir) +include $(CLEAR_VARS) + +LOCAL_MODULE_TAGS := optional + +LOCAL_SRC_FILES := bdaddr_read.c + +LOCAL_SHARED_LIBRARIES := libcutils + +LOCAL_MODULE := bdaddr_read + +include $(BUILD_EXECUTABLE) + diff --git a/bdaddr_read/bdaddr_read.c b/bdaddr_read/bdaddr_read.c new file mode 100644 index 0000000..c6e08c9 --- /dev/null +++ b/bdaddr_read/bdaddr_read.c @@ -0,0 +1,54 @@ +#include <fcntl.h> +#include <string.h> +#include <cutils/properties.h> +#include <cutils/log.h> + +#define LOG_TAG "bdaddr" +#define SAMSUNG_BDADDR_PATH "/efs/imei/bt.txt" +#define BDADDR_PATH "/data/bdaddr" + +/* Read bluetooth MAC from SAMSUNG_BDADDR_PATH (different format), + * write it to BDADDR_PATH, and set ro.bt.bdaddr_path to BDADDR_PATH + * + * Adapted from bdaddr_read.c of thunderg + */ + +int main() { + char tmpbdaddr[23]; // bt_macaddr:xxxxxxxxxxxx + char bdaddr[18]; + int count; + int fd; + + fd = open(SAMSUNG_BDADDR_PATH, O_RDONLY); + if(fd < 0) { + fprintf(stderr, "open(%s) failed\n", SAMSUNG_BDADDR_PATH); + LOGE("Can't open %s\n", SAMSUNG_BDADDR_PATH); + return -1; + } + + count = read(fd, tmpbdaddr, sizeof(tmpbdaddr)); + if (count < 0) { + fprintf(stderr, "read(%s) failed\n", SAMSUNG_BDADDR_PATH); + LOGE("Can't read %s\n", SAMSUNG_BDADDR_PATH); + return -1; + } + else if (count != sizeof(tmpbdaddr)) { + fprintf(stderr, "read(%s) unexpected size %d\n", SAMSUNG_BDADDR_PATH, count); + LOGE("Error reading %s (unexpected size %d)\n", SAMSUNG_BDADDR_PATH, count); + return -1; + } + + count = sprintf(bdaddr, "%2.2s:%2.2s:%2.2s:%2.2s:%2.2s:%2.2s\0", + tmpbdaddr+11,tmpbdaddr+13,tmpbdaddr+15,tmpbdaddr+17,tmpbdaddr+19,tmpbdaddr+21); + + fd = open(BDADDR_PATH, O_WRONLY|O_CREAT|O_TRUNC, 00600|00060|00006); + if (fd < 0) { + fprintf(stderr, "open(%s) failed\n", BDADDR_PATH); + LOGE("Can't open %s\n", BDADDR_PATH); + return -2; + } + write(fd, bdaddr, 18); + close(fd); + property_set("ro.bt.bdaddr_path", BDADDR_PATH); + return 0; +} diff --git a/init.aries.rc b/init.aries.rc index c43bcd7..fabe861 100644 --- a/init.aries.rc +++ b/init.aries.rc @@ -16,7 +16,6 @@ on boot setprop ro.build.product aries setprop ro.product.device aries setprop ro.radio.noril yes - setprop ro.bt.bdaddr_path "/efs/bluetooth/bt_addr" # fake some battery state setprop status.battery.state Slow @@ -69,8 +68,6 @@ on fs chmod 770 /efs/imei # permissions for bluetooth. - chown bluetooth bluetooth /efs/bluetooth - chown bluetooth bluetooth ro.bt.bdaddr_path chown bluetooth bluetooth /dev/s3c2410_serial0 chmod 0600 /dev/s3c2410_serial0 chmod 0660 /sys/class/rfkill/rfkill0/state @@ -209,6 +206,14 @@ service iprenew_eth0 /system/bin/dhcpcd -n disabled oneshot +service bdaddr /system/bin/bdaddr_read + user root + disabled + oneshot + +on property:init.svc.bootanim=running + start bdaddr + service hciattach /system/bin/brcm_patchram_plus --enable_hci --enable_lpm \ --baudrate 3000000 --patchram /vendor/firmware/bcm4329.hcd /dev/s3c2410_serial0 user bluetooth |