3 * Copyright (c) 2010-2011 Adrian Chadd, Xenion Pty Ltd.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 #include <sys/types.h>
38 #include "ar9300/ar9300eep.h"
41 eeprom_9300_hdr_print(const uint16_t *buf)
43 const ar9300_eeprom_t *ee = (ar9300_eeprom_t *) buf;
45 printf("| Version: %d, Template: %d, MAC: %02x:%02x:%02x:%02x:%02x:%02x |\n",
57 eeprom_9300_base_print(const uint16_t *buf)
59 const ar9300_eeprom_t *ee = (ar9300_eeprom_t *) buf;
60 const OSPREY_BASE_EEP_HEADER *ee_base = &ee->base_eep_header;
62 printf("| RegDomain: 0x%02x 0x%02x TxRxMask: 0x%02x OpFlags: 0x%02x OpMisc: 0x%02x |\n",
66 ee_base->op_cap_flags.op_flags,
67 ee_base->op_cap_flags.eepMisc);
69 printf("| RfSilent: 0x%02x BtOptions: 0x%02x DeviceCap: 0x%02x DeviceType: 0x%02x |\n",
71 ee_base->blue_tooth_options,
73 ee_base->device_type);
75 printf("| pwrTableOffset: %d dB, feature_enable: 0x%02x MiscConfig: 0x%02x |\n",
76 ee_base->pwrTableOffset,
77 ee_base->feature_enable,
78 ee_base->misc_configuration);
80 printf("| EepromWriteGpio: %d, WlanDisableGpio: %d, WlanLedGpio: %d RxBandSelectGpio: %d |\n",
81 ee_base->eeprom_write_enable_gpio,
82 ee_base->wlan_disable_gpio,
83 ee_base->wlan_led_gpio,
84 ee_base->rx_band_select_gpio);
86 printf("| TxRxGain: %d, SwReg: %d |\n",
92 eeprom_9300_modal_print(const OSPREY_MODAL_EEP_HEADER *m)
96 printf("| AntCtrl: 0x%08x AntCtrl2: 0x%08x |\n",
100 for (i = 0; i < OSPREY_MAX_CHAINS; i++) {
101 printf("| Ch %d: AntCtrl: 0x%08x Atten1: %d, atten1_margin: %d, NfThresh: %d |\n",
103 m->ant_ctrl_chain[i],
105 m->xatten1_margin[i],
106 m->noise_floor_thresh_ch[i]);
110 for (i = 0; i < OSPREY_EEPROM_MODAL_SPURS; i++) {
111 printf("(%d: %d) ", i, m->spur_chans[i]);
115 printf("| TempSlope: %d, VoltSlope: %d, QuickDrop: %d, XpaBiasLvl %d |\n",
121 printf("| txFrameToDataStart: %d, TxFrameToPaOn: %d, TxEndToXpaOff: %d, TxEndToRxOn: %d, TxFrameToXpaOn: %d |\n",
122 m->tx_frame_to_data_start,
123 m->tx_frame_to_pa_on,
124 m->tx_end_to_xpa_off,
126 m->tx_frame_to_xpa_on);
128 printf("| txClip: %d, AntGain: %d, SwitchSettling: %d, adcDesiredSize: %d |\n",
134 printf("| Thresh62: %d, PaprdMaskHt20: 0x%08x, PaPrdMaskHt40: 0x%08x |\n",
136 m->paprd_rate_mask_ht20,
137 m->paprd_rate_mask_ht40);
139 printf("| SwitchComSpdt: %02x, XlnaBiasStrength: %d, RfGainCap: %d, TxGainCap: %x\n",
141 m->xLNA_bias_strength,
146 u_int8_t reserved[MAX_MODAL_RESERVED];
147 u_int16_t switchcomspdt;
148 u_int8_t xLNA_bias_strength; // bit: 0,1:chain0, 2,3:chain1, 4,5:chain2
149 u_int8_t rf_gain_cap;
150 u_int8_t tx_gain_cap; // bit0:4 txgain cap, txgain index for max_txgain + 20 (10dBm higher than max txgain)
151 u_int8_t futureModal[MAX_MODAL_FUTURE];
152 // last 12 bytes stolen and moved to newly created base extension structure
157 load_eeprom_dump(const char *file, uint16_t *buf)
164 fp = fopen(file, "r");
169 if (fgets(b, 1024, fp) == NULL)
174 b[strlen(b)-1] = '\0';
177 sscanf(b, "%x: %x %x %x %x %x %x %x %x\n",
178 &i, &r[0], &r[1], &r[2], &r[3], &r[4],
179 &r[5], &r[6], &r[7]);
195 printf("Usage: %s <eeprom dump file>\n", argv[0]);
197 printf(" The eeprom dump file is a text hexdump of an EEPROM.\n");
198 printf(" The lines must be formatted as follows:\n");
199 printf(" 0xAAAA: 0xDD 0xDD 0xDD 0xDD 0xDD 0xDD 0xDD 0xDD\n");
200 printf(" where each line must have exactly eight data bytes.\n");
205 main(int argc, char *argv[])
207 uint16_t *eep = NULL;
208 const ar9300_eeprom_t *ee;
210 eep = calloc(4096, sizeof(int16_t));
215 load_eeprom_dump(argv[1], eep);
216 ee = (ar9300_eeprom_t *) eep;
218 eeprom_9300_hdr_print(eep);
219 eeprom_9300_base_print(eep);
221 printf("\n2GHz modal:\n");
222 eeprom_9300_modal_print(&ee->modal_header_2g);
224 printf("\n5GHz modal:\n");
225 eeprom_9300_modal_print(&ee->modal_header_5g);