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 #include <stdio.h>
18 #include <stdlib.h>
19 #include <string.h>
20 #include <getopt.h>
21 #include "wfc_util_fctrl.h"
22 #include "wfc_util_common.h"
23 
24 #ifdef WLAN_CHIP_VERSION_WCNSS
25 #ifndef WFC_UTIL_CFG_FILE_NAME
26 #define WFC_UTIL_CFG_FILE_NAME          "./WCNSS_qcom_cfg.ini"
27 #endif
28 #ifndef WFC_UTIL_NV_BIN_FILE_NAME
29 #define WFC_UTIL_NV_BIN_FILE_NAME       "./WCNSS_qcom_wlan_nv.bin"
30 #endif
31 #else  /* WLAN_CHIP_VERSION_WCN1314 */
32 #ifndef WFC_UTIL_CFG_FILE_NAME
33 #define WFC_UTIL_CFG_FILE_NAME          "./WCN1314_qcom_cfg.ini"
34 #endif
35 #ifndef WFC_UTIL_NV_BIN_FILE_NAME
36 #define WFC_UTIL_NV_BIN_FILE_NAME       "./WCN1314_qcom_wlan_nv.bin"
37 #endif
38 #endif /* WLAN_CHIP_VERSION_XXXX */
39 #define WFC_UTIL_CFG_TAG_END_OF_CFG     "END"
40 #define WFC_UTIL_CFG_TAG_MAC_ADDRESS    "NetworkAddress="
41 #define WFC_UTIL_CFG_TAG_AP_MAC_ADDRESS "gAPMacAddr="
42 #define WFC_UTIL_CFG_TAG_END_OF_LINE    "\n"
43 #define WFC_UTIL_CFG_LENGHT_MAC         (6)
44 #define WFC_UTIL_CFG_LENGHT_MAC_STRING  (WFC_UTIL_CFG_LENGHT_MAC*2)
45 
46 /*
47  * persist/WCNSS_qcom_wlan_nv.bin
48  *
49  * typedef PACKED_PRE struct PACKED_POST
50  * {
51  *     //always ensure fields are aligned to 32-bit boundaries
52  *     tANI_U16  productId;
53  *     tANI_U8   productBands;
54  *     tANI_U8   wlanNvRevId;
55  *
56  *     tANI_U8   numOfTxChains;
57  *     tANI_U8   numOfRxChains;
58  *     tANI_U8   macAddr[NV_FIELD_MAC_ADDR_SIZE];
59  *     tANI_U8   mfgSN[NV_FIELD_MFG_SN_SIZE];
60  * } sNvFields;
61  */
62 #define WFC_UTIL_NV_BIN_HEADER_LENGTH    (4)
63 #define WFC_UTIL_NV_BIN_POS_PRODUCT_ID   (WFC_UTIL_NV_BIN_HEADER_LENGTH + 0)
64 #define WFC_UTIL_NV_BIN_POS_PRODUCT_BAND (WFC_UTIL_NV_BIN_HEADER_LENGTH + 2)
65 #define WFC_UTIL_NV_BIN_POS_MAC_ADDR     (WFC_UTIL_NV_BIN_HEADER_LENGTH + 6)
66 
main(int argc,char ** argv)67 int main(int argc, char **argv)
68 {
69 	int ret = 0;
70 	char mac_add_buff[WFC_UTIL_CFG_LENGHT_MAC_STRING+1];
71 	unsigned char mac_add_buff_2[WFC_UTIL_CFG_LENGHT_MAC] = {0x88, 0xcd, 0xba, 0x0c, 0x90, 0x00};
72 	unsigned char mac_add_buff_3[WFC_UTIL_CFG_LENGHT_MAC] = {0x00, 0x90, 0x0c, 0xba, 0xcd, 0x88};
73 
74 	printf("wfc_util_main is started\n");
75 
76 	if(0 < wfc_util_fget_string(WFC_UTIL_CFG_FILE_NAME,
77 	                            WFC_UTIL_CFG_TAG_END_OF_CFG,
78 	                            WFC_UTIL_CFG_TAG_MAC_ADDRESS,
79 	                            WFC_UTIL_CFG_TAG_END_OF_LINE,
80 	                            mac_add_buff,
81 	                            WFC_UTIL_CFG_LENGHT_MAC_STRING+1)) {
82 		printf("wfc_util_main : %s%s\n", WFC_UTIL_CFG_TAG_MAC_ADDRESS, mac_add_buff);
83 	} else {
84 		printf("wfc_util_main : %s is not found\n", WFC_UTIL_CFG_TAG_MAC_ADDRESS);
85 	}
86 
87 	wfc_util_fset_string(WFC_UTIL_CFG_FILE_NAME,
88 	                     WFC_UTIL_CFG_TAG_END_OF_CFG,
89 	                     WFC_UTIL_CFG_TAG_AP_MAC_ADDRESS,
90 	                     WFC_UTIL_CFG_TAG_END_OF_LINE,
91 	                     "00900cbacd88");
92 
93 	wfc_util_fset_string(WFC_UTIL_CFG_FILE_NAME,
94 	                     WFC_UTIL_CFG_TAG_END_OF_CFG,
95 	                     WFC_UTIL_CFG_TAG_MAC_ADDRESS,
96 	                     WFC_UTIL_CFG_TAG_END_OF_LINE,
97 	                     "00900cbacd88");
98 
99 	if(0 < wfc_util_fget_string(WFC_UTIL_CFG_FILE_NAME,
100 	                            WFC_UTIL_CFG_TAG_END_OF_CFG,
101 	                            WFC_UTIL_CFG_TAG_MAC_ADDRESS,
102 	                            WFC_UTIL_CFG_TAG_END_OF_LINE,
103 	                            mac_add_buff,
104 	                            WFC_UTIL_CFG_LENGHT_MAC_STRING+1)) {
105 		printf("wfc_util_main : %s%s\n", WFC_UTIL_CFG_TAG_MAC_ADDRESS, mac_add_buff);
106 
107 		wfc_util_atoh(mac_add_buff, strlen(mac_add_buff), mac_add_buff_2, WFC_UTIL_CFG_LENGHT_MAC);
108 		printf("wfc_util_main : %s%02x:%02x:%02x:%02x:%02x:%02x\n",
109 		                        WFC_UTIL_CFG_TAG_MAC_ADDRESS,
110 		                        mac_add_buff_2[0], mac_add_buff_2[1], mac_add_buff_2[2],
111 		                        mac_add_buff_2[3], mac_add_buff_2[4], mac_add_buff_2[5]);
112 
113 		wfc_util_htoa(mac_add_buff_2, WFC_UTIL_CFG_LENGHT_MAC, mac_add_buff, WFC_UTIL_CFG_LENGHT_MAC_STRING);
114 		printf("wfc_util_main : %s%s\n", WFC_UTIL_CFG_TAG_MAC_ADDRESS, mac_add_buff);
115 
116 	} else {
117 		printf("wfc_util_main : %s is not found\n", WFC_UTIL_CFG_TAG_MAC_ADDRESS);
118 	}
119 
120 	wfc_util_fset_buffer(WFC_UTIL_NV_BIN_FILE_NAME,
121 	                     WFC_UTIL_NV_BIN_POS_MAC_ADDR,
122 	                     mac_add_buff_3,
123 	                     WFC_UTIL_CFG_LENGHT_MAC);
124 
125 	if(0 < wfc_util_fget_buffer(WFC_UTIL_NV_BIN_FILE_NAME,
126 	                            WFC_UTIL_NV_BIN_POS_MAC_ADDR,
127 	                            6,
128 	                            mac_add_buff_2,
129 	                            WFC_UTIL_CFG_LENGHT_MAC)) {
130 		printf("wfc_util_main : wfc_util_fget_buffer[%02x:%02x:%02x:%02x:%02x:%02x]\n",
131 		                        mac_add_buff_2[0], mac_add_buff_2[1], mac_add_buff_2[2],
132 		                        mac_add_buff_2[3], mac_add_buff_2[4], mac_add_buff_2[5]);
133 	} else {
134 		printf("wfc_util_main : %s is not found\n", WFC_UTIL_CFG_TAG_MAC_ADDRESS);
135 	}
136 
137 	return ret;
138 }
139 
140