Skip to content

Commit 1a23e55

Browse files
author
Daz Jones
committed
setbtmac: get the bdaddr from the radio instead of cheating
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
1 parent 2bfe1dd commit 1a23e55

File tree

4 files changed

+41
-37
lines changed

4 files changed

+41
-37
lines changed

setbtmac/Android.mk

+6-2
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,20 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
1615
LOCAL_PATH:= $(call my-dir)
1716
include $(CLEAR_VARS)
1817

18+
$(shell mkdir -p $(OUT)/obj/SHARED_LIBRARIES/libnv_intermediates/)
19+
$(shell touch $(OUT)/obj/SHARED_LIBRARIES/libnv_intermediates/export_includes)
20+
$(shell mkdir -p $(OUT)/obj/SHARED_LIBRARIES/liboncrpc_intermediates/)
21+
$(shell touch $(OUT)/obj/SHARED_LIBRARIES/liboncrpc_intermediates/export_includes)
22+
1923
LOCAL_MODULE_TAGS := optional
2024

2125
LOCAL_SRC_FILES := setbtmac.c
2226

2327
LOCAL_PRELINK_MODULE := true
24-
LOCAL_SHARED_LIBRARIES := libcutils
28+
LOCAL_SHARED_LIBRARIES := libcutils libnv liboncrpc
2529
LOCAL_MODULE := setbtmac
2630

2731
include $(BUILD_EXECUTABLE)

setbtmac/setbtmac.c

+28-21
Original file line numberDiff line numberDiff line change
@@ -20,43 +20,50 @@
2020
#include <cutils/properties.h>
2121
#include <sys/stat.h>
2222

23-
static const char PROP_SERIALNO[] = "ro.serialno";
23+
#define NV_READ_F 0
24+
#define NV_BD_ADDR_I 0x1BF
25+
26+
/* In libnv.so */
27+
extern void nv_cmd_remote(int func, int item, void *result);
28+
29+
/* In liboncrpc.so */
30+
extern void oncrpc_init();
31+
extern void oncrpc_deinit();
32+
extern void oncrpc_task_start();
33+
extern void oncrpc_task_stop();
34+
2435
static const char PROP_BDADDR[] = "ro.bt.bdaddr_path";
2536
static const char FILE_BDADDR[] = "/data/misc/bluetooth/.bdaddr";
2637

27-
void SetMAC(void);
28-
2938
int main()
3039
{
31-
SetMAC();
32-
return 0;
33-
}
34-
35-
void SetMAC(void)
36-
{
37-
char serialno[PROPERTY_VALUE_MAX];
3840
char bdaddr[PROPERTY_VALUE_MAX];
3941
int file;
4042

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

45-
property_get(PROP_SERIALNO, serialno, NULL);
45+
/* Set Bluetooth MAC address by loading it from the radio. */
46+
oncrpc_init();
47+
oncrpc_task_start();
48+
nv_cmd_remote(NV_READ_F, NV_BD_ADDR_I, &mac_bits);
49+
oncrpc_task_stop();
50+
oncrpc_deinit();
4651

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

52-
file = open(FILE_BDADDR, O_WRONLY|O_CREAT|O_TRUNC, 00600|00060|00006);
57+
file = open(FILE_BDADDR, O_WRONLY|O_CREAT|O_TRUNC, 00666);
58+
5359
if (file < 0)
54-
{
5560
ALOGE("Can't open %s\n", FILE_BDADDR);
56-
}
61+
5762
write(file, bdaddr, strlen(bdaddr));
5863
close(file);
59-
chmod(FILE_BDADDR, 00600|00060|00006);
64+
chmod(FILE_BDADDR, 00666);
6065

6166
property_set(PROP_BDADDR, FILE_BDADDR);
67+
68+
return 0;
6269
}

setwifimac/Android.mk

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (C) 2012 The CyanogenMod project
1+
# Copyright (C) 2013 The CyanogenMod project
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -12,7 +12,6 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
1615
LOCAL_PATH:= $(call my-dir)
1716
include $(CLEAR_VARS)
1817

setwifimac/setwifimac.c

+6-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2012 The CyanogenMod Project
2+
* Copyright (C) 2013 The CyanogenMod Project
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,19 +21,11 @@
2121
/* In libhwrpc.so */
2222
extern void huawei_oem_rapi_streaming_function(int n, int p1, int p2, int p3, int *v1, int *v2, char *v3);
2323

24-
static const char DRIVER_PROP_MAC_PARAM[] = "wlan.module.mac_param";
25-
26-
void SetMAC(void);
24+
static const char PROP_MAC_PARAM[] = "wlan.module.mac_param";
2725

2826
int main()
2927
{
30-
SetMAC();
31-
return 0;
32-
}
33-
34-
void SetMAC(void)
35-
{
36-
char wlan_mac_arg[PROPERTY_VALUE_MAX] = "mac_param=00:90:4c:ce:43:30";
28+
char wlan_mac_arg[PROPERTY_VALUE_MAX];
3729
char mac_bits[8];
3830
int y = 0;
3931

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

50-
property_set(DRIVER_PROP_MAC_PARAM, wlan_mac_arg);
42+
property_set(PROP_MAC_PARAM, wlan_mac_arg);
43+
44+
return 0;
5145
}

0 commit comments

Comments
 (0)