cal2p54: Update to new RSSI info
[openwrt/svn-archive/archive.git] / utils / calvaria / files / src / cal2p54.c
1 /*
2 * cal2p54 - CAL to p54spi EEPROM converter
3 *
4 * Copyright (c) 2011 Michael Buesch <mb@bu3sch.de>
5 *
6 * Licensed under the GNU General Public License version 2.
7 */
8
9 #include <stdlib.h>
10 #include <stdio.h>
11 #include <string.h>
12 #include <errno.h>
13 #include <stdint.h>
14 #include <unistd.h>
15 #include <fcntl.h>
16 #include <sys/mman.h>
17
18
19 /* Template data from Linux p54spi_eeprom.h:
20 *
21 * Copyright (C) 2003 Conexant Americas Inc. All Rights Reserved.
22 * Copyright (C) 2004, 2005, 2006 Nokia Corporation
23 * Copyright 2008 Johannes Berg <johannes@sipsolutions.net>
24 * Copyright 2008 Christian Lamparter <chunkeey@web.de>
25 *
26 * based on:
27 * - cx3110x's pda.h from Nokia
28 * - cx3110-transfer.log by Johannes Berg
29 */
30
31 static const uint8_t template_eeprom_pda_wrap[] = {
32 /* struct eeprom_pda_wrap */
33 0x47, 0x4d, 0x55, 0xaa, /* magic */
34 0x00, 0x00, /* pad */
35 0x00, 0x00, /* eeprom_pda_data_wrap length */
36 0x00, 0x00, 0x00, 0x00, /* arm opcode */
37 };
38
39 static const uint8_t template_mac_address[] = {
40 /* bogus MAC address */
41 0x04, 0x00, 0x01, 0x01, /* PDR_MAC_ADDRESS */
42 0x00, 0x02, 0xee, 0xc0, 0xff, 0xee,
43 };
44
45 static const uint8_t template_bootrec_exp_if[] = {
46 /* struct bootrec_exp_if */
47 0x06, 0x00, 0x01, 0x10, /* PDR_INTERFACE_LIST */
48 0x00, 0x00, /* role */
49 0x0f, 0x00, /* if_id */
50 0x85, 0x00, /* variant = Longbow RF, 2GHz */
51 0x01, 0x00, /* btm_compat */
52 0x1f, 0x00, /* top_compat */
53
54 0x03, 0x00, 0x02, 0x10, /* PDR_HARDWARE_PLATFORM_COMPONENT_ID */
55 0x03, 0x20, 0x00, 0x43,
56 };
57
58 static const uint8_t template_pda_country_list[] = {
59 /* struct pda_country[6] */
60 0x0d, 0x00, 0x07, 0x10, /* PDR_COUNTRY_LIST */
61 0x10, 0x00, 0x00, 0x00,
62 0x20, 0x00, 0x00, 0x00,
63 0x30, 0x00, 0x00, 0x00,
64 0x31, 0x00, 0x00, 0x00,
65 0x32, 0x00, 0x00, 0x00,
66 0x40, 0x00, 0x00, 0x00,
67 };
68
69 static const uint8_t template_pda_country[] = {
70 /* struct pda_country */
71 0x03, 0x00, 0x08, 0x10, /* PDR_DEFAULT_COUNTRY */
72 0x30, 0x00, 0x00, 0x00, /* ETSI */
73 };
74
75 static const uint8_t template_antenna_gain[] = {
76 0x03, 0x00, 0x00, 0x11, /* PDR_ANTENNA_GAIN */
77 0x08, 0x08, 0x08, 0x08,
78 };
79
80 static const uint8_t template_rssi_linear_approx_custom2[] = {
81 0x0a, 0x00, 0xff, 0xca, /* PDR_RSSI_LINEAR_APPROXIMATION_CUSTOMV2 */
82 0x01, 0x00, 0x0a, 0x00,
83 0x00, 0x00, 0x0a, 0x00,
84 0x85, 0x09, 0x0a, 0x01, 0x72, 0xfe, 0x1a, 0x00, 0x00, 0x00,
85 };
86
87 static const uint8_t template_pa_cal_curve[] = {
88 /* struct pda_custom_wrapper */
89 0x10, 0x06, 0x5d, 0xb0, /* PDR_PRISM_PA_CAL_CURVE_DATA_CUSTOM */
90 0x0d, 0x00, 0xee, 0x00, /* 13 entries, 238 bytes per entry */
91 0x00, 0x00, 0x16, 0x0c, /* no offset, 3094 total len */
92 /* 2412 MHz */
93 0x6c, 0x09,
94 0x10, 0x01, 0x9a, 0x84,
95 0xaa, 0x8a, 0xaa, 0x8a, 0xaa, 0x8a, 0xaa, 0x8a,
96 0x3c, 0xb6, 0x3c, 0xb6, 0x3c, 0xb6, 0x3c, 0xb6,
97 0x3c, 0xb6, 0x3c, 0xb6, 0x3c, 0xb6, 0x3c, 0xb6,
98 0xf0, 0x00, 0x94, 0x6c,
99 0x99, 0x82, 0x99, 0x82, 0x99, 0x82, 0x99, 0x82,
100 0x2b, 0xae, 0x2b, 0xae, 0x2b, 0xae, 0x2b, 0xae,
101 0x2b, 0xae, 0x2b, 0xae, 0x2b, 0xae, 0x2b, 0xae,
102 0xd0, 0x00, 0xaa, 0x5a,
103 0x88, 0x7a, 0x88, 0x7a, 0x88, 0x7a, 0x88, 0x7a,
104 0x1a, 0xa6, 0x1a, 0xa6, 0x1a, 0xa6, 0x1a, 0xa6,
105 0x1a, 0xa6, 0x1a, 0xa6, 0x1a, 0xa6, 0x1a, 0xa6,
106 0xa0, 0x00, 0xf3, 0x47,
107 0x6e, 0x6e, 0x6e, 0x6e, 0x6e, 0x6e, 0x6e, 0x6e,
108 0x00, 0x9a, 0x00, 0x9a, 0x00, 0x9a, 0x00, 0x9a,
109 0x00, 0x9a, 0x00, 0x9a, 0x00, 0x9a, 0x00, 0x9a,
110 0x50, 0x00, 0x59, 0x36,
111 0x43, 0x5a, 0x43, 0x5a, 0x43, 0x5a, 0x43, 0x5a,
112 0xd5, 0x85, 0xd5, 0x85, 0xd5, 0x85, 0xd5, 0x85,
113 0xd5, 0x85, 0xd5, 0x85, 0xd5, 0x85, 0xd5, 0x85,
114 0x00, 0x00, 0xe4, 0x2d,
115 0x18, 0x46, 0x18, 0x46, 0x18, 0x46, 0x18, 0x46,
116 0xaa, 0x71, 0xaa, 0x71, 0xaa, 0x71, 0xaa, 0x71,
117 0xaa, 0x71, 0xaa, 0x71, 0xaa, 0x71, 0xaa, 0x71,
118 0x00, 0x80, 0x00, 0x00,
119 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
120 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
121 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
122 0x00, 0x80, 0x00, 0x00,
123 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
124 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
125 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
126 0x00, 0x00, 0x00, 0x00,
127 0x00, 0x00, 0x00, 0x00, 0x06, 0x80, 0x80, 0x00,
128
129 /* 2417 MHz */
130 0x71, 0x09,
131 0x10, 0x01, 0xb9, 0x83,
132 0x7d, 0x8a, 0x7d, 0x8a, 0x7d, 0x8a, 0x7d, 0x8a,
133 0x0f, 0xb6, 0x0f, 0xb6, 0x0f, 0xb6, 0x0f, 0xb6,
134 0x0f, 0xb6, 0x0f, 0xb6, 0x0f, 0xb6, 0x0f, 0xb6,
135 0xf0, 0x00, 0x2e, 0x6c,
136 0x68, 0x82, 0x68, 0x82, 0x68, 0x82, 0x68, 0x82,
137 0xfa, 0xad, 0xfa, 0xad, 0xfa, 0xad, 0xfa, 0xad,
138 0xfa, 0xad, 0xfa, 0xad, 0xfa, 0xad, 0xfa, 0xad,
139 0xd0, 0x00, 0x8d, 0x5a,
140 0x52, 0x7a, 0x52, 0x7a, 0x52, 0x7a, 0x52, 0x7a,
141 0xe4, 0xa5, 0xe4, 0xa5, 0xe4, 0xa5, 0xe4, 0xa5,
142 0xe4, 0xa5, 0xe4, 0xa5, 0xe4, 0xa5, 0xe4, 0xa5,
143 0xa0, 0x00, 0x0a, 0x48,
144 0x32, 0x6e, 0x32, 0x6e, 0x32, 0x6e, 0x32, 0x6e,
145 0xc4, 0x99, 0xc4, 0x99, 0xc4, 0x99, 0xc4, 0x99,
146 0xc4, 0x99, 0xc4, 0x99, 0xc4, 0x99, 0xc4, 0x99,
147 0x50, 0x00, 0x7c, 0x36,
148 0xfc, 0x59, 0xfc, 0x59, 0xfc, 0x59, 0xfc, 0x59,
149 0x8e, 0x85, 0x8e, 0x85, 0x8e, 0x85, 0x8e, 0x85,
150 0x8e, 0x85, 0x8e, 0x85, 0x8e, 0x85, 0x8e, 0x85,
151 0x00, 0x00, 0xf5, 0x2d,
152 0xc6, 0x45, 0xc6, 0x45, 0xc6, 0x45, 0xc6, 0x45,
153 0x58, 0x71, 0x58, 0x71, 0x58, 0x71, 0x58, 0x71,
154 0x58, 0x71, 0x58, 0x71, 0x58, 0x71, 0x58, 0x71,
155 0x00, 0x80, 0x00, 0x00,
156 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
157 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
158 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
159 0x00, 0x80, 0x00, 0x00,
160 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
161 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
162 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
163 0x00, 0x00, 0x00, 0x00,
164 0x00, 0x00, 0x00, 0x00, 0x06, 0x80, 0x80, 0x00,
165
166 /* 2422 MHz */
167 0x76, 0x09,
168 0x10, 0x01, 0xb9, 0x83,
169 0x7d, 0x8a, 0x7d, 0x8a, 0x7d, 0x8a, 0x7d, 0x8a,
170 0x0f, 0xb6, 0x0f, 0xb6, 0x0f, 0xb6, 0x0f, 0xb6,
171 0x0f, 0xb6, 0x0f, 0xb6, 0x0f, 0xb6, 0x0f, 0xb6,
172 0xf0, 0x00, 0x2e, 0x6c,
173 0x68, 0x82, 0x68, 0x82, 0x68, 0x82, 0x68, 0x82,
174 0xfa, 0xad, 0xfa, 0xad, 0xfa, 0xad, 0xfa, 0xad,
175 0xfa, 0xad, 0xfa, 0xad, 0xfa, 0xad, 0xfa, 0xad,
176 0xd0, 0x00, 0x8d, 0x5a,
177 0x52, 0x7a, 0x52, 0x7a, 0x52, 0x7a, 0x52, 0x7a,
178 0xe4, 0xa5, 0xe4, 0xa5, 0xe4, 0xa5, 0xe4, 0xa5,
179 0xe4, 0xa5, 0xe4, 0xa5, 0xe4, 0xa5, 0xe4, 0xa5,
180 0xa0, 0x00, 0x0a, 0x48,
181 0x32, 0x6e, 0x32, 0x6e, 0x32, 0x6e, 0x32, 0x6e,
182 0xc4, 0x99, 0xc4, 0x99, 0xc4, 0x99, 0xc4, 0x99,
183 0xc4, 0x99, 0xc4, 0x99, 0xc4, 0x99, 0xc4, 0x99,
184 0x50, 0x00, 0x7c, 0x36,
185 0xfc, 0x59, 0xfc, 0x59, 0xfc, 0x59, 0xfc, 0x59,
186 0x8e, 0x85, 0x8e, 0x85, 0x8e, 0x85, 0x8e, 0x85,
187 0x8e, 0x85, 0x8e, 0x85, 0x8e, 0x85, 0x8e, 0x85,
188 0x00, 0x00, 0xf5, 0x2d,
189 0xc6, 0x45, 0xc6, 0x45, 0xc6, 0x45, 0xc6, 0x45,
190 0x58, 0x71, 0x58, 0x71, 0x58, 0x71, 0x58, 0x71,
191 0x58, 0x71, 0x58, 0x71, 0x58, 0x71, 0x58, 0x71,
192 0x00, 0x80, 0x00, 0x00,
193 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
194 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
195 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
196 0x00, 0x80, 0x00, 0x00,
197 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
198 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
199 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
200 0x00, 0x00, 0x00, 0x00,
201 0x00, 0x00, 0x00, 0x00, 0x06, 0x80, 0x80, 0x00,
202
203 /* 2427 MHz */
204 0x7b, 0x09,
205 0x10, 0x01, 0x48, 0x83,
206 0x67, 0x8a, 0x67, 0x8a, 0x67, 0x8a, 0x67, 0x8a,
207 0xf9, 0xb5, 0xf9, 0xb5, 0xf9, 0xb5, 0xf9, 0xb5,
208 0xf9, 0xb5, 0xf9, 0xb5, 0xf9, 0xb5, 0xf9, 0xb5,
209 0xf0, 0x00, 0xfb, 0x6b,
210 0x50, 0x82, 0x50, 0x82, 0x50, 0x82, 0x50, 0x82,
211 0xe2, 0xad, 0xe2, 0xad, 0xe2, 0xad, 0xe2, 0xad,
212 0xe2, 0xad, 0xe2, 0xad, 0xe2, 0xad, 0xe2, 0xad,
213 0xd0, 0x00, 0x7e, 0x5a,
214 0x38, 0x7a, 0x38, 0x7a, 0x38, 0x7a, 0x38, 0x7a,
215 0xca, 0xa5, 0xca, 0xa5, 0xca, 0xa5, 0xca, 0xa5,
216 0xca, 0xa5, 0xca, 0xa5, 0xca, 0xa5, 0xca, 0xa5,
217 0xa0, 0x00, 0x15, 0x48,
218 0x14, 0x6e, 0x14, 0x6e, 0x14, 0x6e, 0x14, 0x6e,
219 0xa6, 0x99, 0xa6, 0x99, 0xa6, 0x99, 0xa6, 0x99,
220 0xa6, 0x99, 0xa6, 0x99, 0xa6, 0x99, 0xa6, 0x99,
221 0x50, 0x00, 0x8e, 0x36,
222 0xd9, 0x59, 0xd9, 0x59, 0xd9, 0x59, 0xd9, 0x59,
223 0x6b, 0x85, 0x6b, 0x85, 0x6b, 0x85, 0x6b, 0x85,
224 0x6b, 0x85, 0x6b, 0x85, 0x6b, 0x85, 0x6b, 0x85,
225 0x00, 0x00, 0xfe, 0x2d,
226 0x9d, 0x45, 0x9d, 0x45, 0x9d, 0x45, 0x9d, 0x45,
227 0x2f, 0x71, 0x2f, 0x71, 0x2f, 0x71, 0x2f, 0x71,
228 0x2f, 0x71, 0x2f, 0x71, 0x2f, 0x71, 0x2f, 0x71,
229 0x00, 0x80, 0x00, 0x00,
230 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
231 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
232 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
233 0x00, 0x80, 0x00, 0x00,
234 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
235 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
236 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
237 0x00, 0x00, 0x00, 0x00,
238 0x00, 0x00, 0x00, 0x00, 0x06, 0x80, 0x80, 0x00,
239
240 /* 2432 MHz */
241 0x80, 0x09,
242 0x10, 0x01, 0xd7, 0x82,
243 0x51, 0x8a, 0x51, 0x8a, 0x51, 0x8a, 0x51, 0x8a,
244 0xe3, 0xb5, 0xe3, 0xb5, 0xe3, 0xb5, 0xe3, 0xb5,
245 0xe3, 0xb5, 0xe3, 0xb5, 0xe3, 0xb5, 0xe3, 0xb5,
246 0xf0, 0x00, 0xc8, 0x6b,
247 0x37, 0x82, 0x37, 0x82, 0x37, 0x82, 0x37, 0x82,
248 0xc9, 0xad, 0xc9, 0xad, 0xc9, 0xad, 0xc9, 0xad,
249 0xc9, 0xad, 0xc9, 0xad, 0xc9, 0xad, 0xc9, 0xad,
250 0xd0, 0x00, 0x6f, 0x5a,
251 0x1d, 0x7a, 0x1d, 0x7a, 0x1d, 0x7a, 0x1d, 0x7a,
252 0xaf, 0xa5, 0xaf, 0xa5, 0xaf, 0xa5, 0xaf, 0xa5,
253 0xaf, 0xa5, 0xaf, 0xa5, 0xaf, 0xa5, 0xaf, 0xa5,
254 0xa0, 0x00, 0x20, 0x48,
255 0xf6, 0x6d, 0xf6, 0x6d, 0xf6, 0x6d, 0xf6, 0x6d,
256 0x88, 0x99, 0x88, 0x99, 0x88, 0x99, 0x88, 0x99,
257 0x88, 0x99, 0x88, 0x99, 0x88, 0x99, 0x88, 0x99,
258 0x50, 0x00, 0x9f, 0x36,
259 0xb5, 0x59, 0xb5, 0x59, 0xb5, 0x59, 0xb5, 0x59,
260 0x47, 0x85, 0x47, 0x85, 0x47, 0x85, 0x47, 0x85,
261 0x47, 0x85, 0x47, 0x85, 0x47, 0x85, 0x47, 0x85,
262 0x00, 0x00, 0x06, 0x2e,
263 0x74, 0x45, 0x74, 0x45, 0x74, 0x45, 0x74, 0x45,
264 0x06, 0x71, 0x06, 0x71, 0x06, 0x71, 0x06, 0x71,
265 0x06, 0x71, 0x06, 0x71, 0x06, 0x71, 0x06, 0x71,
266 0x00, 0x80, 0x00, 0x00,
267 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
268 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
269 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
270 0x00, 0x80, 0x00, 0x00,
271 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
272 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
273 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
274 0x00, 0x00, 0x00, 0x00,
275 0x00, 0x00, 0x00, 0x00, 0x06, 0x80, 0x80, 0x00,
276
277 /* 2437 MHz */
278 0x85, 0x09,
279 0x10, 0x01, 0x67, 0x82,
280 0x3a, 0x8a, 0x3a, 0x8a, 0x3a, 0x8a, 0x3a, 0x8a,
281 0xcc, 0xb5, 0xcc, 0xb5, 0xcc, 0xb5, 0xcc, 0xb5,
282 0xcc, 0xb5, 0xcc, 0xb5, 0xcc, 0xb5, 0xcc, 0xb5,
283 0xf0, 0x00, 0x95, 0x6b,
284 0x1f, 0x82, 0x1f, 0x82, 0x1f, 0x82, 0x1f, 0x82,
285 0xb1, 0xad, 0xb1, 0xad, 0xb1, 0xad, 0xb1, 0xad,
286 0xb1, 0xad, 0xb1, 0xad, 0xb1, 0xad, 0xb1, 0xad,
287 0xd0, 0x00, 0x61, 0x5a,
288 0x02, 0x7a, 0x02, 0x7a, 0x02, 0x7a, 0x02, 0x7a,
289 0x94, 0xa5, 0x94, 0xa5, 0x94, 0xa5, 0x94, 0xa5,
290 0x94, 0xa5, 0x94, 0xa5, 0x94, 0xa5, 0x94, 0xa5,
291 0xa0, 0x00, 0x2c, 0x48,
292 0xd8, 0x6d, 0xd8, 0x6d, 0xd8, 0x6d, 0xd8, 0x6d,
293 0x6a, 0x99, 0x6a, 0x99, 0x6a, 0x99, 0x6a, 0x99,
294 0x6a, 0x99, 0x6a, 0x99, 0x6a, 0x99, 0x6a, 0x99,
295 0x50, 0x00, 0xb1, 0x36,
296 0x92, 0x59, 0x92, 0x59, 0x92, 0x59, 0x92, 0x59,
297 0x24, 0x85, 0x24, 0x85, 0x24, 0x85, 0x24, 0x85,
298 0x24, 0x85, 0x24, 0x85, 0x24, 0x85, 0x24, 0x85,
299 0x00, 0x00, 0x0f, 0x2e,
300 0x4b, 0x45, 0x4b, 0x45, 0x4b, 0x45, 0x4b, 0x45,
301 0xdd, 0x70, 0xdd, 0x70, 0xdd, 0x70, 0xdd, 0x70,
302 0xdd, 0x70, 0xdd, 0x70, 0xdd, 0x70, 0xdd, 0x70,
303 0x00, 0x80, 0x00, 0x00,
304 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
305 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
306 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
307 0x00, 0x80, 0x00, 0x00,
308 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
309 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
310 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
311 0x00, 0x00, 0x00, 0x00,
312 0x00, 0x00, 0x00, 0x00, 0x06, 0x80, 0x80, 0x00,
313
314 /* 2442 MHz */
315 0x8a, 0x09,
316 0x10, 0x01, 0xf6, 0x81,
317 0x24, 0x8a, 0x24, 0x8a, 0x24, 0x8a, 0x24, 0x8a,
318 0xb6, 0xb5, 0xb6, 0xb5, 0xb6, 0xb5, 0xb6, 0xb5,
319 0xb6, 0xb5, 0xb6, 0xb5, 0xb6, 0xb5, 0xb6, 0xb5,
320 0xf0, 0x00, 0x62, 0x6b,
321 0x06, 0x82, 0x06, 0x82, 0x06, 0x82, 0x06, 0x82,
322 0x98, 0xad, 0x98, 0xad, 0x98, 0xad, 0x98, 0xad,
323 0x98, 0xad, 0x98, 0xad, 0x98, 0xad, 0x98, 0xad,
324 0xd0, 0x00, 0x52, 0x5a,
325 0xe7, 0x79, 0xe7, 0x79, 0xe7, 0x79, 0xe7, 0x79,
326 0x79, 0xa5, 0x79, 0xa5, 0x79, 0xa5, 0x79, 0xa5,
327 0x79, 0xa5, 0x79, 0xa5, 0x79, 0xa5, 0x79, 0xa5,
328 0xa0, 0x00, 0x37, 0x48,
329 0xba, 0x6d, 0xba, 0x6d, 0xba, 0x6d, 0xba, 0x6d,
330 0x4c, 0x99, 0x4c, 0x99, 0x4c, 0x99, 0x4c, 0x99,
331 0x4c, 0x99, 0x4c, 0x99, 0x4c, 0x99, 0x4c, 0x99,
332 0x50, 0x00, 0xc2, 0x36,
333 0x6e, 0x59, 0x6e, 0x59, 0x6e, 0x59, 0x6e, 0x59,
334 0x00, 0x85, 0x00, 0x85, 0x00, 0x85, 0x00, 0x85,
335 0x00, 0x85, 0x00, 0x85, 0x00, 0x85, 0x00, 0x85,
336 0x00, 0x00, 0x17, 0x2e,
337 0x22, 0x45, 0x22, 0x45, 0x22, 0x45, 0x22, 0x45,
338 0xb4, 0x70, 0xb4, 0x70, 0xb4, 0x70, 0xb4, 0x70,
339 0xb4, 0x70, 0xb4, 0x70, 0xb4, 0x70, 0xb4, 0x70,
340 0x00, 0x80, 0x00, 0x00,
341 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
342 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
343 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
344 0x00, 0x80, 0x00, 0x00,
345 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
346 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
347 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
348 0x00, 0x00, 0x00, 0x00,
349 0x00, 0x00, 0x00, 0x00, 0x06, 0x80, 0x80, 0x00,
350
351 /* 2447 MHz */
352 0x8f, 0x09,
353 0x10, 0x01, 0x75, 0x83,
354 0x61, 0x8a, 0x61, 0x8a, 0x61, 0x8a, 0x61, 0x8a,
355 0xf3, 0xb5, 0xf3, 0xb5, 0xf3, 0xb5, 0xf3, 0xb5,
356 0xf3, 0xb5, 0xf3, 0xb5, 0xf3, 0xb5, 0xf3, 0xb5,
357 0xf0, 0x00, 0x4b, 0x6c,
358 0x3f, 0x82, 0x3f, 0x82, 0x3f, 0x82, 0x3f, 0x82,
359 0xd1, 0xad, 0xd1, 0xad, 0xd1, 0xad, 0xd1, 0xad,
360 0xd1, 0xad, 0xd1, 0xad, 0xd1, 0xad, 0xd1, 0xad,
361 0xd0, 0x00, 0xda, 0x5a,
362 0x1c, 0x7a, 0x1c, 0x7a, 0x1c, 0x7a, 0x1c, 0x7a,
363 0xae, 0xa5, 0xae, 0xa5, 0xae, 0xa5, 0xae, 0xa5,
364 0xae, 0xa5, 0xae, 0xa5, 0xae, 0xa5, 0xae, 0xa5,
365 0xa0, 0x00, 0x6d, 0x48,
366 0xe9, 0x6d, 0xe9, 0x6d, 0xe9, 0x6d, 0xe9, 0x6d,
367 0x7b, 0x99, 0x7b, 0x99, 0x7b, 0x99, 0x7b, 0x99,
368 0x7b, 0x99, 0x7b, 0x99, 0x7b, 0x99, 0x7b, 0x99,
369 0x50, 0x00, 0xc6, 0x36,
370 0x92, 0x59, 0x92, 0x59, 0x92, 0x59, 0x92, 0x59,
371 0x24, 0x85, 0x24, 0x85, 0x24, 0x85, 0x24, 0x85,
372 0x24, 0x85, 0x24, 0x85, 0x24, 0x85, 0x24, 0x85,
373 0x00, 0x00, 0x15, 0x2e,
374 0x3c, 0x45, 0x3c, 0x45, 0x3c, 0x45, 0x3c, 0x45,
375 0xce, 0x70, 0xce, 0x70, 0xce, 0x70, 0xce, 0x70,
376 0xce, 0x70, 0xce, 0x70, 0xce, 0x70, 0xce, 0x70,
377 0x00, 0x80, 0x00, 0x00,
378 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
379 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
380 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
381 0x00, 0x80, 0x00, 0x00,
382 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
383 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
384 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
385 0x00, 0x00, 0x00, 0x00,
386 0x00, 0x00, 0x00, 0x00, 0x06, 0x80, 0x80, 0x00,
387
388 /* 2452 MHz */
389 0x94, 0x09,
390 0x10, 0x01, 0xf4, 0x84,
391 0x9e, 0x8a, 0x9e, 0x8a, 0x9e, 0x8a, 0x9e, 0x8a,
392 0x30, 0xb6, 0x30, 0xb6, 0x30, 0xb6, 0x30, 0xb6,
393 0x30, 0xb6, 0x30, 0xb6, 0x30, 0xb6, 0x30, 0xb6,
394 0xf0, 0x00, 0x34, 0x6d,
395 0x77, 0x82, 0x77, 0x82, 0x77, 0x82, 0x77, 0x82,
396 0x09, 0xae, 0x09, 0xae, 0x09, 0xae, 0x09, 0xae,
397 0x09, 0xae, 0x09, 0xae, 0x09, 0xae, 0x09, 0xae,
398 0xd0, 0x00, 0x62, 0x5b,
399 0x50, 0x7a, 0x50, 0x7a, 0x50, 0x7a, 0x50, 0x7a,
400 0xe2, 0xa5, 0xe2, 0xa5, 0xe2, 0xa5, 0xe2, 0xa5,
401 0xe2, 0xa5, 0xe2, 0xa5, 0xe2, 0xa5, 0xe2, 0xa5,
402 0xa0, 0x00, 0xa2, 0x48,
403 0x17, 0x6e, 0x17, 0x6e, 0x17, 0x6e, 0x17, 0x6e,
404 0xa9, 0x99, 0xa9, 0x99, 0xa9, 0x99, 0xa9, 0x99,
405 0xa9, 0x99, 0xa9, 0x99, 0xa9, 0x99, 0xa9, 0x99,
406 0x50, 0x00, 0xc9, 0x36,
407 0xb7, 0x59, 0xb7, 0x59, 0xb7, 0x59, 0xb7, 0x59,
408 0x49, 0x85, 0x49, 0x85, 0x49, 0x85, 0x49, 0x85,
409 0x49, 0x85, 0x49, 0x85, 0x49, 0x85, 0x49, 0x85,
410 0x00, 0x00, 0x12, 0x2e,
411 0x57, 0x45, 0x57, 0x45, 0x57, 0x45, 0x57, 0x45,
412 0xe9, 0x70, 0xe9, 0x70, 0xe9, 0x70, 0xe9, 0x70,
413 0xe9, 0x70, 0xe9, 0x70, 0xe9, 0x70, 0xe9, 0x70,
414 0x00, 0x80, 0x00, 0x00,
415 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
416 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
417 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
418 0x00, 0x80, 0x00, 0x00,
419 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
420 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
421 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
422 0x00, 0x00, 0x00, 0x00,
423 0x00, 0x00, 0x00, 0x00, 0x06, 0x80, 0x80, 0x00,
424
425 /* 2452 MHz */
426 0x99, 0x09,
427 0x10, 0x01, 0x74, 0x86,
428 0xdb, 0x8a, 0xdb, 0x8a, 0xdb, 0x8a, 0xdb, 0x8a,
429 0x6d, 0xb6, 0x6d, 0xb6, 0x6d, 0xb6, 0x6d, 0xb6,
430 0x6d, 0xb6, 0x6d, 0xb6, 0x6d, 0xb6, 0x6d, 0xb6,
431 0xf0, 0x00, 0x1e, 0x6e,
432 0xb0, 0x82, 0xb0, 0x82, 0xb0, 0x82, 0xb0, 0x82,
433 0x42, 0xae, 0x42, 0xae, 0x42, 0xae, 0x42, 0xae,
434 0x42, 0xae, 0x42, 0xae, 0x42, 0xae, 0x42, 0xae,
435 0xd0, 0x00, 0xeb, 0x5b,
436 0x85, 0x7a, 0x85, 0x7a, 0x85, 0x7a, 0x85, 0x7a,
437 0x17, 0xa6, 0x17, 0xa6, 0x17, 0xa6, 0x17, 0xa6,
438 0x17, 0xa6, 0x17, 0xa6, 0x17, 0xa6, 0x17, 0xa6,
439 0xa0, 0x00, 0xd8, 0x48,
440 0x46, 0x6e, 0x46, 0x6e, 0x46, 0x6e, 0x46, 0x6e,
441 0xd8, 0x99, 0xd8, 0x99, 0xd8, 0x99, 0xd8, 0x99,
442 0xd8, 0x99, 0xd8, 0x99, 0xd8, 0x99, 0xd8, 0x99,
443 0x50, 0x00, 0xcd, 0x36,
444 0xdb, 0x59, 0xdb, 0x59, 0xdb, 0x59, 0xdb, 0x59,
445 0x6d, 0x85, 0x6d, 0x85, 0x6d, 0x85, 0x6d, 0x85,
446 0x6d, 0x85, 0x6d, 0x85, 0x6d, 0x85, 0x6d, 0x85,
447 0x00, 0x00, 0x10, 0x2e,
448 0x71, 0x45, 0x71, 0x45, 0x71, 0x45, 0x71, 0x45,
449 0x03, 0x71, 0x03, 0x71, 0x03, 0x71, 0x03, 0x71,
450 0x03, 0x71, 0x03, 0x71, 0x03, 0x71, 0x03, 0x71,
451 0x00, 0x80, 0x00, 0x00,
452 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
453 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
454 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
455 0x00, 0x80, 0x00, 0x00,
456 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
457 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
458 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
459 0x00, 0x00, 0x00, 0x00,
460 0x00, 0x00, 0x00, 0x00, 0x06, 0x80, 0x80, 0x00,
461
462 /* 2557 MHz */
463 0x9e, 0x09,
464 0x10, 0x01, 0xf3, 0x87,
465 0x17, 0x8b, 0x17, 0x8b, 0x17, 0x8b, 0x17, 0x8b,
466 0xa9, 0xb6, 0xa9, 0xb6, 0xa9, 0xb6, 0xa9, 0xb6,
467 0xa9, 0xb6, 0xa9, 0xb6, 0xa9, 0xb6, 0xa9, 0xb6,
468 0xf0, 0x00, 0x07, 0x6f,
469 0xe9, 0x82, 0xe9, 0x82, 0xe9, 0x82, 0xe9, 0x82,
470 0x7b, 0xae, 0x7b, 0xae, 0x7b, 0xae, 0x7b, 0xae,
471 0x7b, 0xae, 0x7b, 0xae, 0x7b, 0xae, 0x7b, 0xae,
472 0xd0, 0x00, 0x73, 0x5c,
473 0xba, 0x7a, 0xba, 0x7a, 0xba, 0x7a, 0xba, 0x7a,
474 0x4c, 0xa6, 0x4c, 0xa6, 0x4c, 0xa6, 0x4c, 0xa6,
475 0x4c, 0xa6, 0x4c, 0xa6, 0x4c, 0xa6, 0x4c, 0xa6,
476 0xa0, 0x00, 0x0d, 0x49,
477 0x74, 0x6e, 0x74, 0x6e, 0x74, 0x6e, 0x74, 0x6e,
478 0x06, 0x9a, 0x06, 0x9a, 0x06, 0x9a, 0x06, 0x9a,
479 0x06, 0x9a, 0x06, 0x9a, 0x06, 0x9a, 0x06, 0x9a,
480 0x50, 0x00, 0xd1, 0x36,
481 0xff, 0x59, 0xff, 0x59, 0xff, 0x59, 0xff, 0x59,
482 0x91, 0x85, 0x91, 0x85, 0x91, 0x85, 0x91, 0x85,
483 0x91, 0x85, 0x91, 0x85, 0x91, 0x85, 0x91, 0x85,
484 0x00, 0x00, 0x0e, 0x2e,
485 0x8b, 0x45, 0x8b, 0x45, 0x8b, 0x45, 0x8b, 0x45,
486 0x1d, 0x71, 0x1d, 0x71, 0x1d, 0x71, 0x1d, 0x71,
487 0x1d, 0x71, 0x1d, 0x71, 0x1d, 0x71, 0x1d, 0x71,
488 0x00, 0x80, 0x00, 0x00,
489 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
490 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
491 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
492 0x00, 0x80, 0x00, 0x00,
493 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
494 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
495 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
496 0x00, 0x00, 0x00, 0x00,
497 0x00, 0x00, 0x00, 0x00, 0x06, 0x80, 0x80, 0x00,
498
499 /* 2562 MHz */
500 0xa3, 0x09,
501 0x10, 0x01, 0x72, 0x89,
502 0x54, 0x8b, 0x54, 0x8b, 0x54, 0x8b, 0x54, 0x8b,
503 0xe6, 0xb6, 0xe6, 0xb6, 0xe6, 0xb6, 0xe6, 0xb6,
504 0xe6, 0xb6, 0xe6, 0xb6, 0xe6, 0xb6, 0xe6, 0xb6,
505 0xf0, 0x00, 0xf0, 0x6f,
506 0x21, 0x83, 0x21, 0x83, 0x21, 0x83, 0x21, 0x83,
507 0xb3, 0xae, 0xb3, 0xae, 0xb3, 0xae, 0xb3, 0xae,
508 0xb3, 0xae, 0xb3, 0xae, 0xb3, 0xae, 0xb3, 0xae,
509 0xd0, 0x00, 0xfb, 0x5c,
510 0xee, 0x7a, 0xee, 0x7a, 0xee, 0x7a, 0xee, 0x7a,
511 0x80, 0xa6, 0x80, 0xa6, 0x80, 0xa6, 0x80, 0xa6,
512 0x80, 0xa6, 0x80, 0xa6, 0x80, 0xa6, 0x80, 0xa6,
513 0xa0, 0x00, 0x43, 0x49,
514 0xa3, 0x6e, 0xa3, 0x6e, 0xa3, 0x6e, 0xa3, 0x6e,
515 0x35, 0x9a, 0x35, 0x9a, 0x35, 0x9a, 0x35, 0x9a,
516 0x35, 0x9a, 0x35, 0x9a, 0x35, 0x9a, 0x35, 0x9a,
517 0x50, 0x00, 0xd4, 0x36,
518 0x24, 0x5a, 0x24, 0x5a, 0x24, 0x5a, 0x24, 0x5a,
519 0xb6, 0x85, 0xb6, 0x85, 0xb6, 0x85, 0xb6, 0x85,
520 0xb6, 0x85, 0xb6, 0x85, 0xb6, 0x85, 0xb6, 0x85,
521 0x00, 0x00, 0x0b, 0x2e,
522 0xa6, 0x45, 0xa6, 0x45, 0xa6, 0x45, 0xa6, 0x45,
523 0x38, 0x71, 0x38, 0x71, 0x38, 0x71, 0x38, 0x71,
524 0x38, 0x71, 0x38, 0x71, 0x38, 0x71, 0x38, 0x71,
525 0x00, 0x80, 0x00, 0x00,
526 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
527 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
528 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
529 0x00, 0x80, 0x00, 0x00,
530 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
531 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
532 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
533 0x00, 0x00, 0x00, 0x00,
534 0x00, 0x00, 0x00, 0x00, 0x06, 0x80, 0x80, 0x00,
535
536 /* 2572 MHz */
537 0xa8, 0x09,
538 0x10, 0x01, 0xf1, 0x8a,
539 0x91, 0x8b, 0x91, 0x8b, 0x91, 0x8b, 0x91, 0x8b,
540 0x23, 0xb7, 0x23, 0xb7, 0x23, 0xb7, 0x23, 0xb7,
541 0x23, 0xb7, 0x23, 0xb7, 0x23, 0xb7, 0x23, 0xb7,
542 0xf0, 0x00, 0xd9, 0x70,
543 0x5a, 0x83, 0x5a, 0x83, 0x5a, 0x83, 0x5a, 0x83,
544 0xec, 0xae, 0xec, 0xae, 0xec, 0xae, 0xec, 0xae,
545 0xec, 0xae, 0xec, 0xae, 0xec, 0xae, 0xec, 0xae,
546 0xd0, 0x00, 0x83, 0x5d,
547 0x23, 0x7b, 0x23, 0x7b, 0x23, 0x7b, 0x23, 0x7b,
548 0xb5, 0xa6, 0xb5, 0xa6, 0xb5, 0xa6, 0xb5, 0xa6,
549 0xb5, 0xa6, 0xb5, 0xa6, 0xb5, 0xa6, 0xb5, 0xa6,
550 0xa0, 0x00, 0x78, 0x49,
551 0xd1, 0x6e, 0xd1, 0x6e, 0xd1, 0x6e, 0xd1, 0x6e,
552 0x63, 0x9a, 0x63, 0x9a, 0x63, 0x9a, 0x63, 0x9a,
553 0x63, 0x9a, 0x63, 0x9a, 0x63, 0x9a, 0x63, 0x9a,
554 0x50, 0x00, 0xd8, 0x36,
555 0x48, 0x5a, 0x48, 0x5a, 0x48, 0x5a, 0x48, 0x5a,
556 0xda, 0x85, 0xda, 0x85, 0xda, 0x85, 0xda, 0x85,
557 0xda, 0x85, 0xda, 0x85, 0xda, 0x85, 0xda, 0x85,
558 0x00, 0x00, 0x09, 0x2e,
559 0xc0, 0x45, 0xc0, 0x45, 0xc0, 0x45, 0xc0, 0x45,
560 0x52, 0x71, 0x52, 0x71, 0x52, 0x71, 0x52, 0x71,
561 0x52, 0x71, 0x52, 0x71, 0x52, 0x71, 0x52, 0x71,
562 0x00, 0x80, 0x00, 0x00,
563 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
564 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
565 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
566 0x00, 0x80, 0x00, 0x00,
567 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
568 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
569 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
570 0x00, 0x00, 0x00, 0x00,
571 0x00, 0x00, 0x00, 0x00, 0x06, 0x80, 0x80, 0x00,
572 };
573
574 /*
575 * Not really sure if this is actually the power_limit database,
576 * it looks a bit "related" to PDR_PRISM_ZIF_TX_IQ_CALIBRATION
577 */
578 static const uint8_t template_pa_cal_output_power_limits[] = {
579 /* struct pda_custom_wrapper */
580 0xae, 0x00, 0xef, 0xbe, /* PDR_PRISM_PA_CAL_OUTPUT_POWER_LIMITS_CUSTOM */
581 0x0d, 0x00, 0x1a, 0x00, /* 13 entries, 26 bytes per entry */
582 0x00, 0x00, 0x52, 0x01, /* no offset, 338 bytes total */
583
584 /* 2412 MHz */
585 0x6c, 0x09,
586 0x10, 0x01, 0x10, 0x01, 0x10, 0x01, 0x10, 0x01,
587 0xe0, 0x00, 0xe0, 0x00, 0xe0, 0x00, 0xe0, 0x00,
588 0xd0, 0x00, 0xd0, 0x00, 0xd0, 0x00, 0xd0, 0x00,
589
590 /* 2417 MHz */
591 0x71, 0x09,
592 0x10, 0x01, 0x10, 0x01, 0x10, 0x01, 0x10, 0x01,
593 0xf0, 0x00, 0xf0, 0x00, 0xf0, 0x00, 0xf0, 0x00,
594 0xd0, 0x00, 0xd0, 0x00, 0xd0, 0x00, 0xd0, 0x00,
595
596 /* 2422 MHz */
597 0x76, 0x09,
598 0x10, 0x01, 0x10, 0x01, 0x10, 0x01, 0x10, 0x01,
599 0xf0, 0x00, 0xf0, 0x00, 0xf0, 0x00, 0xf0, 0x00,
600 0xd0, 0x00, 0xd0, 0x00, 0xd0, 0x00, 0xd0, 0x00,
601
602 /* 2427 MHz */
603 0x7b, 0x09,
604 0x10, 0x01, 0x10, 0x01, 0x10, 0x01, 0x10, 0x01,
605 0xf0, 0x00, 0xf0, 0x00, 0xf0, 0x00, 0xf0, 0x00,
606 0xd0, 0x00, 0xd0, 0x00, 0xd0, 0x00, 0xd0, 0x00,
607
608 /* 2432 MHz */
609 0x80, 0x09,
610 0x10, 0x01, 0x10, 0x01, 0x10, 0x01, 0x10, 0x01,
611 0xf0, 0x00, 0xf0, 0x00, 0xf0, 0x00, 0xf0, 0x00,
612 0xd0, 0x00, 0xd0, 0x00, 0xd0, 0x00, 0xd0, 0x00,
613
614 /* 2437 MHz */
615 0x85, 0x09,
616 0x10, 0x01, 0x10, 0x01, 0x10, 0x01, 0x10, 0x01,
617 0xf0, 0x00, 0xf0, 0x00, 0xf0, 0x00, 0xf0, 0x00,
618 0xd0, 0x00, 0xd0, 0x00, 0xd0, 0x00, 0xd0, 0x00,
619
620 /* 2442 MHz */
621 0x8a, 0x09,
622 0x10, 0x01, 0x10, 0x01, 0x10, 0x01, 0x10, 0x01,
623 0xf0, 0x00, 0xf0, 0x00, 0xf0, 0x00, 0xf0, 0x00,
624 0xd0, 0x00, 0xd0, 0x00, 0xd0, 0x00, 0xd0, 0x00,
625
626 /* 2447 MHz */
627 0x8f, 0x09,
628 0x10, 0x01, 0x10, 0x01, 0x10, 0x01, 0x10, 0x01,
629 0xf0, 0x00, 0xf0, 0x00, 0xf0, 0x00, 0xf0, 0x00,
630 0xd0, 0x00, 0xd0, 0x00, 0xd0, 0x00, 0xd0, 0x00,
631
632 /* 2452 MHz */
633 0x94, 0x09,
634 0x10, 0x01, 0x10, 0x01, 0x10, 0x01, 0x10, 0x01,
635 0xf0, 0x00, 0xf0, 0x00, 0xf0, 0x00, 0xf0, 0x00,
636 0xd0, 0x00, 0xd0, 0x00, 0xd0, 0x00, 0xd0, 0x00,
637
638 /* 2457 MHz */
639 0x99, 0x09,
640 0x10, 0x01, 0x10, 0x01, 0x10, 0x01, 0x10, 0x01,
641 0xf0, 0x00, 0xf0, 0x00, 0xf0, 0x00, 0xf0, 0x00,
642 0xd0, 0x00, 0xd0, 0x00, 0xd0, 0x00, 0xd0, 0x00,
643
644 /* 2462 MHz */
645 0x9e, 0x09,
646 0x10, 0x01, 0x10, 0x01, 0x10, 0x01, 0x10, 0x01,
647 0xf0, 0x00, 0xf0, 0x00, 0xf0, 0x00, 0xf0, 0x00,
648 0xd0, 0x00, 0xd0, 0x00, 0xd0, 0x00, 0xd0, 0x00,
649
650 /* 2467 MHz */
651 0xa3, 0x09,
652 0x10, 0x01, 0x10, 0x01, 0x10, 0x01, 0x10, 0x01,
653 0xf0, 0x00, 0xf0, 0x00, 0xf0, 0x00, 0xf0, 0x00,
654 0xd0, 0x00, 0xd0, 0x00, 0xd0, 0x00, 0xd0, 0x00,
655
656 /* 2472 MHz */
657 0xa8, 0x09,
658 0x10, 0x01, 0x10, 0x01, 0x10, 0x01, 0x10, 0x01,
659 0xf0, 0x00, 0xf0, 0x00, 0xf0, 0x00, 0xf0, 0x00,
660 0xd0, 0x00, 0xd0, 0x00, 0xd0, 0x00, 0xd0, 0x00,
661 };
662
663 static const uint8_t template_pda_iq_autocal[] = {
664 /* struct pda_iq_autocal_entry[13] */
665 0x42, 0x00, 0x06, 0x19, /* PDR_PRISM_ZIF_TX_IQ_CALIBRATION */
666 /* 2412 MHz */
667 0x6c, 0x09, 0x26, 0x00, 0xf8, 0xff, 0xf7, 0xff, 0xff, 0x00,
668 /* 2417 MHz */
669 0x71, 0x09, 0x26, 0x00, 0xf8, 0xff, 0xf7, 0xff, 0xff, 0x00,
670 /* 2422 MHz */
671 0x76, 0x09, 0x26, 0x00, 0xf8, 0xff, 0xf7, 0xff, 0xff, 0x00,
672 /* 2427 MHz */
673 0x7b, 0x09, 0x26, 0x00, 0xf8, 0xff, 0xf7, 0xff, 0xff, 0x00,
674 /* 2432 MHz */
675 0x80, 0x09, 0x25, 0x00, 0xf7, 0xff, 0xf7, 0xff, 0xff, 0x00,
676 /* 2437 MHz */
677 0x85, 0x09, 0x25, 0x00, 0xf7, 0xff, 0xf7, 0xff, 0xff, 0x00,
678 /* 2442 MHz */
679 0x8a, 0x09, 0x25, 0x00, 0xf7, 0xff, 0xf7, 0xff, 0xff, 0x00,
680 /* 2447 MHz */
681 0x8f, 0x09, 0x25, 0x00, 0xf7, 0xff, 0xf7, 0xff, 0xff, 0x00,
682 /* 2452 MHz */
683 0x94, 0x09, 0x25, 0x00, 0xf7, 0xff, 0xf7, 0xff, 0xff, 0x00,
684 /* 2457 MHz */
685 0x99, 0x09, 0x25, 0x00, 0xf5, 0xff, 0xf9, 0xff, 0x00, 0x01,
686 /* 2462 MHz */
687 0x9e, 0x09, 0x25, 0x00, 0xf5, 0xff, 0xf9, 0xff, 0x00, 0x01,
688 /* 2467 MHz */
689 0xa3, 0x09, 0x25, 0x00, 0xf5, 0xff, 0xf9, 0xff, 0x00, 0x01,
690 /* 2472 MHz */
691 0xa8, 0x09, 0x25, 0x00, 0xf5, 0xff, 0xf9, 0xff, 0x00, 0x01,
692 };
693
694 static const uint8_t template_pdr_end[] = {
695 0x02, 0x00, 0x00, 0x00, /* PDR_END */
696 };
697
698 /* linux/lib/crc-ccitt.c
699 *
700 * This mysterious table is just the CRC of each possible byte. It can be
701 * computed using the standard bit-at-a-time methods. The polynomial can
702 * be seen in entry 128, 0x8408. This corresponds to x^0 + x^5 + x^12.
703 * Add the implicit x^16, and you have the standard CRC-CCITT.
704 */
705 static uint16_t const crc_ccitt_table[256] = {
706 0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf,
707 0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7,
708 0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e,
709 0x9cc9, 0x8d40, 0xbfdb, 0xae52, 0xdaed, 0xcb64, 0xf9ff, 0xe876,
710 0x2102, 0x308b, 0x0210, 0x1399, 0x6726, 0x76af, 0x4434, 0x55bd,
711 0xad4a, 0xbcc3, 0x8e58, 0x9fd1, 0xeb6e, 0xfae7, 0xc87c, 0xd9f5,
712 0x3183, 0x200a, 0x1291, 0x0318, 0x77a7, 0x662e, 0x54b5, 0x453c,
713 0xbdcb, 0xac42, 0x9ed9, 0x8f50, 0xfbef, 0xea66, 0xd8fd, 0xc974,
714 0x4204, 0x538d, 0x6116, 0x709f, 0x0420, 0x15a9, 0x2732, 0x36bb,
715 0xce4c, 0xdfc5, 0xed5e, 0xfcd7, 0x8868, 0x99e1, 0xab7a, 0xbaf3,
716 0x5285, 0x430c, 0x7197, 0x601e, 0x14a1, 0x0528, 0x37b3, 0x263a,
717 0xdecd, 0xcf44, 0xfddf, 0xec56, 0x98e9, 0x8960, 0xbbfb, 0xaa72,
718 0x6306, 0x728f, 0x4014, 0x519d, 0x2522, 0x34ab, 0x0630, 0x17b9,
719 0xef4e, 0xfec7, 0xcc5c, 0xddd5, 0xa96a, 0xb8e3, 0x8a78, 0x9bf1,
720 0x7387, 0x620e, 0x5095, 0x411c, 0x35a3, 0x242a, 0x16b1, 0x0738,
721 0xffcf, 0xee46, 0xdcdd, 0xcd54, 0xb9eb, 0xa862, 0x9af9, 0x8b70,
722 0x8408, 0x9581, 0xa71a, 0xb693, 0xc22c, 0xd3a5, 0xe13e, 0xf0b7,
723 0x0840, 0x19c9, 0x2b52, 0x3adb, 0x4e64, 0x5fed, 0x6d76, 0x7cff,
724 0x9489, 0x8500, 0xb79b, 0xa612, 0xd2ad, 0xc324, 0xf1bf, 0xe036,
725 0x18c1, 0x0948, 0x3bd3, 0x2a5a, 0x5ee5, 0x4f6c, 0x7df7, 0x6c7e,
726 0xa50a, 0xb483, 0x8618, 0x9791, 0xe32e, 0xf2a7, 0xc03c, 0xd1b5,
727 0x2942, 0x38cb, 0x0a50, 0x1bd9, 0x6f66, 0x7eef, 0x4c74, 0x5dfd,
728 0xb58b, 0xa402, 0x9699, 0x8710, 0xf3af, 0xe226, 0xd0bd, 0xc134,
729 0x39c3, 0x284a, 0x1ad1, 0x0b58, 0x7fe7, 0x6e6e, 0x5cf5, 0x4d7c,
730 0xc60c, 0xd785, 0xe51e, 0xf497, 0x8028, 0x91a1, 0xa33a, 0xb2b3,
731 0x4a44, 0x5bcd, 0x6956, 0x78df, 0x0c60, 0x1de9, 0x2f72, 0x3efb,
732 0xd68d, 0xc704, 0xf59f, 0xe416, 0x90a9, 0x8120, 0xb3bb, 0xa232,
733 0x5ac5, 0x4b4c, 0x79d7, 0x685e, 0x1ce1, 0x0d68, 0x3ff3, 0x2e7a,
734 0xe70e, 0xf687, 0xc41c, 0xd595, 0xa12a, 0xb0a3, 0x8238, 0x93b1,
735 0x6b46, 0x7acf, 0x4854, 0x59dd, 0x2d62, 0x3ceb, 0x0e70, 0x1ff9,
736 0xf78f, 0xe606, 0xd49d, 0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330,
737 0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0x0f78
738 };
739
740 static inline uint16_t crc_ccitt_byte(uint16_t crc, const uint8_t c)
741 {
742 return (crc >> 8) ^ crc_ccitt_table[(crc ^ c) & 0xff];
743 }
744
745 static uint16_t crc_ccitt(uint16_t crc, uint8_t const *buffer, size_t len)
746 {
747 while (len--)
748 crc = crc_ccitt_byte(crc, *buffer++);
749 return crc;
750 }
751
752 static int generate_pa_cal_curve(uint8_t *buffer,
753 const uint8_t *txgen_image,
754 size_t txgen_image_size)
755 {
756 memcpy(buffer, template_pa_cal_curve, sizeof(template_pa_cal_curve));
757
758 //TODO
759
760 return 0;
761 }
762
763 static int generate_iq_autocal(uint8_t *buffer,
764 const uint8_t *iqalign_image,
765 size_t iqalign_image_size)
766 {
767 unsigned int expected_size;
768 uint8_t *out;
769 const uint8_t *in;
770 unsigned int i;
771
772 expected_size = 13 * 8 + 4;
773 if (iqalign_image_size != expected_size) {
774 fprintf(stderr, "ERROR: Unknown wlan-iq-align image size. "
775 "Got %u, but expected %u\n",
776 (unsigned int)iqalign_image_size, expected_size);
777 return -EINVAL;
778 }
779
780 in = iqalign_image;
781 out = buffer;
782
783 memcpy(out, template_pda_iq_autocal, sizeof(template_pda_iq_autocal));
784
785 in += 4; /* Skip zero padding */
786 out += 4; /* Skip header */
787 for (i = 0; i < 13; i++) {
788 out += 2; /* Skip little endian 16bit Mhz number */
789 memcpy(out, in, 8);
790 out += 8; /* Next element */
791 in += 8; /* Next element */
792 }
793
794 return 0;
795 }
796
797 static int generate_eeprom(FILE *outstream,
798 const uint8_t *txgen_image,
799 size_t txgen_image_size,
800 const uint8_t *iqalign_image,
801 size_t iqalign_image_size)
802 {
803 int err, res = 0;
804 uint16_t crc = ~0;
805 uint8_t crc_buf[2];
806 uint8_t gen_pda_iq_autocal[sizeof(template_pda_iq_autocal)];
807 uint8_t gen_pa_cal_curve[sizeof(template_pa_cal_curve)];
808
809 err = generate_iq_autocal(gen_pda_iq_autocal,
810 iqalign_image, iqalign_image_size);
811 if (err)
812 return err;
813 err = generate_pa_cal_curve(gen_pa_cal_curve,
814 txgen_image, txgen_image_size);
815 if (err)
816 return err;
817
818 #define writebuf(buffer, do_crc) do { \
819 if (do_crc) \
820 crc = crc_ccitt(crc, buffer, sizeof(buffer)); \
821 res = fwrite(buffer, sizeof(buffer), 1, outstream); \
822 if (res != 1) { \
823 fprintf(stderr, "Failed to write output data\n"); \
824 return -EIO; \
825 } \
826 } while (0)
827
828 writebuf(template_eeprom_pda_wrap, 0);
829 writebuf(template_mac_address, 1);
830 writebuf(template_bootrec_exp_if, 1);
831 writebuf(template_pda_country_list, 1);
832 writebuf(template_pda_country, 1);
833 writebuf(template_antenna_gain, 1);
834 writebuf(template_rssi_linear_approx_custom2, 1);
835 writebuf(gen_pa_cal_curve, 1);
836 writebuf(template_pa_cal_output_power_limits, 1);
837 writebuf(gen_pda_iq_autocal, 1);
838 writebuf(template_pdr_end, 1);
839
840 crc = ~crc;
841 crc_buf[0] = crc & 0xFF;
842 crc_buf[1] = (crc >> 8) & 0xFF;
843 res = fwrite(crc_buf, sizeof(crc_buf), 1, outstream);
844 if (res != 1) {
845 fprintf(stderr, "Failed to write CRC\n");
846 return -EIO;
847 }
848
849 return 0;
850 }
851
852 static void * map_file(const char *filepath, int readonly,
853 uint64_t *filelen)
854 {
855 int fd;
856 off_t len;
857 void *data;
858
859 fd = open(filepath, readonly ? O_RDONLY : O_RDWR);
860 if (fd < 0) {
861 fprintf(stderr, "Failed to open file %s: %s\n",
862 filepath, strerror(errno));
863 return NULL;
864 }
865 len = lseek(fd, 0, SEEK_END);
866 if (len < 0 || lseek(fd, 0, SEEK_SET)) {
867 fprintf(stderr, "Failed to calculate file length of %s: %s\n",
868 filepath, strerror(errno));
869 close(fd);
870 return NULL;
871 }
872
873 data = mmap(NULL, len,
874 readonly ? PROT_READ : (PROT_READ | PROT_WRITE),
875 readonly ? MAP_PRIVATE : 0,
876 fd, 0);
877 close(fd);
878 if (data == MAP_FAILED) {
879 fprintf(stderr, "Failed to MMAP file %s: %s\n",
880 filepath, strerror(errno));
881 return NULL;
882 }
883 madvise(data, len, MADV_SEQUENTIAL);
884
885 *filelen = len;
886
887 return data;
888 }
889
890 static void unmap_file(void *mapping, uint64_t len)
891 {
892 if (mapping)
893 munmap(mapping, len);
894 }
895
896 static void usage(FILE *fd)
897 {
898 fprintf(fd, "cal2p54 - CAL to p54spi EEPROM converter\n");
899 fprintf(fd, "\n");
900 fprintf(fd, "Usage: cal2p54 WLAN-TX-GEN2-IMAGE WLAN-IQ-ALIGN-IMAGE\n");
901 }
902
903 int main(int argc, char **argv)
904 {
905 int err, ret = 0;
906 uint8_t *txgen_image = NULL;
907 uint64_t txgen_image_len = 0;
908 uint8_t *iqalign_image = NULL;
909 uint64_t iqalign_image_len = 0;
910
911 const char *txgen_filepath;
912 const char *iqalign_filepath;
913
914 if (argc != 3) {
915 usage(stderr);
916 return 1;
917 }
918 txgen_filepath = argv[1];
919 iqalign_filepath = argv[2];
920
921 txgen_image = map_file(txgen_filepath, 1, &txgen_image_len);
922 iqalign_image = map_file(iqalign_filepath, 1, &iqalign_image_len);
923 if (!txgen_image || !iqalign_image) {
924 ret = 1;
925 goto out;
926 }
927
928 err = generate_eeprom(stdout, txgen_image, txgen_image_len,
929 iqalign_image, iqalign_image_len);
930 if (err) {
931 ret = 1;
932 goto out;
933 }
934
935 out:
936 unmap_file(txgen_image, txgen_image_len);
937 unmap_file(iqalign_image, iqalign_image_len);
938
939 return ret;
940 }