2
* pi-getromtoken.c: Retrieve a rom token from a device.
4
* Copyright (C) 2002, Owen Stenseth
6
* This program is free software; you can redistribute it and/or modify it
7
* under the terms of the GNU General Public License as published by the
8
* Free Software Foundation; either version 2 of the License, or (at your
9
* option) any later version.
11
* This program is distributed in the hope that it will be useful, but
12
* WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
14
* Public License for more details.
16
* You should have received a copy of the GNU General Public License along
17
* with this program; if not, write to the Free Software Foundation, Inc.,
18
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26
#include <sys/types.h>
32
#include <netinet/in.h>
34
#include "pi-header.h"
35
#include "pi-source.h"
36
#include "pi-syspkt.h"
39
/* Declare prototypes */
40
static void display_help(char *progname);
41
void print_splash(char *progname);
42
int pilot_connect(char *port);
44
struct option options[] = {
45
{"port", required_argument, NULL, 'p'},
46
{"help", no_argument, NULL, 'h'},
47
{"version", no_argument, NULL, 'v'},
48
{"token", required_argument, NULL, 't'},
52
static const char *optstring = "p:hvu:i:t:";
54
static void display_help(char *progname)
56
printf(" Reads a ROM token from a Palm Handheld device\n\n");
57
printf(" Usage: %s -p <port> -t <romtoken>\n\n", progname);
58
printf(" Options:\n");
59
printf(" -p, --port <port> Use device file <port> to communicate with Palm\n");
60
printf(" -h, --help Display help information for %s\n", progname);
61
printf(" -v, --version Display %s version information\n", progname);
62
printf(" -t <token> A ROM token to read (i.e. snum)\n\n");
63
printf(" Example: %s -p /dev/pilot -t snum\n\n", progname);
64
printf(" Other tokens you may currently extract are:\n");
65
printf(" adcc: Entropy for internal A->D convertor calibration\n");
66
printf(" irda: Present only on memory card w/IrDA support\n");
67
printf(" snum: Device serial number (from Memory Card Flash ID)\n\n");
72
int main(int argc, char *argv[])
76
char *progname = argv[0],
85
while ((c = getopt_long(argc, argv, optstring, options, NULL)) != -1) {
89
display_help(progname);
92
print_splash(progname);
101
display_help(progname);
107
display_help(progname);
111
set_long(&long_token, *((long *)token));
113
sd = pilot_connect(port);
117
if (dlp_GetROMToken(sd, long_token, buffer, &size) < 0)
120
if (dlp_EndOfSync(sd, 0) < 0)
123
if (pi_close(sd) < 0)
126
fprintf(stderr, "Token for '%s' was: %s\n", token, buffer);