Tools for working with Cidco Mailstations
at master 117 lines 2.2 kB view raw
1/* 2 * recvdump 3 * based on win32/maildump.cpp by FyberOptic 4 * 5 * must be run as root to set iopl and use inb/outb 6 * 7 * assumes codedump or datadump has been loaded on the Mailstation and is 8 * running 9 */ 10 11#include <stdio.h> 12#include <stdlib.h> 13#include <string.h> 14#include <err.h> 15#include <errno.h> 16#include <unistd.h> 17#include <sys/types.h> 18#include <sys/limits.h> 19 20#include "tribble.h" 21 22void 23usage(void) 24{ 25 printf("usage: %s [-d] [-p port address] <code|data|mem>\n", 26 getprogname()); 27 exit(1); 28} 29 30int 31main(int argc, char *argv[]) 32{ 33 FILE *pFile; 34 unsigned int received = 0, expected = 0; 35 int ch, b, codeflash = 0, dataflash = 0, mem = 0; 36 char fn[14]; 37 38 while ((ch = getopt(argc, argv, "dp:")) != -1) { 39 switch (ch) { 40 case 'd': 41 tribble_debug = 1; 42 break; 43 case 'p': 44 tribble_port = (unsigned)strtol(optarg, NULL, 0); 45 if (errno) 46 err(1, "invalid port value"); 47 break; 48 default: 49 usage(); 50 } 51 } 52 argc -= optind; 53 argv += optind; 54 55 if (argc != 1) 56 usage(); 57 58 if (strncmp((char *)argv[0], "code", 5) == 0) { 59 if (dataflash || mem) 60 usage(); 61 codeflash = 1; 62 } else if (strncmp((char *)argv[0], "data", 5) == 0) { 63 if (codeflash || mem) 64 usage(); 65 dataflash = 1; 66 } else if (strncmp((char *)argv[0], "mem", 4) == 0) { 67 if (codeflash || dataflash) 68 usage(); 69 mem = 1; 70 } else 71 errx(1, "unknown dump parameter: %s\n", argv[0]); 72 73 if (codeflash) { 74 expected = 1024 * 1024; 75 strlcpy(fn, "codeflash.bin", sizeof(fn)); 76 } else if (dataflash) { 77 expected = 1024 * 512; 78 strlcpy(fn, "dataflash.bin", sizeof(fn)); 79 } else if (mem) { 80 expected = (1024 * 64) - 1; 81 strlcpy(fn, "mem.bin", sizeof(fn)); 82 } else 83 usage(); 84 85 checkio(); 86 87 pFile = fopen(fn, "wb"); 88 if (!pFile) { 89 printf("couldn't open file %s\n", fn); 90 return 1; 91 } 92 93 printf("[port 0x%x] dumping to %s, run Code Dump on Mailstation...", 94 tribble_port, fn); 95 fflush(stdout); 96 97 while (received < expected) { 98 if ((b = recvbyte()) == -1) 99 continue; 100 101 fputc(b & 0xff, pFile); 102 fflush(pFile); 103 104 if (received++ == 0) 105 printf("\n"); 106 107 if (received % 1024 == 0 || received == expected) { 108 printf("\rreceived: %07d/%07d", received, expected); 109 fflush(stdout); 110 } 111 } 112 fclose(pFile); 113 114 printf("\n"); 115 116 return 0; 117}