summaryrefslogtreecommitdiff
path: root/conn_init/wfc_util_main.c
blob: 01e1c8604b7916d7d7771823376be484cc2dae8d (plain)
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*
 * Copyright 2012 The Android Open Source 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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <getopt.h>
#include "wfc_util_fctrl.h"
#include "wfc_util_common.h"

#ifdef WLAN_CHIP_VERSION_WCNSS
#ifndef WFC_UTIL_CFG_FILE_NAME
#define WFC_UTIL_CFG_FILE_NAME          "./WCNSS_qcom_cfg.ini"
#endif
#ifndef WFC_UTIL_NV_BIN_FILE_NAME
#define WFC_UTIL_NV_BIN_FILE_NAME       "./WCNSS_qcom_wlan_nv.bin"
#endif
#else  /* WLAN_CHIP_VERSION_WCN1314 */
#ifndef WFC_UTIL_CFG_FILE_NAME
#define WFC_UTIL_CFG_FILE_NAME          "./WCN1314_qcom_cfg.ini"
#endif
#ifndef WFC_UTIL_NV_BIN_FILE_NAME
#define WFC_UTIL_NV_BIN_FILE_NAME       "./WCN1314_qcom_wlan_nv.bin"
#endif
#endif /* WLAN_CHIP_VERSION_XXXX */
#define WFC_UTIL_CFG_TAG_END_OF_CFG     "END"
#define WFC_UTIL_CFG_TAG_MAC_ADDRESS    "NetworkAddress="
#define WFC_UTIL_CFG_TAG_AP_MAC_ADDRESS "gAPMacAddr="
#define WFC_UTIL_CFG_TAG_END_OF_LINE    "\n"
#define WFC_UTIL_CFG_LENGHT_MAC         (6)
#define WFC_UTIL_CFG_LENGHT_MAC_STRING  (WFC_UTIL_CFG_LENGHT_MAC*2)

/*
 * persist/WCNSS_qcom_wlan_nv.bin
 *
 * typedef PACKED_PRE struct PACKED_POST
 * {
 *     //always ensure fields are aligned to 32-bit boundaries
 *     tANI_U16  productId;
 *     tANI_U8   productBands;
 *     tANI_U8   wlanNvRevId;
 *
 *     tANI_U8   numOfTxChains;
 *     tANI_U8   numOfRxChains;
 *     tANI_U8   macAddr[NV_FIELD_MAC_ADDR_SIZE];
 *     tANI_U8   mfgSN[NV_FIELD_MFG_SN_SIZE];
 * } sNvFields;
 */
#define WFC_UTIL_NV_BIN_HEADER_LENGTH    (4)
#define WFC_UTIL_NV_BIN_POS_PRODUCT_ID   (WFC_UTIL_NV_BIN_HEADER_LENGTH + 0)
#define WFC_UTIL_NV_BIN_POS_PRODUCT_BAND (WFC_UTIL_NV_BIN_HEADER_LENGTH + 2)
#define WFC_UTIL_NV_BIN_POS_MAC_ADDR     (WFC_UTIL_NV_BIN_HEADER_LENGTH + 6)

