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 "ps3encdec_dev.h"
25 #define PS3ENCDEC_IOCTL_VERSION "0.0.1"
36 static struct option long_opts
[] = {
37 { "help", no_argument
, NULL
, 'h' },
38 { "verbose", no_argument
, NULL
, 'v' },
39 { "version", no_argument
, NULL
, 'V' },
46 static void usage(void) {
48 "Usage: ps3encdec_ioctl [OPTIONS] DEVICE [ARGS]\n"
51 " -h, --help Show this message and exit\n"
52 " -v, --verbose Increase verbosity\n"
53 " -V, --version Show version information and exit\n"
55 " kgen1 ARG1 EdecKgen1\n"
56 " kgenflash EdecKgenFlash\n"
58 "Simple example: EdecKgen1:\n"
59 " ps3encdec_ioctl /dev/ps3encdec kgen1 0x00 0x01 0x00 0x30 0x72 0xA7 0x88 0xEC \\\n"
60 " 0xFC 0xA4 0x06 0x71 0x4C 0xB1 0x50 0xC9 0xFB 0xE0 0x06 0xC2 0x74 0xB5 \\\n"
61 " 0x84 0xC4 0xE6 0xBD 0x1E 0x55 0x4E 0x36 0xE9 0xC9 0xD6 0x09 0xBC 0xB4 \\\n"
62 " 0x79 0xA6 0xBC 0xDE 0x60 0xA5 0xB2 0x41 0xC7 0x15 0x68 0x68 0x82 0x1D \\\n"
63 " 0x8F 0xD6 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00\n");
69 static void version(void)
72 "ps3encdec_ioctl " PS3ENCDEC_IOCTL_VERSION
"\n"
73 "Copyright (C) 2011 graf_chokolo <grafchokolo@googlemail.com>\n"
74 "This is free software. You may redistribute copies of it "
75 "under the terms of\n"
76 "the GNU General Public License 2 "
77 "<http://www.gnu.org/licenses/gpl2.html>.\n"
78 "There is NO WARRANTY, to the extent permitted by law.\n");
84 static int process_opts(int argc
, char **argv
, struct opts
*opts
)
88 while ((c
= getopt_long(argc
, argv
, "hvV", long_opts
, NULL
)) != -1) {
100 opts
->do_version
= 1;
104 fprintf(stderr
, "Invalid command option: %c\n", c
);
109 if (optind
>= argc
) {
110 fprintf(stderr
, "No device specified\n");
114 opts
->device_name
= argv
[optind
];
117 if (optind
>= argc
) {
118 fprintf(stderr
, "No command specified\n");
122 opts
->cmd
= argv
[optind
];
131 static int cmd_kgen1(int fd
, struct opts
*opts
, int argc
, char **argv
)
134 uint64_t cmdbuf_size
;
135 uint8_t cmdbuf
[0x40];
136 uint8_t respbuf
[0x50];
140 if (optind
>= argc
) {
141 fprintf(stderr
, "No ARG1 specified\n");
147 while (optind
< argc
) {
148 val
= strtoul(argv
[optind
], &endptr
, 0);
149 if ((*endptr
!= '\0') || (val
> 0xff)) {
150 fprintf(stderr
, "Invalid ARG1 specified: %s\n", argv
[optind
]);
156 cmdbuf
[cmdbuf_size
++] = val
;
158 if (cmdbuf_size
== 0x40)
162 if (cmdbuf_size
< 0x40) {
163 fprintf(stderr
, "ARG1 should be of size 0x40 bytes\n");
167 error
= ps3encdec_dev_do_request(fd
, 0x81, cmdbuf
, sizeof(cmdbuf
), respbuf
, sizeof(respbuf
));
170 fprintf(stderr
, "%s: %s\n", opts
->device_name
, strerror(errno
));
172 for (i
= 0; i
< sizeof(respbuf
); i
++)
173 fprintf(stdout
, "0x%02x ", respbuf
[i
]);
175 fprintf(stdout
, "\n");
184 static int cmd_kgenflash(int fd
, struct opts
*opts
, int argc
, char **argv
)
188 error
= ps3encdec_dev_do_request(fd
, 0x84, NULL
, 0, NULL
, 0);
191 fprintf(stderr
, "%s: %s\n", opts
->device_name
, strerror(errno
));
199 int main(int argc
, char **argv
)
202 int fd
= 0, error
= 0;
204 memset(&opts
, 0, sizeof(opts
));
206 if (process_opts(argc
, argv
, &opts
)) {
215 } else if (opts
.do_version
) {
220 fd
= ps3encdec_dev_open(opts
.device_name
);
222 fprintf(stderr
, "%s: %s\n", opts
.device_name
, strerror(errno
));
227 if (!strcmp(opts
.cmd
, "kgen1")) {
228 error
= cmd_kgen1(fd
, &opts
, argc
, argv
);
229 } else if (!strcmp(opts
.cmd
, "kgenflash")) {
230 error
= cmd_kgenflash(fd
, &opts
, argc
, argv
);
243 ps3encdec_dev_close(fd
);