Skip to content

Commit

Permalink
setbtmac: get the bdaddr from the radio instead of cheating
Browse files Browse the repository at this point in the history
Cheating worked unless you were on the Gingerbread bootloader, as
the serialno was not set to the bdaddr but some other weird string.

This is pretty much the same method that brcm_patchram_plus uses, without
all of the fancy structs and enums... and error checking, but it's hard to do
that without having the code for this stuff, and probably not really necessary
anyway. :D

Also clean up setwifimac
  • Loading branch information
Daz Jones committed Sep 28, 2013
1 parent 2bfe1dd commit 1a23e55
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 37 deletions.
8 changes: 6 additions & 2 deletions setbtmac/Android.mk
Expand Up @@ -12,16 +12,20 @@
# See the License for the specific language governing permissions and
# limitations under the License.


LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)

$(shell mkdir -p $(OUT)/obj/SHARED_LIBRARIES/libnv_intermediates/)
$(shell touch $(OUT)/obj/SHARED_LIBRARIES/libnv_intermediates/export_includes)
$(shell mkdir -p $(OUT)/obj/SHARED_LIBRARIES/liboncrpc_intermediates/)
$(shell touch $(OUT)/obj/SHARED_LIBRARIES/liboncrpc_intermediates/export_includes)

LOCAL_MODULE_TAGS := optional

LOCAL_SRC_FILES := setbtmac.c

LOCAL_PRELINK_MODULE := true
LOCAL_SHARED_LIBRARIES := libcutils
LOCAL_SHARED_LIBRARIES := libcutils libnv liboncrpc
LOCAL_MODULE := setbtmac

include $(BUILD_EXECUTABLE)
49 changes: 28 additions & 21 deletions setbtmac/setbtmac.c
Expand Up @@ -20,43 +20,50 @@
#include <cutils/properties.h>
#include <sys/stat.h>

static const char PROP_SERIALNO[] = "ro.serialno";
#define NV_READ_F 0
#define NV_BD_ADDR_I 0x1BF

/* In libnv.so */
extern void nv_cmd_remote(int func, int item, void *result);

/* In liboncrpc.so */
extern void oncrpc_init();
extern void oncrpc_deinit();
extern void oncrpc_task_start();
extern void oncrpc_task_stop();

static const char PROP_BDADDR[] = "ro.bt.bdaddr_path";
static const char FILE_BDADDR[] = "/data/misc/bluetooth/.bdaddr";

void SetMAC(void);

int main()
{
SetMAC();
return 0;
}

void SetMAC(void)
{
char serialno[PROPERTY_VALUE_MAX];
char bdaddr[PROPERTY_VALUE_MAX];
int file;

/* The Bluetooth MAC address is the same as the device's serialno.
Use this as the Bluetooth stack introduced in 4.2 cannot get our
MAC address due to Huawei weirdness. */
int mac_bits[2] = { 0, };

property_get(PROP_SERIALNO, serialno, NULL);
/* Set Bluetooth MAC address by loading it from the radio. */
oncrpc_init();
oncrpc_task_start();
nv_cmd_remote(NV_READ_F, NV_BD_ADDR_I, &mac_bits);
oncrpc_task_stop();
oncrpc_deinit();

sprintf(bdaddr, "%2.2s:%2.2s:%2.2s:%2.2s:%2.2s:%2.2s",
serialno, serialno+2, serialno+4,
serialno+6, serialno+8, serialno+10);
sprintf(bdaddr, "%02X:%02X:%02X:%02X:%02X:%02X",
(mac_bits[1]&0xFF00) >> 8, mac_bits[1]&0xFF, (mac_bits[0]&0xFF000000) >> 24,
(mac_bits[0]&0xFF0000) >> 16, (mac_bits[0]&0xFF00) >> 8, mac_bits[0]&0xFF);
printf("%s\n", bdaddr);

file = open(FILE_BDADDR, O_WRONLY|O_CREAT|O_TRUNC, 00600|00060|00006);
file = open(FILE_BDADDR, O_WRONLY|O_CREAT|O_TRUNC, 00666);

if (file < 0)
{
ALOGE("Can't open %s\n", FILE_BDADDR);
}

write(file, bdaddr, strlen(bdaddr));
close(file);
chmod(FILE_BDADDR, 00600|00060|00006);
chmod(FILE_BDADDR, 00666);

property_set(PROP_BDADDR, FILE_BDADDR);

return 0;
}
3 changes: 1 addition & 2 deletions setwifimac/Android.mk
@@ -1,4 +1,4 @@
# Copyright (C) 2012 The CyanogenMod project
# Copyright (C) 2013 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.
Expand All @@ -12,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.


LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)

Expand Down
18 changes: 6 additions & 12 deletions setwifimac/setwifimac.c
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2012 The CyanogenMod Project
* Copyright (C) 2013 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.
Expand All @@ -21,19 +21,11 @@
/* In libhwrpc.so */
extern void huawei_oem_rapi_streaming_function(int n, int p1, int p2, int p3, int *v1, int *v2, char *v3);

static const char DRIVER_PROP_MAC_PARAM[] = "wlan.module.mac_param";

void SetMAC(void);
static const char PROP_MAC_PARAM[] = "wlan.module.mac_param";

int main()
{
SetMAC();
return 0;
}

void SetMAC(void)
{
char wlan_mac_arg[PROPERTY_VALUE_MAX] = "mac_param=00:90:4c:ce:43:30";
char wlan_mac_arg[PROPERTY_VALUE_MAX];
char mac_bits[8];
int y = 0;

Expand All @@ -47,5 +39,7 @@ void SetMAC(void)
mac_bits[2], mac_bits[1], mac_bits[0]);
printf("%s\n", wlan_mac_arg);

property_set(DRIVER_PROP_MAC_PARAM, wlan_mac_arg);
property_set(PROP_MAC_PARAM, wlan_mac_arg);

return 0;
}

0 comments on commit 1a23e55

Please sign in to comment.