initial import
[ps3linux_ps3lv1call_tools.git] / ps3lv1call.c
bloba070212418b2c51542eef3f85913f1a9b5dc6e91
1 /*-
2 * Copyright (C) 2012 glevand <geoffrey.levand@mail.ru>
3 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
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.
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <stdint.h>
30 #include <getopt.h>
31 #include <errno.h>
33 #include "dev.h"
35 static struct option long_opts[] = {
36 { "device", no_argument, NULL, 'd' },
37 { NULL, 0, NULL, 0 }
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;
46 * parse_opts
48 static int parse_opts(int argc, char **argv)
50 int c, i;
51 char *endptr;
53 while ((c = getopt_long(argc, argv, "d:", long_opts, NULL)) != -1) {
54 switch (c) {
55 case 'd':
56 device = optarg;
57 break;
58 default:
59 fprintf(stderr, "invalid option specified: %c\n", c);
60 return (-1);
61 break;
65 if (optind >= argc) {
66 fprintf(stderr, "no lv1 call number specified\n");
67 return (-1);
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]);
73 return (-1);
76 optind++;
78 num_in_args = argc - optind;
79 if (num_in_args > 8) {
80 fprintf(stderr, "too many lv1 call input arguments specified\n");
81 return (-1);
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",
88 argv[optind + i]);
89 return (-1);
93 return (0);
97 * main
99 int main(int argc, char **argv)
101 uint64_t out_args[7];
102 int64_t result;
103 int n, i, ret;
105 ret = parse_opts(argc, argv);
106 if (ret)
107 return (255);
109 n = dev_do_lv1call(device, num_lv1call, in_args, num_in_args, out_args, &result);
110 if (n < 0) {
111 fprintf(stderr, "device error %d\n", errno);
112 return (1);
115 if (result) {
116 fprintf(stderr, "lv1 call %llu error %lld\n", num_lv1call, result);
117 return (2);
120 for (i = 0; i < n; i++)
121 fprintf(stdout, "%016llx%s", out_args[i], i == (n - 1) ? "\n" : " ");
123 return (0);