From dafe9d89fb8c48f8407c341ae05c8196fdfb34c0 Mon Sep 17 00:00:00 2001 From: Ricardo Cerqueira Date: Wed, 25 May 2016 22:55:41 -0400 Subject: [PATCH] g5: Add hwaddrs to set WiFi and BT addresses --- g5.mk | 4 ++++ hwaddrs/Android.mk | 27 +++++++++++++++++++++ hwaddrs/getmac.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++ system_prop.mk | 4 ++++ 4 files changed, 95 insertions(+) create mode 100644 hwaddrs/Android.mk create mode 100644 hwaddrs/getmac.c diff --git a/g5.mk b/g5.mk index e53ae08..10fec74 100644 --- a/g5.mk +++ b/g5.mk @@ -96,6 +96,10 @@ PRODUCT_COPY_FILES += \ $(LOCAL_PATH)/configs/audio_policy.conf:system/etc/audio_policy.conf \ $(LOCAL_PATH)/configs/mixer_paths.xml:system/etc/mixer_paths.xml +# Bluetooth +PRODUCT_PACKAGES += \ + hwaddrs + # Display PRODUCT_PACKAGES += \ copybit.msm8996 \ diff --git a/hwaddrs/Android.mk b/hwaddrs/Android.mk new file mode 100644 index 0000000..649d6ce --- /dev/null +++ b/hwaddrs/Android.mk @@ -0,0 +1,27 @@ +# Copyright (C) 2011-2015 The CyanogenMod project +# +# 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 := getmac.c + +LOCAL_PRELINK_MODULE := false + +LOCAL_MODULE := hwaddrs + +include $(BUILD_EXECUTABLE) diff --git a/hwaddrs/getmac.c b/hwaddrs/getmac.c new file mode 100644 index 0000000..3ebc0e3 --- /dev/null +++ b/hwaddrs/getmac.c @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2011-2015 The CyanogenMod Project + * + * 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. + */ + +#include +#include +#include +#include + +/* Read plain address from misc partiton and set the Wifi and BT mac addresses accordingly */ + +int main() { + int fd1, fd2; + char macbyte; + char macbuf[3]; + int i; + + fd1 = open("/dev/block/bootdevice/by-name/misc",O_RDONLY); + fd2 = open("/data/misc/wifi/config",O_WRONLY|O_CREAT|O_TRUNC,S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH); + + write(fd2,"cur_etheraddr=",14); + + for (i = 0; i<6; i++) { + lseek(fd1,0x3000+i,SEEK_SET); + lseek(fd2,0,SEEK_END); + read(fd1,&macbyte,1); + sprintf(macbuf,"%02x",macbyte); + write(fd2,&macbuf,2); + if (i!=5) write(fd2,":",1); + } + + write(fd2,"\n",1); + close(fd2); + + fd2 = open("/data/misc/bdaddr",O_WRONLY|O_CREAT|O_TRUNC,S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH); + for (i = 0; i<6; i++) { + lseek(fd1,0x4000+i,SEEK_SET); + lseek(fd2,0,SEEK_END); + read(fd1,&macbyte,1); + sprintf(macbuf,"%02x",macbyte); + write(fd2,&macbuf,2); + if (i!=5) write(fd2,":",1); + } + close(fd2); + + close(fd1); + return 0; +} diff --git a/system_prop.mk b/system_prop.mk index df3a2ca..4d74c7b 100644 --- a/system_prop.mk +++ b/system_prop.mk @@ -16,6 +16,10 @@ PRODUCT_PROPERTY_OVERRIDES += \ audio.offload.multiple.enabled=true \ audio.offload.video=false +# Bluetooth +PRODUCT_PROPERTY_OVERRIDES += \ + ro.bt.bdaddr_path="/data/misc/bdaddr" + # Camera PRODUCT_PROPERTY_OVERRIDES += \ camera2.portability.force_api=2