arcode.c revision 302408
1/* 2 * Copyright (c) 2011 Adrian Chadd, Xenion Pty Ltd. 3 * 4 * Permission to use, copy, modify, and/or distribute this software for any 5 * purpose with or without fee is hereby granted, provided that the above 6 * copyright notice and this permission notice appear in all copies. 7 * 8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 * 16 * $FreeBSD: stable/11/tools/tools/ath/arcode/arcode.c 244960 2013-01-02 18:03:19Z adrian $ 17 */ 18 19#include <stdio.h> 20#include <stdlib.h> 21#include <unistd.h> 22#include <fcntl.h> 23#include <errno.h> 24 25#include <sys/types.h> 26#include <sys/alq.h> 27 28#include "ah_decode.h" 29 30#define MAX_MARKERS 9 31 32const char *markers[] = { 33 "AH_MARK_RESET", /* ar*Reset entry, bChannelChange */ 34 "AH_MARK_RESET_LINE", /* ar*_reset.c, line %d */ 35 "AH_MARK_RESET_DONE", /* ar*Reset exit, error code */ 36 "AH_MARK_CHIPRESET", /* ar*ChipReset, channel num */ 37 "AH_MARK_PERCAL", /* ar*PerCalibration, channel num */ 38 "AH_MARK_SETCHANNEL", /* ar*SetChannel, channel num */ 39 "AH_MARK_ANI_RESET", /* ar*AniReset, opmode */ 40 "AH_MARK_ANI_POLL", /* ar*AniReset, listen time */ 41 "AH_MARK_ANI_CONTROL", /* ar*AniReset, cmd */ 42}; 43 44static void 45op_read(struct athregrec *a) 46{ 47 printf("read\t%.8x = %.8x\n", a->reg, a->val); 48} 49 50static void 51op_write(struct athregrec *a) 52{ 53 printf("write\t%.8x = %.8x\n", a->reg, a->val); 54} 55 56static void 57op_device(struct athregrec *a) 58{ 59 printf("device\t0x%x/0x%x\n", a->reg, a->val); 60} 61 62static void 63op_mark(struct athregrec *a) 64{ 65 const char *s = "UNKNOWN"; 66 if (a->reg <= MAX_MARKERS) 67 s = markers[a->reg]; 68 69 printf("mark\t%s (%d): %d\n", s, a->reg, a->val); 70} 71 72int 73main(int argc, const char *argv[]) 74{ 75 const char *file = argv[1]; 76 int fd; 77 struct athregrec a; 78 int r; 79 80 if (argc < 2) { 81 printf("usage: %s <ahq log>\n", argv[0]); 82 exit(127); 83 } 84 85 fd = open(file, O_RDONLY); 86 if (fd < 0) { 87 perror("open"); 88 exit(127); 89 } 90 91 while (1) { 92 r = read(fd, &a, sizeof(a)); 93 if (r != sizeof(a)) 94 break; 95 switch (a.op) { 96 case OP_READ: 97 op_read(&a); 98 break; 99 case OP_WRITE: 100 op_write(&a); 101 break; 102 case OP_DEVICE: 103 op_device(&a); 104 break; 105 case OP_MARK: 106 op_mark(&a); 107 break; 108 default: 109 printf("op: %d; reg: 0x%x; val: 0x%x\n", 110 a.op, a.reg, a.val); 111 } 112 } 113 close(fd); 114} 115