• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2012 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifdef CONFIG_LGE_WLAN_QCOM_PATCH
18 
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <string.h>
22 
23 #include "wfc_util_log.h"
24 #include "wfc_util_fctrl.h"
25 #include "wfc_util_common.h"
26 
27 #include "cutils/properties.h"
28 
29 #include "private/android_filesystem_config.h"
30 
31 #define WFC_UTIL_FEAUTRE_COPY_NV_BIN
32 
33 #ifdef WLAN_CHIP_VERSION_WCNSS
34 #ifndef WFC_UTIL_CFG_FILE_NAME
35 #define WFC_UTIL_CFG_FILE_NAME          "/data/misc/wifi/WCNSS_qcom_cfg.ini"
36 #endif
37 #ifndef WFC_UTIL_CFG_TEMPFILE_NAME
38 #define WFC_UTIL_CFG_TEMPFILE_NAME      "/system/etc/wifi/WCNSS_qcom_cfg.ini"
39 #endif
40 #else  /* WLAN_CHIP_VERSION_WCN1314 */
41 #ifndef WFC_UTIL_CFG_FILE_NAME
42 #define WFC_UTIL_CFG_FILE_NAME          "/data/misc/wifi/WCN1314_qcom_cfg.ini"
43 #endif
44 #ifndef WFC_UTIL_CFG_TEMPFILE_NAME
45 #define WFC_UTIL_CFG_TEMPFILE_NAME      "/system/etc/wifi/WCN1314_qcom_cfg.ini"
46 #endif
47 #endif /* WLAN_CHIP_VERSION_XXXX */
48 
49 #ifdef WFC_UTIL_FEAUTRE_COPY_NV_BIN
50 #ifdef WLAN_CHIP_VERSION_WCNSS
51 #ifndef WFC_UTIL_NV_BIN_TEMPFILE_NAME
52 #define WFC_UTIL_NV_BIN_TEMPFILE_NAME   "/system/etc/wifi/WCNSS_qcom_wlan_nv.bin"
53 #endif
54 #ifndef WFC_UTIL_NV_BIN_FILE_NAME
55 #define WFC_UTIL_NV_BIN_FILE_NAME       "/data/misc/wifi/WCNSS_qcom_wlan_nv.bin"
56 #endif
57 #else  /* WLAN_CHIP_VERSION_WCN1314 */
58 #ifndef WFC_UTIL_NV_BIN_TEMPFILE_NAME
59 #define WFC_UTIL_NV_BIN_TEMPFILE_NAME   "/persist/WCN1314_qcom_wlan_nv.bin"
60 #endif
61 #ifndef WFC_UTIL_NV_BIN_FILE_NAME
62 #define WFC_UTIL_NV_BIN_FILE_NAME       "/data/misc/wifi/WCN1314_qcom_wlan_nv.bin"
63 #endif
64 #endif /* WLAN_CHIP_VERSION_XXXX */
65 #else  /* WFC_UTIL_FEAUTRE_COPY_NV_BIN */
66 #ifndef WFC_UTIL_NV_BIN_FILE_NAME
67 #ifdef WLAN_CHIP_VERSION_WCNSS
68 #define WFC_UTIL_NV_BIN_FILE_NAME       "/persist/WCNSS_qcom_wlan_nv.bin"
69 #else  /* WLAN_CHIP_VERSION_WCN1314 */
70 #define WFC_UTIL_NV_BIN_FILE_NAME       "/persist/WCN1314_qcom_wlan_nv.bin"
71 #endif /* WLAN_CHIP_VERSION_XXXX */
72 #endif
73 #endif /* WFC_UTIL_FEAUTRE_COPY_NV_BIN */
74 
75 #define WFC_UTIL_CFG_TAG_END_OF_CFG     "END"
76 /*
77  * Station Mode MAC Address
78  */
79 #ifdef WLAN_CHIP_VERSION_WCNSS
80 #define WFC_UTIL_CFG_TAG_MAC_ADDRESS    "Intf0MacAddress="
81 #else  /* WLAN_CHIP_VERSION_WCN1314 */
82 #define WFC_UTIL_CFG_TAG_MAC_ADDRESS    "NetworkAddress="
83 #endif /* WLAN_CHIP_VERSION_XXXX */
84 /*
85  * AP Mode MAC Address
86  */
87 #define WFC_UTIL_CFG_TAG_AP_MAC_ADDRESS "gAPMacAddr="
88 
89 /*
90  * Idle Mode Power Save enable/disable for OTA test
91  */
92 #define WFC_UTIL_CFG_TAG_IDLE_MODE_POWER_SAVE "gEnableImps="
93 
94 /*
95  * Beacon Mode Power Save enable/disable for OTA test
96  */
97 #define WFC_UTIL_CFG_TAG_POWER_SAVE "gEnableBmps="
98 
99 /*
100  * L2 roaming on/off for OTA test
101  */
102 #define WFC_UTIL_CFG_TAG_L2Roaming "gEnableHandoff="
103 
104 /*
105  * Heartbeat24 changing for OtA test
106  */
107 #define WFC_UTIL_CFG_TAG_HEARTBEAT24 "gHeartbeat24="
108 
109 /*
110  * TAG for end of line
111  */
112 #define WFC_UTIL_CFG_TAG_END_OF_LINE    "\n"
113 
114 #define WFC_UTIL_CFG_LENGHT_MAC         (6)
115 #define WFC_UTIL_CFG_LENGHT_MAC_STRING  (WFC_UTIL_CFG_LENGHT_MAC*2)
116 
117 /*
118  * persist/WCNSS_qcom_wlan_nv.bin
119  *
120  * NV validity bitmap (4 bytes)
121  * {
122  *     Bit 0 - Regulatory domain tables
123  *     Bit 1 - Fields(including product ID, product bands, number of Tx/Rx chains, MAC address, manufacturing board number)
124  *     Bit 2 - Optimal power per rate table
125  *     Bit 3 - Default regulatory domain and country code
126  *     Bit 4:31 - Reserved; always 0
127  * }
128  *
129  * typedef PACKED_PRE struct PACKED_POST
130  * {
131  *     //always ensure fields are aligned to 32-bit boundaries
132  *     tANI_U16  productId;
133  *     tANI_U8   productBands;        //0: 0.4 GHz, 1: 2.4+5.0 GHz, 2: 5.0 GHz
134  *     tANI_U8   wlanNvRevId;         //0: WCN1312, 1: WCN1314, 2: PRIMA
135  *
136  *     tANI_U8   numOfTxChains;
137  *     tANI_U8   numOfRxChains;
138  *     tANI_U8   macAddr[NV_FIELD_MAC_ADDR_SIZE];
139  *     tANI_U8   mfgSN[NV_FIELD_MFG_SN_SIZE];
140  * } sNvFields;
141  */
142 #define WFC_UTIL_NV_BIN_HEADER_LENGTH   (4)
143 #define WFC_UTIL_NV_BIN_POS_PRODUCT_ID  (WFC_UTIL_NV_BIN_HEADER_LENGTH + 0)
144 #define WFC_UTIL_NV_BIN_POS_MAC_ADDR    (WFC_UTIL_NV_BIN_HEADER_LENGTH + 6)
145 
146 #ifdef WLAN_CHIP_VERSION_WCNSS
147 /* refer to prima/CORE/WDA/src/wlan_nv.c */
148 static unsigned char nvFilelds_default[6] = {0, 0, /* productId */
149                                              1,    /* productBands */
150                                              2,    /* wlanNvRevId */
151                                              1,    /* numOfTxChains */
152                                              2};   /* numOfRxChains */
153 #else  /* WLAN_CHIP_VERSION_WCN1314 */
154 static unsigned char nvFilelds_default[6] = {1, 0, /* productId */
155                                              1,    /* productBands */
156                                              1,    /* wlanNvRevId */
157                                              1,    /* numOfTxChains */
158                                              1};   /* numOfRxChains */
159 #endif /* WLAN_CHIP_VERSION_XXXX */
160 
161 /*
162  * wfc_util_qcom_is_default_mac
163  *
164  *
165  *
166  * return : it will return 1 if mac_add is default mac address,
167  *          2 if mac_add is RFT mac address
168  *          or 0 if not.
169  */
wfc_util_qcom_is_default_mac(char * mac_add)170 static int wfc_util_qcom_is_default_mac(char *mac_add)
171 {
172 #define WFC_UTIL_CFG_DEFAULT_MAC_RFT     "00900CBACD88"
173 #define WFC_UTIL_CFG_DEFAULT_MAC_00      "000000000000"
174 #define WFC_UTIL_CFG_DEFAULT_MAC_FF      "FFFFFFFFFFFF"
175 #define WFC_UTIL_CFG_DEFAULT_MAC_QCOM_I0 "000AF58989FF"
176 #define WFC_UTIL_CFG_DEFAULT_MAC_QCOM_I1 "000AF58989FE"
177 #define WFC_UTIL_CFG_DEFAULT_MAC_QCOM_I2 "000AF58989FD"
178 #define WFC_UTIL_CFG_DEFAULT_MAC_QCOM_I3 "000AF58989FC"
179 #define WFC_UTIL_CFG_DEFAULT_MAC_QCOM_AP "000AF58989EF"
180 
181 	int i, sZarray=0;
182 	/*
183 	 * default mac address array
184 	 */
185 	char mac_add_buff[][WFC_UTIL_CFG_LENGHT_MAC_STRING+1] = {
186 			{WFC_UTIL_CFG_DEFAULT_MAC_00},
187 			{WFC_UTIL_CFG_DEFAULT_MAC_FF},
188 			{WFC_UTIL_CFG_DEFAULT_MAC_QCOM_I0}
189 	};
190 
191 	sZarray = sizeof(mac_add_buff) / sizeof(mac_add_buff[0]);
192 
193 	for(i=0; i<sZarray ;i++) {
194 		if(0 == strncmp(mac_add, mac_add_buff[i], WFC_UTIL_CFG_LENGHT_MAC_STRING)) {
195 			wfc_util_log_error("This is default MAC address [%s]", mac_add_buff[i]);
196 			return 1;
197 		}
198 	}
199 
200 	/*
201 	if(1 == wfc_util_is_random_mac(mac_add)) {
202 		wfc_util_log_error("This is Random MAC address");
203 		return 1;
204 	}
205 	*/
206 
207 	if(0 == strncmp(mac_add, WFC_UTIL_CFG_DEFAULT_MAC_RFT, WFC_UTIL_CFG_LENGHT_MAC_STRING)) {
208 		wfc_util_log_error("This is RFT MAC address [%s]", WFC_UTIL_CFG_DEFAULT_MAC_RFT);
209 		return 2;
210 	}
211 
212 	return 0;
213 }
214 
wfc_util_qcom_write_mac(char * mac_add)215 static void wfc_util_qcom_write_mac(char *mac_add)
216 {
217 	/*
218 	 * Station Mode MAC Address
219 	 */
220 	wfc_util_fset_string(WFC_UTIL_CFG_FILE_NAME,
221 	                     WFC_UTIL_CFG_TAG_END_OF_CFG,
222 	                     WFC_UTIL_CFG_TAG_MAC_ADDRESS,
223 	                     WFC_UTIL_CFG_TAG_END_OF_LINE,
224 	                     mac_add);
225 
226 	/*
227 	 * AP Mode MAC Address
228 	 */
229 	wfc_util_fset_string(WFC_UTIL_CFG_FILE_NAME,
230 	                     WFC_UTIL_CFG_TAG_END_OF_CFG,
231 	                     WFC_UTIL_CFG_TAG_AP_MAC_ADDRESS,
232 	                     WFC_UTIL_CFG_TAG_END_OF_LINE,
233 	                     mac_add);
234 
235 	return;
236 }
237 
238 /*
239  *  When OTA is enabled, power save mode and L2 roaming trigger should be off
240  */
wfc_util_qcom_write_ota_enable(void)241 static void wfc_util_qcom_write_ota_enable(void)
242 {
243 /*
244  * write Beacon Mode Power Save off and L2 Roaming off
245  */
246 	char *PowerSaveOff = "0";
247 	//char *L2RoamingOff = "0";
248 	char *Heartbeat24 = "120";
249 
250 	char string_buff[5];
251 
252 	wfc_util_fset_string(WFC_UTIL_CFG_FILE_NAME,
253 	                     WFC_UTIL_CFG_TAG_END_OF_CFG,
254 	                     WFC_UTIL_CFG_TAG_IDLE_MODE_POWER_SAVE,
255 	                     WFC_UTIL_CFG_TAG_END_OF_LINE,
256 	                     PowerSaveOff);
257 
258 	wfc_util_fset_string(WFC_UTIL_CFG_FILE_NAME,
259 	                     WFC_UTIL_CFG_TAG_END_OF_CFG,
260 	                     WFC_UTIL_CFG_TAG_POWER_SAVE,
261 	                     WFC_UTIL_CFG_TAG_END_OF_LINE,
262 	                     PowerSaveOff);
263 
264 /* We don't need to change this becasue the default value of WFC_UTIL_CFG_TAG_L2Roaming is 0.
265 	wfc_util_fset_string(WFC_UTIL_CFG_FILE_NAME,
266 	                     WFC_UTIL_CFG_TAG_END_OF_CFG,
267 	                     WFC_UTIL_CFG_TAG_L2Roaming,
268 	                     WFC_UTIL_CFG_TAG_END_OF_LINE,
269 	                     L2RoamingOff);
270 */
271 
272 	if(0 < wfc_util_fget_string(WFC_UTIL_CFG_FILE_NAME,
273 	                            WFC_UTIL_CFG_TAG_END_OF_CFG,
274 	                            WFC_UTIL_CFG_TAG_HEARTBEAT24,
275 	                            WFC_UTIL_CFG_TAG_END_OF_LINE,
276 	                            string_buff,
277 	                            5)) {
278 		wfc_util_fset_string(WFC_UTIL_CFG_FILE_NAME,
279 		                     WFC_UTIL_CFG_TAG_END_OF_CFG,
280 		                     WFC_UTIL_CFG_TAG_HEARTBEAT24,
281 		                     WFC_UTIL_CFG_TAG_END_OF_LINE,
282 		                     Heartbeat24);
283 	} else {
284 		wfc_util_log_error("%s is not exist", WFC_UTIL_CFG_TAG_HEARTBEAT24);
285 	}
286 
287 	return;
288 }
289 
290 /*
291  *  When OTA is enabled, power save mode and L2 roaming trigger should be off
292  */
wfc_util_qcom_write_ota_disable(void)293 static void wfc_util_qcom_write_ota_disable(void)
294 {
295 /*
296  * write Beacon Mode Power Save on and L2 Roaming on
297  */
298 	char *PowerSaveOff = "1";
299 	//char *L2RoamingOff = "1";
300 	char *Heartbeat24 = "40";
301 
302 	char string_buff[5];
303 
304 	wfc_util_fset_string(WFC_UTIL_CFG_FILE_NAME,
305 	                     WFC_UTIL_CFG_TAG_END_OF_CFG,
306 	                     WFC_UTIL_CFG_TAG_IDLE_MODE_POWER_SAVE,
307 	                     WFC_UTIL_CFG_TAG_END_OF_LINE,
308 	                     PowerSaveOff);
309 
310 	wfc_util_fset_string(WFC_UTIL_CFG_FILE_NAME,
311 	                     WFC_UTIL_CFG_TAG_END_OF_CFG,
312 	                     WFC_UTIL_CFG_TAG_POWER_SAVE,
313 	                     WFC_UTIL_CFG_TAG_END_OF_LINE,
314 	                     PowerSaveOff);
315 
316 /* We don't need to change this becasue the default value of WFC_UTIL_CFG_TAG_L2Roaming is 0.
317 	wfc_util_fset_string(WFC_UTIL_CFG_FILE_NAME,
318 	                     WFC_UTIL_CFG_TAG_END_OF_CFG,
319 	                     WFC_UTIL_CFG_TAG_L2Roaming,
320 	                     WFC_UTIL_CFG_TAG_END_OF_LINE,
321 	                     L2RoamingOff);
322 */
323 
324 	if(0 < wfc_util_fget_string(WFC_UTIL_CFG_FILE_NAME,
325 	                            WFC_UTIL_CFG_TAG_END_OF_CFG,
326 	                            WFC_UTIL_CFG_TAG_HEARTBEAT24,
327 	                            WFC_UTIL_CFG_TAG_END_OF_LINE,
328 	                            string_buff,
329 	                            5)) {
330 		wfc_util_fset_string(WFC_UTIL_CFG_FILE_NAME,
331 		                     WFC_UTIL_CFG_TAG_END_OF_CFG,
332 		                     WFC_UTIL_CFG_TAG_HEARTBEAT24,
333 		                     WFC_UTIL_CFG_TAG_END_OF_LINE,
334 		                     Heartbeat24);
335 	} else {
336 		wfc_util_log_error("%s is not exist", WFC_UTIL_CFG_TAG_HEARTBEAT24);
337 	}
338 
339 	return;
340 }
341 
wfc_util_qcom_write_mac_to_bin(unsigned char * mac_add)342 static void wfc_util_qcom_write_mac_to_bin(unsigned char *mac_add)
343 {
344 	unsigned char nvValidityBitmap[WFC_UTIL_NV_BIN_HEADER_LENGTH];
345 
346 	if(0 != wfc_util_ffile_check(WFC_UTIL_NV_BIN_FILE_NAME,
347 	                             F_OK|R_OK|W_OK)) {
348 		wfc_util_log_error("We don't access file [%s]", WFC_UTIL_NV_BIN_FILE_NAME);
349 		return;
350 	}
351 
352 	memset(nvValidityBitmap, 0, WFC_UTIL_NV_BIN_HEADER_LENGTH);
353 
354 	/*
355 	 * Write RFT MAC Address
356 	 */
357 	wfc_util_fset_buffer(WFC_UTIL_NV_BIN_FILE_NAME,
358 	                     WFC_UTIL_NV_BIN_POS_MAC_ADDR,
359 	                     mac_add,
360 	                     WFC_UTIL_CFG_LENGHT_MAC);
361 
362 	/*
363 	 * Read NV validity bitmap
364 	 */
365 	if (0 < wfc_util_fget_buffer(WFC_UTIL_NV_BIN_FILE_NAME,
366 	                             0,
367 	                             WFC_UTIL_NV_BIN_HEADER_LENGTH,
368 	                             nvValidityBitmap,
369 	                             WFC_UTIL_NV_BIN_HEADER_LENGTH)){
370 	        /*
371 	         * Check whether Fields bit(Bit 1) is set
372 	         */
373 		if (0x02 & nvValidityBitmap[0]) {
374 			wfc_util_log_info("We don't need to write the default value for NvFilelds");
375 		} else {
376 		        /*
377 		         * Update the Fields bit(Bit 1)
378 		         */
379 			nvValidityBitmap[0] |= 0x02;
380 			wfc_util_fset_buffer(WFC_UTIL_NV_BIN_FILE_NAME,
381 			                     0,
382 			                     nvValidityBitmap,
383 			                     WFC_UTIL_NV_BIN_HEADER_LENGTH);
384 
385 		        /*
386 		         * Write the default value for NvFilelds
387 		         */
388 			wfc_util_fset_buffer(WFC_UTIL_NV_BIN_FILE_NAME,
389 			                     WFC_UTIL_NV_BIN_POS_PRODUCT_ID,
390 			                     nvFilelds_default,
391 			                     6);
392 		}
393 	} else {
394 		wfc_util_log_error("Read Fail nvValidityBitmap");
395 	}
396 
397 	return;
398 }
399 
400 /*
401  * wfc_util_qcom_reset_mac_to_bin
402  *
403  * reset the mac address of nv bin file
404  *
405  * return : void
406  */
wfc_util_qcom_reset_mac_to_bin(void)407 static void wfc_util_qcom_reset_mac_to_bin(void)
408 {
409 	unsigned char mac_addr[WFC_UTIL_CFG_LENGHT_MAC];
410 
411 	if(0 != wfc_util_ffile_check(WFC_UTIL_NV_BIN_FILE_NAME,
412 	                             F_OK|R_OK|W_OK)) {
413 		wfc_util_log_error("We don't access file [%s]", WFC_UTIL_NV_BIN_FILE_NAME);
414 		return;
415 	}
416 
417 	if(0 < wfc_util_fget_buffer(WFC_UTIL_NV_BIN_FILE_NAME,
418 	                            WFC_UTIL_NV_BIN_POS_MAC_ADDR,
419 	                            WFC_UTIL_CFG_LENGHT_MAC,
420 	                            mac_addr,
421 	                            WFC_UTIL_CFG_LENGHT_MAC)) {
422 		if(0x00 == mac_addr[0] && 0x00 == mac_addr[1] && 0x00 == mac_addr[2] &&
423 		   0x00 == mac_addr[3] && 0x00 == mac_addr[4] && 0x00 == mac_addr[5])
424 		{
425 			return;
426 		}
427 	}
428 
429 	memset(mac_addr, 0, WFC_UTIL_CFG_LENGHT_MAC);
430 
431 	wfc_util_fset_buffer(WFC_UTIL_NV_BIN_FILE_NAME,
432 	                     WFC_UTIL_NV_BIN_POS_MAC_ADDR,
433 	                     mac_addr,
434 	                     WFC_UTIL_CFG_LENGHT_MAC);
435 
436 	return;
437 }
438 
wfc_util_qcom_write_mac_process(unsigned char * nv_mac_addr,char * mac_add_buff)439 static int wfc_util_qcom_write_mac_process(unsigned char *nv_mac_addr, char *mac_add_buff)
440 {
441 	char nv_mac_add_buff[WFC_UTIL_CFG_LENGHT_MAC_STRING+1];
442 	int  is_default_nv_mac = 0;
443 	int  is_same_mac = -1;
444 
445 	if (NULL == nv_mac_addr) {
446 		return 0;
447 	}
448 
449 	wfc_util_htoa(nv_mac_addr, WFC_UTIL_CFG_LENGHT_MAC,
450 	              nv_mac_add_buff, WFC_UTIL_CFG_LENGHT_MAC_STRING+1);
451 
452 	is_default_nv_mac = wfc_util_qcom_is_default_mac(nv_mac_add_buff);
453 
454 	is_same_mac = strncmp(mac_add_buff, nv_mac_add_buff, WFC_UTIL_CFG_LENGHT_MAC_STRING);
455 
456 	/*
457 	 * 1. nv mac address is not a default mac address
458 	 * 2. same with mac address of config file
459 	 */
460 	if (((!is_default_nv_mac) && (0==is_same_mac)) ||
461 	/*
462 	 * 1. nv mac address is RFT mac address
463 	 * 2. same with mac address of config file
464 	 */
465 	    ((2==is_default_nv_mac) && (0==is_same_mac))
466 	   ) {
467 		return 1;
468 	}
469 	/*
470 	 * 1. nv mac address not a default mac address excepting RFT mac address
471 	 * 2. does not same with mac address of config file
472 	 */
473 	else if ((1!=is_default_nv_mac) && (0!=is_same_mac)) {
474 		wfc_util_log_error("Change %s%s", WFC_UTIL_CFG_TAG_MAC_ADDRESS, nv_mac_add_buff);
475 		/*
476 		 * Update MAC address
477 		 */
478 		wfc_util_qcom_write_mac(nv_mac_add_buff);
479 
480 #ifdef WFC_UTIL_FEATURE_DO_NOT_WRITE_MAC_TO_BIN
481 		/*
482 		 * Write RFT MAC address to nv.bin
483 		 */
484 		if (2==is_default_nv_mac) {
485 			wfc_util_qcom_write_mac_to_bin(nv_mac_addr);
486 		/*
487 		 * reset mac address of nv.bin if nv_mac_addr is not RFT mac address
488 		 */
489 		} else {
490 			wfc_util_qcom_reset_mac_to_bin();
491 		}
492 #else  /* WFC_UTIL_FEATURE_DO_NOT_WRITE_MAC_TO_BIN */
493 		/*
494 		 * Write MAC address to nv.bin
495 		 */
496 		wfc_util_qcom_write_mac_to_bin(nv_mac_addr);
497 #endif /* WFC_UTIL_FEATURE_DO_NOT_WRITE_MAC_TO_BIN */
498 
499 		return 1;
500 	}
501 
502 	return 0;
503 }
504 
wfc_util_qcom_create_random_mac(void)505 static void wfc_util_qcom_create_random_mac(void)
506 {
507 	unsigned char random_mac_addr[WFC_UTIL_CFG_LENGHT_MAC];
508 	char mac_add_buff[WFC_UTIL_CFG_LENGHT_MAC_STRING+1];
509 
510 	wfc_util_log_info("wfc_util_qcom_create_random_mac");
511 
512 	wfc_util_random_mac(random_mac_addr);
513 
514 	wfc_util_htoa(random_mac_addr, WFC_UTIL_CFG_LENGHT_MAC, mac_add_buff, WFC_UTIL_CFG_LENGHT_MAC_STRING+1);
515 
516 	wfc_util_qcom_write_mac(mac_add_buff);
517 
518 #ifdef WFC_UTIL_FEATURE_DO_NOT_WRITE_MAC_TO_BIN
519 	wfc_util_qcom_reset_mac_to_bin();
520 #else  /* WFC_UTIL_FEATURE_DO_NOT_WRITE_MAC_TO_BIN */
521 	wfc_util_qcom_write_mac_to_bin(random_mac_addr);
522 #endif /* WFC_UTIL_FEATURE_DO_NOT_WRITE_MAC_TO_BIN */
523 
524 	return;
525 }
526 
527 /*
528  * wfc_util_qcom_check_config
529  *
530  * check the qcom wlan driver config file
531  *
532  * return : it will return 0 if procedure is success
533  *          or will return -1 if not.
534  */
wfc_util_qcom_check_config(unsigned char * nv_mac_addr)535 int wfc_util_qcom_check_config(unsigned char *nv_mac_addr)
536 {
537 	char mac_add_buff[WFC_UTIL_CFG_LENGHT_MAC_STRING+1];
538 
539 	/* make sure driver config file exists */
540 	if(0 > wfc_util_ffile_check_copy(WFC_UTIL_CFG_FILE_NAME,
541 	                             WFC_UTIL_CFG_TEMPFILE_NAME,
542 	                             0660,
543 	                             AID_SYSTEM,
544 	                             /* we use "radio" for gid to access from "rild" for AT cmd. */
545 	                             AID_WIFI/*AID_WIFI*/)) {
546 		wfc_util_log_error("Fail to Access [%s]", WFC_UTIL_CFG_FILE_NAME);
547 		return -1;
548 	}
549 
550 #ifdef WFC_UTIL_FEAUTRE_COPY_NV_BIN
551 	char nv_bin_tempfile_name[50];
552 	char baseband[PROPERTY_VALUE_MAX];
553 
554 	// Default use WCNSS_qcom_wlan_nv_flo.bin
555 	property_get("ro.boot.baseband", baseband, "apq");
556 	if(!strncmp(baseband, "apq", 3)) {
557 		sprintf(nv_bin_tempfile_name, "/system/etc/wifi/WCNSS_qcom_wlan_nv_flo.bin");
558 	} else if( !strncmp(baseband, "mdm", 3)){
559 		sprintf(nv_bin_tempfile_name, "/system/etc/wifi/WCNSS_qcom_wlan_nv_deb.bin");
560 	}
561 	wfc_util_log_error("nv bin : %s", nv_bin_tempfile_name);
562 
563 	if(0 > wfc_util_ffile_check_copy(WFC_UTIL_NV_BIN_FILE_NAME,
564 	                             nv_bin_tempfile_name,
565 	                             0660,
566 	                             AID_SYSTEM,
567 	                             /* we use "radio" for gid to access from "rild" for AT cmd. */
568 	                             AID_WIFI/*AID_WIFI*/)) {
569 		wfc_util_log_error("Fail to Access [%s]", WFC_UTIL_NV_BIN_FILE_NAME);
570 		return -1;
571 	}
572 #endif /* WFC_UTIL_FEAUTRE_COPY_NV_BIN */
573 
574 	/*
575 	 * Read MAC address from config file
576 	 */
577 	if(0 < wfc_util_fget_string(WFC_UTIL_CFG_FILE_NAME,
578 	                        WFC_UTIL_CFG_TAG_END_OF_CFG,
579 	                        WFC_UTIL_CFG_TAG_MAC_ADDRESS,
580 	                        WFC_UTIL_CFG_TAG_END_OF_LINE,
581 	                        mac_add_buff,
582 	                        WFC_UTIL_CFG_LENGHT_MAC_STRING+1)) {
583 		wfc_util_log_info("%s%s", WFC_UTIL_CFG_TAG_MAC_ADDRESS, mac_add_buff);
584 
585 		/*
586 		 * Write nv mac address
587 		 */
588 		if (1 != wfc_util_qcom_write_mac_process(nv_mac_addr, mac_add_buff)) {
589 			/*
590 			 * Check whether this is default mac address or not
591 			 */
592 			if (wfc_util_qcom_is_default_mac(mac_add_buff)) {
593 				/*
594 				 * Create random MAC address
595 				 */
596 				wfc_util_qcom_create_random_mac();
597 			}
598 		}
599 	} else {
600 		wfc_util_log_error("%s does not have mac address", WFC_UTIL_CFG_FILE_NAME);
601 
602 		memset( mac_add_buff, 0, WFC_UTIL_CFG_LENGHT_MAC_STRING+1 );
603 
604 		/*
605 		 * Write nv mac address
606 		 */
607 		if (1 != wfc_util_qcom_write_mac_process(nv_mac_addr, mac_add_buff)) {
608 			/*
609 			 * Create random MAC address
610 			 */
611 			wfc_util_qcom_create_random_mac();
612 		}
613 	}
614 
615 	return 0;
616 }
617 
618 /*
619  * wfc_util_qcom_reset_mac
620  *
621  * reset the mac address of config file
622  *
623  * return : void
624  */
wfc_util_qcom_reset_mac(void)625 void wfc_util_qcom_reset_mac(void)
626 {
627 	wfc_util_qcom_write_mac("000000000000");
628 
629 	wfc_util_qcom_reset_mac_to_bin();
630 
631 	return;
632 }
633 
634 /*
635  * wfc_util_qcom_ota_enable
636  *
637  * enable ota mode by reconfiguring BMPS and L2Roaming
638  *
639  * return : int (boolean)
640  */
wfc_util_qcom_ota_enable(void)641 int wfc_util_qcom_ota_enable(void)
642 {
643 	wfc_util_qcom_write_ota_enable();
644 	return 1;
645 }
646 
647 /*
648  * wfc_util_qcom_ota_disable
649  *
650  * disable ota mode by reconfiguring BMPS and L2Roaming
651  *
652  * return : int (boolean)
653  */
wfc_util_qcom_ota_disable(void)654 int wfc_util_qcom_ota_disable(void)
655 {
656 	wfc_util_qcom_write_ota_disable();
657 	return 1;
658 }
659 
660 /*
661  * wfc_util_qcom_checkt_roaming_off
662  *
663  * Check L2Roaming configuration
664  *
665  * return : int (boolean)
666  */
wfc_util_qcom_checkt_roaming_off(void)667 int wfc_util_qcom_checkt_roaming_off(void)
668 {
669 	char string_buff[5];
670 	/*
671 	 * check whether OTA test is enabled or not.
672 	 */
673 	if(0 < wfc_util_fget_string(WFC_UTIL_CFG_FILE_NAME,
674 	                            WFC_UTIL_CFG_TAG_END_OF_CFG,
675 	                            //WFC_UTIL_CFG_TAG_L2Roaming,
676 	                            WFC_UTIL_CFG_TAG_POWER_SAVE,
677 	                            WFC_UTIL_CFG_TAG_END_OF_LINE,
678 	                            string_buff,
679 	                            5)) {
680 		//wfc_util_log_info("%s%s", WFC_UTIL_CFG_TAG_L2Roaming, string_buff);
681 		wfc_util_log_info("%s%s", WFC_UTIL_CFG_TAG_POWER_SAVE, string_buff);
682 		if(0 == strncmp(string_buff, "0", 1)) {
683 			return 1;
684 		}
685 	}
686 	return 0;
687 }
688 
689 #endif /* CONFIG_LGE_WLAN_QCOM_PATCH */
690 
691