Skip to content

Commit

Permalink
sagit: read wlan mac address
Browse files Browse the repository at this point in the history
  • Loading branch information
thune-xiaobai authored and Verevka committed Jul 27, 2017
1 parent 1bb7a29 commit cc7c990
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 0 deletions.
1 change: 1 addition & 0 deletions device.mk
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ PRODUCT_PACKAGES += \
libQWiFiSoftApCfg \
libwpa_client \
hostapd \
readmac \
dhcpcd.conf \
wpa_supplicant \
wpa_supplicant.conf
Expand Down
11 changes: 11 additions & 0 deletions readmac/Android.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
LOCAL_PATH:= $(call my-dir)

ifeq ($(strip $(BOARD_HAS_QCOM_WLAN)),true)
include $(CLEAR_VARS)
LOCAL_MODULE := readmac
LOCAL_MODULE_TAGS := optional
LOCAL_SRC_FILES := xiaomi_readmac.c
LOCAL_CFLAGS += -Wall
LOCAL_SHARED_LIBRARIES := libc libcutils libutils liblog libqminvapi
include $(BUILD_EXECUTABLE)
endif
88 changes: 88 additions & 0 deletions readmac/xiaomi_readmac.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* Copyright (C) 2016 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.
*/

#define LOG_TAG "xiaomi_readmac"
#define LOG_NDEBUG 0

#include <cutils/log.h>

#include <string.h>

#define MAC_ADDR_SIZE 6
#define WLAN_MAC_BIN "/persist/wlan_mac.bin"

extern int qmi_nv_read_wlan_mac(char** mac);

static int check_wlan_mac_bin_file()
{
char content[1024];
FILE *fp;

fp = fopen(WLAN_MAC_BIN, "r");
if (fp != NULL) {
memset(content, 0, sizeof(content));
fread(content, 1, sizeof(content)-1, fp);
fclose(fp);

if (strstr(content, "Intf0MacAddress") == NULL) {
ALOGV("%s is missing Intf0MacAddress entry value", WLAN_MAC_BIN);
return 1;
}

if (strstr(content, "Intf1MacAddress") == NULL) {
ALOGV("%s is missing Intf1MacAddress entry value", WLAN_MAC_BIN);
return 1;
}

return 0;
}
return 1;
}

int main(int argc, char *argv[])
{
unsigned char wlan_addr[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
char* nv_wlan_mac = NULL;
int ret, i;
FILE *fp;

// Read WLAN MAC address from modem NV
ret = qmi_nv_read_wlan_mac(&nv_wlan_mac);
if (!nv_wlan_mac) {
ALOGE("qmi_nv_read_wlan_mac error %d", ret);
return 1;
}
for (i = 0; i < MAC_ADDR_SIZE; i++) {
wlan_addr[i] = nv_wlan_mac[i];
}

// Store WLAN MAC address in the persist file, if needed
if (check_wlan_mac_bin_file()) {
fp = fopen(WLAN_MAC_BIN, "w");
fprintf(fp, "Intf0MacAddress=%02X%02X%02X%02X%02X%02X\n",
wlan_addr[0], wlan_addr[1], wlan_addr[2], wlan_addr[3], wlan_addr[4], wlan_addr[5]);
fprintf(fp, "Intf1MacAddress=%02X%02X%02X%02X%02X%02X\n",
wlan_addr[0], wlan_addr[1], wlan_addr[2], wlan_addr[3], wlan_addr[4], (unsigned char)(wlan_addr[5]+1));
fprintf(fp, "END\n");
fclose(fp);

ALOGV("%s was successfully generated", WLAN_MAC_BIN);
} else {
ALOGV("%s already exists and is valid", WLAN_MAC_BIN);
}

return 0;
}
6 changes: 6 additions & 0 deletions rootdir/etc/init.target.rc
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,12 @@ service qdmastatsd /system/bin/qdmastatsd
user system
group system

service readmac /system/bin/readmac
class main
user root
group root
oneshot

on charger
write /sys/class/input/input0/enabled 0
write /sys/class/input/input1/enabled 0
Expand Down

0 comments on commit cc7c990

Please sign in to comment.