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"
57 "Simple example: EdecKgen1:\n"
58 " ps3encdec_ioctl /dev/ps3encdec kgen1 0x00 0x01 0x00 0x30 0x72 0xA7 0x88 0xEC \\\n"
59 " 0xFC 0xA4 0x06 0x71 0x4C 0xB1 0x50 0xC9 0xFB 0xE0 0x06 0xC2 0x74 0xB5 \\\n"
60 " 0x84 0xC4 0xE6 0xBD 0x1E 0x55 0x4E 0x36 0xE9 0xC9 0xD6 0x09 0xBC 0xB4 \\\n"
61 " 0x79 0xA6 0xBC 0xDE 0x60 0xA5 0xB2 0x41 0xC7 0x15 0x68 0x68 0x82 0x1D \\\n"
62 " 0x8F 0xD6 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00\n");
68 static void version(void)
71 "ps3encdec_ioctl " PS3ENCDEC_IOCTL_VERSION
"\n"
72 "Copyright (C) 2011 graf_chokolo <grafchokolo@googlemail.com>\n"
73 "This is free software. You may redistribute copies of it "
74 "under the terms of\n"
75 "the GNU General Public License 2 "
76 "<http://www.gnu.org/licenses/gpl2.html>.\n"
77 "There is NO WARRANTY, to the extent permitted by law.\n");
83 static int process_opts(int argc
, char **argv
, struct opts
*opts
)
87 while ((c
= getopt_long(argc
, argv
, "hvV", long_opts
, NULL
)) != -1) {
103 fprintf(stderr
, "Invalid command option: %c\n", c
);
108 if (optind
>= argc
) {
109 fprintf(stderr
, "No device specified\n");
113 opts
->device_name
= argv
[optind
];
116 if (optind
>= argc
) {
117 fprintf(stderr
, "No command specified\n");
121 opts
->cmd
= argv
[optind
];
130 static int cmd_kgen1(int fd
, struct opts
*opts
, int argc
, char **argv
)
133 uint64_t cmdbuf_size
;
134 uint8_t cmdbuf
[0x40];
135 uint8_t respbuf
[0x50];
139 if (optind
>= argc
) {
140 fprintf(stderr
, "No ARG1 specified\n");
146 while (optind
< argc
) {
147 val
= strtoul(argv
[optind
], &endptr
, 0);
148 if ((*endptr
!= '\0') || (val
> 0xff)) {
149 fprintf(stderr
, "Invalid ARG1 specified: %s\n", argv
[optind
]);
155 cmdbuf
[cmdbuf_size
++] = val
;
157 if (cmdbuf_size
== 0x40)
161 if (cmdbuf_size
< 0x40) {
162 fprintf(stderr
, "ARG1 should be of size 0x40 bytes\n");
166 error
= ps3encdec_dev_do_request(fd
, 0x81, cmdbuf
, sizeof(cmdbuf
), respbuf
, sizeof(respbuf
));
169 fprintf(stderr
, "%s: %s\n", opts
->device_name
, strerror(errno
));
171 for (i
= 0; i
< sizeof(respbuf
); i
++)
172 fprintf(stdout
, "0x%02x ", respbuf
[i
]);
174 fprintf(stdout
, "\n");
182 int main(int argc
, char **argv
)
185 int fd
= 0, error
= 0;
187 memset(&opts
, 0, sizeof(opts
));
189 if (process_opts(argc
, argv
, &opts
)) {
198 } else if (opts
.do_version
) {
203 fd
= ps3encdec_dev_open(opts
.device_name
);
205 fprintf(stderr
, "%s: %s\n", opts
.device_name
, strerror(errno
));
210 if (!strcmp(opts
.cmd
, "kgen1")) {
211 error
= cmd_kgen1(fd
, &opts
, argc
, argv
);
224 ps3encdec_dev_close(fd
);