Skip to content

Commit

Permalink
g5: Add hwaddrs to set WiFi and BT addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
rmcc authored and Rashed97 committed May 26, 2016
1 parent f8d555b commit dafe9d8
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 0 deletions.
4 changes: 4 additions & 0 deletions g5.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
27 changes: 27 additions & 0 deletions hwaddrs/Android.mk
Original file line number Diff line number Diff line change
@@ -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)
60 changes: 60 additions & 0 deletions hwaddrs/getmac.c
Original file line number Diff line number Diff line change
@@ -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 <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

/* 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;
}
4 changes: 4 additions & 0 deletions system_prop.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit dafe9d8

Please sign in to comment.