blob: 0f3412f618f0dc1b633600089a60c10b627979c3 [file] [log] [blame]
rjw1f884582022-01-06 17:20:42 +08001
2/******************************************************************************
3* C O M P I L E R F L A G S
4*******************************************************************************
5*/
6
7/******************************************************************************
8* E X T E R N A L R E F E R E N C E S
9*******************************************************************************
10*/
11#include <stdio.h>
12#include <stdlib.h>
13#include <unistd.h>
14#include <signal.h>
15#include <string.h>
16#include <sys/stat.h>
17#include <sys/sendfile.h>
18#include <fcntl.h>
19#include <linux/types.h>
20#include <limits.h>
21#include <getopt.h>
22#include <errno.h>
23#include <time.h>
24
25/******************************************************************************
26* C O N S T A N T S
27*******************************************************************************
28*/
29/* !defined(ANDROID) */
30
31
32/******************************************************************************
33* D A T A T Y P E S
34*******************************************************************************
35*/
36
37/******************************************************************************
38* M A C R O S
39*******************************************************************************
40*/
41
42/******************************************************************************
43* F U N C T I O N D E C L A R A T I O N S
44*******************************************************************************
45*/
46
47/******************************************************************************
48* P U B L I C D A T A
49*******************************************************************************
50*/
51
52/******************************************************************************
53* P R I V A T E D A T A
54*******************************************************************************
55*/
56char EEPROM_PATH[64] = "/data/misc/connectivity/EEPROM_MT7668.bin";
57
58/******************************************************************************
59* F U N C T I O N S
60*******************************************************************************
61*/
62int main(int argc, char *argv[]) {
63 FILE *fh = NULL, *frandom = NULL;
64 long random_value = 0;
65 int rc;
66 unsigned char uacEEPROMImage[6];
67
68 fh = fopen(EEPROM_PATH, "rb+");
69 if(fh != NULL) {
70 /*Check WIFI Mac address*/
71 fseek(fh, 0x4, SEEK_SET);
72 fread(uacEEPROMImage, sizeof(unsigned char), 6, fh);
73 if(uacEEPROMImage[0] == 0 && uacEEPROMImage[1] == 0 &&
74 uacEEPROMImage[2] == 0 && uacEEPROMImage[3] == 0 &&
75 uacEEPROMImage[4] == 0 && uacEEPROMImage[5] == 0)
76 {
77 //time(&timep);
78 /*Get Random value*/
79 frandom = fopen("/dev/urandom", "rb");
80 if (frandom == NULL) {
81 printf("Could not open /dev/urandom.\n");
82 return -1;
83 }
84
85 rc = fread(&random_value, 1, sizeof(long), frandom);
86 fclose(frandom);
87
88 //random_value = random();
89 printf("Time:%x\n", random_value);
90 uacEEPROMImage[0] = 0x00;
91 uacEEPROMImage[1] = 0x08;
92 uacEEPROMImage[2] = 0x22;
93 uacEEPROMImage[3] = random_value >> 16;
94 uacEEPROMImage[4] = random_value >> 8;
95 uacEEPROMImage[5] = random_value;
96
97 fseek(fh, 0x4, SEEK_SET);
98 fwrite(uacEEPROMImage, sizeof(unsigned char), 6, fh);
99 }
100
101 /*Check BT Mac Address*/
102 fseek(fh, 0x384, SEEK_SET);
103 fread(uacEEPROMImage, sizeof(unsigned char), 6, fh);
104 if(uacEEPROMImage[0] == 0 && uacEEPROMImage[1] == 0 &&
105 uacEEPROMImage[2] == 0 && uacEEPROMImage[3] == 0 &&
106 uacEEPROMImage[4] == 0 && uacEEPROMImage[5] == 0)
107 {
108 if (random_value == 0) {
109 frandom = fopen("/dev/urandom", "rb");
110 if (frandom == NULL) {
111 printf("Could not open /dev/urandom.\n");
112 return -1;
113 }
114
115 rc = fread(&random_value, 1, sizeof(long), frandom);
116 fclose(frandom);
117
118 uacEEPROMImage[0] = 0x00;
119 uacEEPROMImage[1] = 0x08;
120 uacEEPROMImage[2] = 0x22;
121 uacEEPROMImage[3] = random_value >> 16;
122 uacEEPROMImage[4] = random_value >> 8;
123 uacEEPROMImage[5] = random_value;
124 }
125 else {
126 uacEEPROMImage[0] = 0x00;
127 uacEEPROMImage[1] = 0x08;
128 uacEEPROMImage[2] = 0x22;
129 uacEEPROMImage[3] = random_value >> 16;
130 uacEEPROMImage[4] = random_value >> 8;
131 uacEEPROMImage[5] = random_value + 1;
132 }
133
134 fseek(fh, 0x384, SEEK_SET);
135 fwrite(uacEEPROMImage, sizeof(unsigned char), 6, fh);
136 }
137
138 fclose(fh);
139 }
140 return 0;
141}