Develop and Download Open Source Software

Browse Subversion Repository

Contents of /trunk/src/dump/dump.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 90 - (show annotations) (download) (as text)
Sun Jun 1 13:35:58 2008 UTC (16 years ago) by tmurakam
File MIME type: text/x-csrc
File size: 4541 byte(s)
updated
1 /*
2 felicalib - FeliCa access wrapper library
3
4 Copyright (c) 2007, Takuya Murakami, All rights reserved.
5
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions are
8 met:
9
10 1. Redistributions of source code must retain the above copyright notice,
11 this list of conditions and the following disclaimer.
12
13 2. Redistributions in binary form must reproduce the above copyright
14 notice, this list of conditions and the following disclaimer in the
15 documentation and/or other materials provided with the distribution.
16
17 3. Neither the name of the project nor the names of its contributors
18 may be used to endorse or promote products derived from this software
19 without specific prior written permission.
20
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
25 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33 /**
34 @file dump.c
35
36 FeliCa �_���v
37 */
38
39 #include <stdio.h>
40
41 #include "felicalib.h"
42
43 static void printserviceinfo(uint16 s);
44 static void hexdump(uint8 *addr, int n);
45
46 int _tmain(int argc, _TCHAR *argv[])
47 {
48 pasori *p;
49 felica *f, *f2;
50 int i, j, k;
51
52 p = pasori_open(NULL);
53 if (!p) {
54 fprintf(stderr, "PaSoRi open failed.\n");
55 exit(1);
56 }
57 pasori_init(p);
58
59 f = felica_polling(p, POLLING_ANY, 0, 0);
60 if (!f) {
61 fprintf(stderr, "Polling card failed.\n");
62 exit(1);
63 }
64 printf("# IDm: ");
65 hexdump(f->IDm, 8);
66 printf("\n");
67 printf("# PMm: ");
68 hexdump(f->PMm, 8);
69 printf("\n\n");
70 felica_free(f);
71
72 f = felica_enum_systemcode(p);
73 if (!f) {
74 exit(1);
75 }
76
77 for (i = 0; i < f->num_system_code; i++) {
78 printf("# System code: %04X\n", N2HS(f->system_code[i]));
79 f2 = felica_enum_service(p, N2HS(f->system_code[i]));
80 if (!f2) {
81 fprintf(stderr, "Enum service failed.\n");
82 exit(1);
83 }
84
85 printf("# Number of area = %d\n", f2->num_area_code);
86 for (j = 0; j < f2->num_area_code; j++) {
87 printf("# Area: %04X - %04X\n", f2->area_code[j], f2->end_service_code[j]);
88 }
89
90 printf("# Number of service code = %d\n", f2->num_service_code);
91 for (j = 0; j < f2->num_service_code; j++) {
92 uint16 service = f2->service_code[j];
93 printserviceinfo(service);
94
95 for (k = 0; k < 255; k++) {
96 uint8 data[16];
97
98 if (felica_read_without_encryption02(f2, service, 0, (uint8)k, data)) {
99 break;
100 }
101
102 printf("%04X:%04X ", service, k);
103 hexdump(data, 16);
104 printf("\n");
105 }
106 }
107 printf("\n");
108 felica_free(f2);
109 }
110
111 felica_free(f);
112 pasori_close(p);
113
114 return 0;
115 }
116
117 static void printserviceinfo(uint16 s)
118 {
119 char *ident;
120
121 switch ((s >> 1) & 0xf) {
122 case 0: ident = "Area Code"; break;
123 case 4: ident = "Random Access R/W"; break;
124 case 5: ident = "Random Access Read only"; break;
125 case 6: ident = "Cyclic Access R/W"; break;
126 case 7: ident = "Cyclic Access Read only"; break;
127 case 8: ident = "Purse (Direct)"; break;
128 case 9: ident = "Purse (Cashback/decrement)"; break;
129 case 10: ident = "Purse (Decrement)"; break;
130 case 11: ident = "Purse (Read only)"; break;
131 default: ident = "INVALID or UNKOWN"; break;
132 }
133
134 printf("# Serivce code = %04X : %s", s, ident);
135 if ((s & 0x1) == 0) {
136 printf(" (Protected)");
137 }
138 printf("\n");
139 }
140
141 static void hexdump(uint8 *addr, int n)
142 {
143 int i;
144 for (i = 0; i < n; i++) {
145 printf("%02X ", addr[i]);
146 }
147 }

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26