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 17 #include <stdio.h> 18 #include <stdlib.h> 19 #include <unistd.h> 20 #include <fcntl.h> 21 #include <errno.h> 22 23 #include <sys/types.h> 24 #include <sys/alq.h> 25 26 #include "ah_decode.h" 27 28 #define MAX_MARKERS 9 29 30 const char *markers[] = { 31 "AH_MARK_RESET", /* ar*Reset entry, bChannelChange */ 32 "AH_MARK_RESET_LINE", /* ar*_reset.c, line %d */ 33 "AH_MARK_RESET_DONE", /* ar*Reset exit, error code */ 34 "AH_MARK_CHIPRESET", /* ar*ChipReset, channel num */ 35 "AH_MARK_PERCAL", /* ar*PerCalibration, channel num */ 36 "AH_MARK_SETCHANNEL", /* ar*SetChannel, channel num */ 37 "AH_MARK_ANI_RESET", /* ar*AniReset, opmode */ 38 "AH_MARK_ANI_POLL", /* ar*AniReset, listen time */ 39 "AH_MARK_ANI_CONTROL", /* ar*AniReset, cmd */ 40 }; 41 42 static void 43 op_read(struct athregrec *a) 44 { 45 printf("read\t%.8x = %.8x\n", a->reg, a->val); 46 } 47 48 static void 49 op_write(struct athregrec *a) 50 { 51 printf("write\t%.8x = %.8x\n", a->reg, a->val); 52 } 53 54 static void 55 op_device(struct athregrec *a) 56 { 57 printf("device\t0x%x/0x%x\n", a->reg, a->val); 58 } 59 60 static void 61 op_mark(struct athregrec *a) 62 { 63 const char *s = "UNKNOWN"; 64 if (a->reg <= MAX_MARKERS) 65 s = markers[a->reg]; 66 67 printf("mark\t%s (%d): %d\n", s, a->reg, a->val); 68 } 69 70 int 71 main(int argc, const char *argv[]) 72 { 73 const char *file = argv[1]; 74 int fd; 75 struct athregrec a; 76 int r; 77 78 if (argc < 2) { 79 printf("usage: %s <ahq log>\n", argv[0]); 80 exit(127); 81 } 82 83 fd = open(file, O_RDONLY); 84 if (fd < 0) { 85 perror("open"); 86 exit(127); 87 } 88 89 while (1) { 90 r = read(fd, &a, sizeof(a)); 91 if (r != sizeof(a)) 92 break; 93 switch (a.op) { 94 case OP_READ: 95 op_read(&a); 96 break; 97 case OP_WRITE: 98 op_write(&a); 99 break; 100 case OP_DEVICE: 101 op_device(&a); 102 break; 103 case OP_MARK: 104 op_mark(&a); 105 break; 106 default: 107 printf("op: %d; reg: 0x%x; val: 0x%x\n", 108 a.op, a.reg, a.val); 109 } 110 } 111 close(fd); 112 } 113