blob: 2b51b330edd2fe12d214be8fb496d34c954a33df [file] [log] [blame]
Colin Crossa3d386e2013-02-06 21:03:34 -08001/*
2 * Copyright (C) 2013 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <stdio.h>
18#include <unistd.h>
Colin Crossa3d386e2013-02-06 21:03:34 -080019#include <cutils/klog.h>
Szymon Starzycki2a656c32013-09-05 14:26:28 -070020#include <getopt.h>
21#include <stdlib.h>
Colin Crossa3d386e2013-02-06 21:03:34 -080022
23#include "debug.h"
Szymon Starzyckib6c5f282013-07-24 17:08:04 -070024#include "trigger.h"
Szymon Starzycki2a656c32013-09-05 14:26:28 -070025#include "socket_client.h"
Szymon Starzycki4662a112013-10-02 17:21:41 -070026#include "secure.h"
Colin Crossa3d386e2013-02-06 21:03:34 -080027
28unsigned int debug_level = DEBUG;
29
30void commands_init();
31void usb_init();
32void config_init();
Szymon Starzycki2a656c32013-09-05 14:26:28 -070033int transport_socket_init();
Szymon Starzyckibc849f12013-09-13 15:37:08 -070034int network_discovery_init();
Szymon Starzycki27ea99f2013-09-18 16:12:43 -070035void ssh_server_start();
Colin Crossa3d386e2013-02-06 21:03:34 -080036
37int main(int argc, char **argv)
38{
Szymon Starzycki2a656c32013-09-05 14:26:28 -070039 int socket_client = 0;
40 int c;
Szymon Starzycki55b61f42013-10-03 11:06:45 -070041 int network = 1;
Szymon Starzycki2a656c32013-09-05 14:26:28 -070042
43 klog_init();
44 klog_set_level(6);
45
46 const struct option longopts[] = {
47 {"socket", no_argument, 0, 'S'},
Szymon Starzycki55b61f42013-10-03 11:06:45 -070048 {"nonetwork", no_argument, 0, 'n'},
Szymon Starzycki2a656c32013-09-05 14:26:28 -070049 {0, 0, 0, 0}
50 };
51
52 while (1) {
Szymon Starzycki55b61f42013-10-03 11:06:45 -070053 c = getopt_long(argc, argv, "Sn", longopts, NULL);
Szymon Starzycki2a656c32013-09-05 14:26:28 -070054 /* Alphabetical cases */
55 if (c < 0)
56 break;
57 switch (c) {
58 case 'S':
59 socket_client = 1;
60 break;
Szymon Starzycki55b61f42013-10-03 11:06:45 -070061 case 'n':
62 network = 0;
63 break;
Szymon Starzycki2a656c32013-09-05 14:26:28 -070064 case '?':
65 return 1;
66 default:
67 return 0;
68 }
69 }
70
Colin Crossa3d386e2013-02-06 21:03:34 -080071 (void)argc;
72 (void)argv;
73
74 klog_init();
75 klog_set_level(6);
76
Szymon Starzycki2a656c32013-09-05 14:26:28 -070077 if (socket_client) {
Szymon Starzycki55b61f42013-10-03 11:06:45 -070078 //TODO: Shouldn't we change current tty into raw mode?
Szymon Starzycki2a656c32013-09-05 14:26:28 -070079 run_socket_client();
80 }
81 else {
Szymon Starzycki4662a112013-10-02 17:21:41 -070082 cert_init_crypto();
Szymon Starzycki2a656c32013-09-05 14:26:28 -070083 config_init();
84 load_trigger();
85 commands_init();
86 usb_init();
Szymon Starzycki55b61f42013-10-03 11:06:45 -070087
88 if (network) {
89 if (!transport_socket_init())
90 exit(1);
91 ssh_server_start();
92 network_discovery_init();
93 }
94
Szymon Starzycki2a656c32013-09-05 14:26:28 -070095 while (1) {
96 sleep(1);
97 }
Colin Crossa3d386e2013-02-06 21:03:34 -080098 }
99 return 0;
100}