~ubuntu-branches/ubuntu/edgy/pilot-link/edgy

« back to all changes in this revision

Viewing changes to src/pi-getromtoken.c

  • Committer: Bazaar Package Importer
  • Author(s): Ludovic Rousseau
  • Date: 2006-09-22 11:51:36 UTC
  • mfrom: (3.1.8 edgy)
  • Revision ID: james.westby@ubuntu.com-20060922115136-qqmy17bx8j5x0y72
Tags: 0.12.1-5
* urgency medium since libpisock-dev was not usable to build any package
* libpisock-dev now depends on libusb-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* 
2
 
 * pi-getromtoken.c:  Retrieve a rom token from a device.
3
 
 * 
4
 
 * Copyright (C) 2002, Owen Stenseth
5
 
 *
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.
10
 
 *
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.
15
 
 *
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
19
 
 *
20
 
 */
21
 
 
22
 
#include "getopt.h"
23
 
#include <stdio.h>
24
 
#include <stdlib.h>
25
 
#include <signal.h>
26
 
#include <sys/types.h>
27
 
#include <sys/stat.h>
28
 
#include <unistd.h>
29
 
#include <fcntl.h>
30
 
#include <signal.h>
31
 
#include <string.h>
32
 
#include <netinet/in.h>
33
 
 
34
 
#include "pi-header.h"
35
 
#include "pi-source.h"
36
 
#include "pi-syspkt.h"
37
 
#include "pi-dlp.h"
38
 
 
39
 
/* Declare prototypes */
40
 
static void display_help(char *progname);
41
 
void print_splash(char *progname);
42
 
int pilot_connect(char *port);
43
 
 
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'},
49
 
        {NULL,          0,                 NULL, 0}
50
 
};
51
 
 
52
 
static const char *optstring = "p:hvu:i:t:";
53
 
 
54
 
static void display_help(char *progname)
55
 
{
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");
68
 
 
69
 
        return;
70
 
}
71
 
 
72
 
int main(int argc, char *argv[])
73
 
{
74
 
        int     c,              /* switch */
75
 
                sd              = -1;
76
 
        char    *progname       = argv[0],
77
 
                *port           = NULL,
78
 
                *token          = NULL;
79
 
 
80
 
        long    long_token;
81
 
        unsigned int size;
82
 
 
83
 
        char    buffer[50];
84
 
        
85
 
        while ((c = getopt_long(argc, argv, optstring, options, NULL)) != -1) {
86
 
                switch (c) {
87
 
 
88
 
                case 'h':
89
 
                        display_help(progname);
90
 
                        return 0;
91
 
                case 'v':
92
 
                        print_splash(progname);
93
 
                        return 0;
94
 
                case 'p':
95
 
                        port = optarg;
96
 
                        break;
97
 
                case 't':
98
 
                        token = optarg;
99
 
                        break;
100
 
                default:
101
 
                        display_help(progname);
102
 
                        return 0;
103
 
                }
104
 
        }
105
 
        
106
 
        if(token == NULL) {
107
 
                display_help(progname);
108
 
                return 0;
109
 
        }
110
 
 
111
 
        set_long(&long_token, *((long *)token));
112
 
        
113
 
        sd = pilot_connect(port);
114
 
        if (sd < 0)
115
 
                goto error;
116
 
 
117
 
        if (dlp_GetROMToken(sd, long_token, buffer, &size) < 0)
118
 
                goto error_close;
119
 
        
120
 
        if (dlp_EndOfSync(sd, 0) < 0)
121
 
                goto error_close;
122
 
 
123
 
        if (pi_close(sd) < 0)
124
 
                goto error;
125
 
 
126
 
        fprintf(stderr, "Token for '%s' was: %s\n", token, buffer);
127
 
 
128
 
        return 0;
129
 
 
130
 
error_close:
131
 
        pi_close(sd);
132
 
        
133
 
error:
134
 
        return -1;
135
 
}