3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; version 2 of the License.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "ps3dm_proxy.h"
27 #define PS3DM_IIM_VERSION "0.0.1"
29 #define PS3DM_IIM_LAID 0x1070000002000001ull
30 #define PS3DM_IIM_PAID 0x1070000300000001ull
41 static struct option long_opts
[] = {
42 { "help", no_argument
, NULL
, 'h' },
43 { "verbose", no_argument
, NULL
, 'v' },
44 { "version", no_argument
, NULL
, 'V' },
51 static void usage(void) {
53 "Usage: ps3dm_iim [OPTIONS] DEVICE COMMAND [ARGS]\n"
56 " -h, --help Show this message and exit\n"
57 " -v, --verbose Increase verbosity\n"
58 " -V, --version Show version information and exit\n"
60 " get_data_size INDEX Returns data size by index\n"
61 " get_data INDEX Returns data by index\n"
66 " get_cisd_size Returns cISD size\n"
68 "Simple example: Get size of EID0:\n"
69 " ps3dm_iim /dev/ps3dmproxy get_data_size 0\n");
75 static void version(void)
78 "ps3dm_iim " PS3DM_IIM_VERSION
"\n"
79 "Copyright (C) 2011 graf_chokolo <grafchokolo@googlemail.com>\n"
80 "This is free software. You may redistribute copies of it "
81 "under the terms of\n"
82 "the GNU General Public License 2 "
83 "<http://www.gnu.org/licenses/gpl2.html>.\n"
84 "There is NO WARRANTY, to the extent permitted by law.\n");
90 static int process_opts(int argc
, char **argv
, struct opts
*opts
)
94 while ((c
= getopt_long(argc
, argv
, "hvV", long_opts
, NULL
)) != -1) {
106 opts
->do_version
= 1;
110 fprintf(stderr
, "Invalid command option: %c\n", c
);
115 if (optind
>= argc
) {
116 fprintf(stderr
, "No device specified\n");
120 opts
->device_name
= argv
[optind
];
123 if (optind
>= argc
) {
124 fprintf(stderr
, "No command specified\n");
128 opts
->cmd
= argv
[optind
];
137 static int cmd_get_data_size(int fd
, struct opts
*opts
, int argc
, char **argv
)
142 struct ps3dm_hdr
*dm_hdr
;
143 struct ps3ss_hdr
*ss_hdr
;
144 struct ps3ss_iim_get_data_size
*ss_iim_get_data_size
;
147 if (optind
>= argc
) {
148 fprintf(stderr
, "No data index specified\n");
152 data_index
= strtoul(argv
[optind
], &endptr
, 0);
153 if (*endptr
!= '\0') {
154 fprintf(stderr
, "Invalid data index specified: %s\n", argv
[optind
]);
160 memset(buf
, 0, sizeof(buf
));
161 dm_hdr
= (struct ps3dm_hdr
*) buf
;
162 ss_hdr
= (struct ps3ss_hdr
*)(dm_hdr
+ 1);
163 ss_iim_get_data_size
= (struct ps3ss_iim_get_data_size
*)(ss_hdr
+ 1);
165 dm_hdr
->request_id
= 1;
166 dm_hdr
->function_id
= PS3SS_FID_IIM
;
167 dm_hdr
->request_size
= PS3SS_HDR_SIZE
+ sizeof(struct ps3ss_iim_get_data_size
);
168 dm_hdr
->response_size
= PS3SS_HDR_SIZE
+ sizeof(struct ps3ss_iim_get_data_size
);
170 ss_hdr
->packet_id
= PS3SS_PID_IIM_GET_DATA_SIZE
;
171 ss_hdr
->function_id
= PS3SS_FID_IIM
;
172 ss_hdr
->laid
= PS3DM_IIM_LAID
;
173 ss_hdr
->paid
= PS3DM_IIM_PAID
;
175 ss_iim_get_data_size
->index
= data_index
;
177 error
= ps3dm_proxy_do_request(fd
, dm_hdr
, PS3DM_HDR_SIZE
+ dm_hdr
->request_size
,
178 dm_hdr
, PS3DM_HDR_SIZE
+ dm_hdr
->response_size
);
181 fprintf(stderr
, "%s: %s\n", opts
->device_name
, strerror(errno
));
182 } else if (ss_hdr
->retval
) {
183 fprintf(stderr
, "%s: SS retval %d\n", opts
->device_name
, ss_hdr
->retval
);
186 fprintf(stdout
, "0x%016lx\n", ss_iim_get_data_size
->size
);
195 static int cmd_get_data(int fd
, struct opts
*opts
, int argc
, char **argv
)
197 #define BUF_SIZE 0x900
201 uint8_t buf
[128 + BUF_SIZE
];
202 struct ps3dm_hdr
*dm_hdr
;
203 struct ps3ss_hdr
*ss_hdr
;
204 struct ps3ss_iim_get_data
*ss_iim_get_data
;
208 if (optind
>= argc
) {
209 fprintf(stderr
, "No data index specified\n");
213 data_index
= strtoul(argv
[optind
], &endptr
, 0);
214 if (*endptr
!= '\0') {
215 fprintf(stderr
, "Invalid data index specified: %s\n", argv
[optind
]);
221 memset(buf
, 0, sizeof(buf
));
222 dm_hdr
= (struct ps3dm_hdr
*) buf
;
223 ss_hdr
= (struct ps3ss_hdr
*)(dm_hdr
+ 1);
224 ss_iim_get_data
= (struct ps3ss_iim_get_data
*)(ss_hdr
+ 1);
226 dm_hdr
->request_id
= 1;
227 dm_hdr
->function_id
= PS3SS_FID_IIM
;
228 dm_hdr
->request_size
= PS3SS_HDR_SIZE
+ sizeof(struct ps3ss_iim_get_data
) +
229 BUF_SIZE
+ sizeof(uint64_t);
230 dm_hdr
->response_size
= PS3SS_HDR_SIZE
+ sizeof(struct ps3ss_iim_get_data
) +
231 BUF_SIZE
+ sizeof(uint64_t);
233 ss_hdr
->packet_id
= PS3SS_PID_IIM_GET_DATA
;
234 ss_hdr
->function_id
= PS3SS_FID_IIM
;
235 ss_hdr
->laid
= PS3DM_IIM_LAID
;
236 ss_hdr
->paid
= PS3DM_IIM_PAID
;
238 ss_iim_get_data
->index
= data_index
;
239 ss_iim_get_data
->buf_size
= BUF_SIZE
;
241 error
= ps3dm_proxy_do_request(fd
, dm_hdr
, PS3DM_HDR_SIZE
+ dm_hdr
->request_size
,
242 dm_hdr
, PS3DM_HDR_SIZE
+ dm_hdr
->response_size
);
245 fprintf(stderr
, "%s: %s\n", opts
->device_name
, strerror(errno
));
246 } else if (ss_hdr
->retval
) {
247 fprintf(stderr
, "%s: SS retval %d\n", opts
->device_name
, ss_hdr
->retval
);
250 data_size
= *(uint64_t *) (ss_iim_get_data
->buf
+ ss_iim_get_data
->buf_size
);
252 for (i
= 0; i
< data_size
; i
++)
253 fprintf(stdout
, "%c", ss_iim_get_data
->buf
[i
]);
264 static int cmd_get_cisd_size(int fd
, struct opts
*opts
, int argc
, char **argv
)
267 struct ps3dm_hdr
*dm_hdr
;
268 struct ps3ss_hdr
*ss_hdr
;
269 struct ps3ss_iim_get_cisd_size
*ss_iim_get_cisd_size
;
272 memset(buf
, 0, sizeof(buf
));
273 dm_hdr
= (struct ps3dm_hdr
*) buf
;
274 ss_hdr
= (struct ps3ss_hdr
*)(dm_hdr
+ 1);
275 ss_iim_get_cisd_size
= (struct ps3ss_iim_get_cisd_size
*)(ss_hdr
+ 1);
277 dm_hdr
->request_id
= 1;
278 dm_hdr
->function_id
= PS3SS_FID_IIM
;
279 dm_hdr
->request_size
= PS3SS_HDR_SIZE
+ sizeof(struct ps3ss_iim_get_cisd_size
);
280 dm_hdr
->response_size
= PS3SS_HDR_SIZE
+ sizeof(struct ps3ss_iim_get_cisd_size
);
282 ss_hdr
->packet_id
= PS3SS_PID_IIM_GET_CISD_SIZE
;
283 ss_hdr
->function_id
= PS3SS_FID_IIM
;
284 ss_hdr
->laid
= PS3DM_IIM_LAID
;
285 ss_hdr
->paid
= PS3DM_IIM_PAID
;
287 error
= ps3dm_proxy_do_request(fd
, dm_hdr
, PS3DM_HDR_SIZE
+ dm_hdr
->request_size
,
288 dm_hdr
, PS3DM_HDR_SIZE
+ dm_hdr
->response_size
);
291 fprintf(stderr
, "%s: %s\n", opts
->device_name
, strerror(errno
));
292 } else if (ss_hdr
->retval
) {
293 fprintf(stderr
, "%s: SS retval %d\n", opts
->device_name
, ss_hdr
->retval
);
296 fprintf(stdout
, "0x%016lx\n", ss_iim_get_cisd_size
->size
);
305 int main(int argc
, char **argv
)
308 int fd
= 0, error
= 0;
310 memset(&opts
, 0, sizeof(opts
));
312 if (process_opts(argc
, argv
, &opts
)) {
321 } else if (opts
.do_version
) {
326 fd
= ps3dm_proxy_open(opts
.device_name
);
328 fprintf(stderr
, "%s: %s\n", opts
.device_name
, strerror(errno
));
333 if (!strcmp(opts
.cmd
, "get_data")) {
334 error
= cmd_get_data(fd
, &opts
, argc
, argv
);
335 } else if (!strcmp(opts
.cmd
, "get_data_size")) {
336 error
= cmd_get_data_size(fd
, &opts
, argc
, argv
);
337 } else if (!strcmp(opts
.cmd
, "get_cisd_size")) {
338 error
= cmd_get_cisd_size(fd
, &opts
, argc
, argv
);
351 ps3dm_proxy_close(fd
);