int main(int argc, char **argv)
{
	int ret = 0;
	char mac_add_buff[WFC_UTIL_CFG_LENGHT_MAC_STRING+1];
	unsigned char mac_add_buff_2[WFC_UTIL_CFG_LENGHT_MAC] = {0x88, 0xcd, 0xba, 0x0c, 0x90, 0x00};
	unsigned char mac_add_buff_3[WFC_UTIL_CFG_LENGHT_MAC] = {0x00, 0x90, 0x0c, 0xba, 0xcd, 0x88};

	printf("wfc_util_main is started\n");

	if(0 < wfc_util_fget_string(WFC_UTIL_CFG_FILE_NAME,
	                            WFC_UTIL_CFG_TAG_END_OF_CFG,
	                            WFC_UTIL_CFG_TAG_MAC_ADDRESS,
	                            WFC_UTIL_CFG_TAG_END_OF_LINE,
	                            mac_add_buff,
	                            WFC_UTIL_CFG_LENGHT_MAC_STRING+1)) {
		printf("wfc_util_main : %s%s\n", WFC_UTIL_CFG_TAG_MAC_ADDRESS, mac_add_buff);
	} else {
		printf("wfc_util_main : %s is not found\n", WFC_UTIL_CFG_TAG_MAC_ADDRESS);
	}

	wfc_util_fset_string(WFC_UTIL_CFG_FILE_NAME,
	                     WFC_UTIL_CFG_TAG_END_OF_CFG,
	                     WFC_UTIL_CFG_TAG_AP_MAC_ADDRESS,
	                     WFC_UTIL_CFG_TAG_END_OF_LINE,
	                     "00900cbacd88");

	wfc_util_fset_string(WFC_UTIL_CFG_FILE_NAME,
	                     WFC_UTIL_CFG_TAG_END_OF_CFG,
	                     WFC_UTIL_CFG_TAG_MAC_ADDRESS,
	                     WFC_UTIL_CFG_TAG_END_OF_LINE,
	                     "00900cbacd88");

	if(0 < wfc_util_fget_string(WFC_UTIL_CFG_FILE_NAME,
	                            WFC_UTIL_CFG_TAG_END_OF_CFG,
	                            WFC_UTIL_CFG_TAG_MAC_ADDRESS,
	                            WFC_UTIL_CFG_TAG_END_OF_LINE,
	                            mac_add_buff,
	                            WFC_UTIL_CFG_LENGHT_MAC_STRING+1)) {
		printf("wfc_util_main : %s%s\n", WFC_UTIL_CFG_TAG_MAC_ADDRESS, mac_add_buff);

		wfc_util_atoh(mac_add_buff, strlen(mac_add_buff), mac_add_buff_2, WFC_UTIL_CFG_LENGHT_MAC);
		printf("wfc_util_main : %s%02x:%02x:%02x:%02x:%02x:%02x\n",
		                        WFC_UTIL_CFG_TAG_MAC_ADDRESS,
		                        mac_add_buff_2[0], mac_add_buff_2[1], mac_add_buff_2[2],
		                        mac_add_buff_2[3], mac_add_buff_2[4], mac_add_buff_2[5]);

		wfc_util_htoa(mac_add_buff_2, WFC_UTIL_CFG_LENGHT_MAC, mac_add_buff, WFC_UTIL_CFG_LENGHT_MAC_STRING);
		printf("wfc_util_main : %s%s\n", WFC_UTIL_CFG_TAG_MAC_ADDRESS, mac_add_buff);

	} else {
		printf("wfc_util_main : %s is not found\n", WFC_UTIL_CFG_TAG_MAC_ADDRESS);
	}

	wfc_util_fset_buffer(WFC_UTIL_NV_BIN_FILE_NAME,
	                     WFC_UTIL_NV_BIN_POS_MAC_ADDR,
	                     mac_add_buff_3,
	                     WFC_UTIL_CFG_LENGHT_MAC);

	if(0 < wfc_util_fget_buffer(WFC_UTIL_NV_BIN_FILE_NAME,
	                            WFC_UTIL_NV_BIN_POS_MAC_ADDR,
	                            6,
	                            mac_add_buff_2,
	                            WFC_UTIL_CFG_LENGHT_MAC)) {
		printf("wfc_util_main : wfc_util_fget_buffer[%02x:%02x:%02x:%02x:%02x:%02x]\n",
		                        mac_add_buff_2[0], mac_add_buff_2[1], mac_add_buff_2[2],
		                        mac_add_buff_2[3], mac_add_buff_2[4], mac_add_buff_2[5]);
	} else {
		printf("wfc_util_main : %s is not found\n", WFC_UTIL_CFG_TAG_MAC_ADDRESS);
	}

	return ret;
}