/
setbtmac.c
60 lines (50 loc) · 1.62 KB
/
setbtmac.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*
* 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.
* 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 <fcntl.h>
#include <string.h>
#include <cutils/log.h>
#include <cutils/properties.h>
static const char PROP_SERIALNO[] = "ro.serialno";
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. */
property_get(PROP_SERIALNO, serialno, NULL);
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);
printf("%s\n", bdaddr);
file = open(FILE_BDADDR, O_WRONLY|O_CREAT|O_TRUNC, 00600|00060|00006);
if (file < 0)
{
ALOGE("Can't open %s\n", FILE_BDADDR);
}
write(file, bdaddr, strlen(bdaddr));
close(file);
property_set(PROP_BDADDR, FILE_BDADDR);
}