2 * Copyright (C) 2012 glevand <geoffrey.levand@mail.ru>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer,
10 * without modification, immediately at the beginning of the file.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 static struct option long_opts
[] = {
36 { "device", no_argument
, NULL
, 'd' },
40 static const char *device
= "/dev/ps3lv1call";
41 static uint64_t num_lv1call
;
42 static uint64_t in_args
[8];
43 static int num_in_args
;
48 static int parse_opts(int argc
, char **argv
)
53 while ((c
= getopt_long(argc
, argv
, "d:", long_opts
, NULL
)) != -1) {
59 fprintf(stderr
, "invalid option specified: %c\n", c
);
66 fprintf(stderr
, "no lv1 call number specified\n");
70 num_lv1call
= strtoull(argv
[optind
], &endptr
, 0);
71 if ((*endptr
!= '\0') || (num_lv1call
> 255)) {
72 fprintf(stderr
, "invalid lv1 call number specified: %s\n", argv
[optind
]);
78 num_in_args
= argc
- optind
;
79 if (num_in_args
> 8) {
80 fprintf(stderr
, "too many lv1 call input arguments specified\n");
84 for (i
= 0; i
< num_in_args
; i
++) {
85 in_args
[i
] = strtoull(argv
[optind
+ i
], &endptr
, 0);
86 if (*endptr
!= '\0') {
87 fprintf(stderr
, "invalid lv1 call input argument specified: %s\n",
99 int main(int argc
, char **argv
)
101 uint64_t out_args
[7];
105 ret
= parse_opts(argc
, argv
);
109 n
= dev_do_lv1call(device
, num_lv1call
, in_args
, num_in_args
, out_args
, &result
);
111 fprintf(stderr
, "device error %d\n", errno
);
116 fprintf(stderr
, "lv1 call %llu error %lld\n", num_lv1call
, result
);
120 for (i
= 0; i
< n
; i
++)
121 fprintf(stdout
, "%016llx%s", out_args
[i
], i
== (n
- 1) ? "\n" : " ");