1254721Semaste/* 2254721Semaste * Copyright (c) 2011 Adrian Chadd, Xenion Pty Ltd. 3254721Semaste * 4254721Semaste * Permission to use, copy, modify, and/or distribute this software for any 5254721Semaste * purpose with or without fee is hereby granted, provided that the above 6254721Semaste * copyright notice and this permission notice appear in all copies. 7254721Semaste * 8254721Semaste * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9254721Semaste * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10254721Semaste * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11254721Semaste * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12254721Semaste * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13254721Semaste * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14254721Semaste * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15254721Semaste * 16254721Semaste * $FreeBSD$ 17254721Semaste */ 18254721Semaste 19254721Semaste#include <stdio.h> 20254721Semaste#include <stdlib.h> 21254721Semaste#include <unistd.h> 22254721Semaste#include <fcntl.h> 23254721Semaste#include <errno.h> 24254721Semaste 25254721Semaste#include <sys/types.h> 26254721Semaste#include <sys/alq.h> 27254721Semaste 28254721Semaste#include "ah_decode.h" 29254721Semaste 30254721Semaste#define MAX_MARKERS 9 31254721Semaste 32254721Semasteconst char *markers[] = { 33254721Semaste "AH_MARK_RESET", /* ar*Reset entry, bChannelChange */ 34254721Semaste "AH_MARK_RESET_LINE", /* ar*_reset.c, line %d */ 35254721Semaste "AH_MARK_RESET_DONE", /* ar*Reset exit, error code */ 36254721Semaste "AH_MARK_CHIPRESET", /* ar*ChipReset, channel num */ 37254721Semaste "AH_MARK_PERCAL", /* ar*PerCalibration, channel num */ 38254721Semaste "AH_MARK_SETCHANNEL", /* ar*SetChannel, channel num */ 39254721Semaste "AH_MARK_ANI_RESET", /* ar*AniReset, opmode */ 40254721Semaste "AH_MARK_ANI_POLL", /* ar*AniReset, listen time */ 41254721Semaste "AH_MARK_ANI_CONTROL", /* ar*AniReset, cmd */ 42254721Semaste}; 43254721Semaste 44254721Semastestatic void 45254721Semasteop_read(struct athregrec *a) 46254721Semaste{ 47254721Semaste printf("read\t%.8x = %.8x\n", a->reg, a->val); 48254721Semaste} 49254721Semaste 50254721Semastestatic void 51254721Semasteop_write(struct athregrec *a) 52254721Semaste{ 53254721Semaste printf("write\t%.8x = %.8x\n", a->reg, a->val); 54254721Semaste} 55254721Semaste 56254721Semastestatic void 57254721Semasteop_device(struct athregrec *a) 58254721Semaste{ 59254721Semaste printf("device\t0x%x/0x%x\n", a->reg, a->val); 60254721Semaste} 61254721Semaste 62254721Semastestatic void 63254721Semasteop_mark(struct athregrec *a) 64254721Semaste{ 65254721Semaste const char *s = "UNKNOWN"; 66254721Semaste if (a->reg <= MAX_MARKERS) 67254721Semaste s = markers[a->reg]; 68254721Semaste 69254721Semaste printf("mark\t%s (%d): %d\n", s, a->reg, a->val); 70254721Semaste} 71254721Semaste 72254721Semasteint 73254721Semastemain(int argc, const char *argv[]) 74254721Semaste{ 75254721Semaste const char *file = argv[1]; 76254721Semaste int fd; 77254721Semaste struct athregrec a; 78254721Semaste int r; 79254721Semaste 80254721Semaste if (argc < 2) { 81254721Semaste printf("usage: %s <ahq log>\n", argv[0]); 82254721Semaste exit(127); 83254721Semaste } 84254721Semaste 85254721Semaste fd = open(file, O_RDONLY); 86254721Semaste if (fd < 0) { 87254721Semaste perror("open"); 88254721Semaste exit(127); 89254721Semaste } 90254721Semaste 91254721Semaste while (1) { 92254721Semaste r = read(fd, &a, sizeof(a)); 93254721Semaste if (r != sizeof(a)) 94254721Semaste break; 95254721Semaste switch (a.op) { 96254721Semaste case OP_READ: 97254721Semaste op_read(&a); 98254721Semaste break; 99254721Semaste case OP_WRITE: 100254721Semaste op_write(&a); 101254721Semaste break; 102254721Semaste case OP_DEVICE: 103254721Semaste op_device(&a); 104254721Semaste break; 105254721Semaste case OP_MARK: 106254721Semaste op_mark(&a); 107254721Semaste break; 108254721Semaste default: 109254721Semaste printf("op: %d; reg: 0x%x; val: 0x%x\n", 110254721Semaste a.op, a.reg, a.val); 111254721Semaste } 112254721Semaste } 113254721Semaste close(fd); 114254721Semaste} 115254721Semaste