blob: 9318c9928c8bb1799a3f2075e5d7ac9e6cd86da8 [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;
41
42 klog_init();
43 klog_set_level(6);
44
45 const struct option longopts[] = {
46 {"socket", no_argument, 0, 'S'},
47 {0, 0, 0, 0}
48 };
49
50 while (1) {
51 c = getopt_long(argc, argv, "S", longopts, NULL);
52 /* Alphabetical cases */
53 if (c < 0)
54 break;
55 switch (c) {
56 case 'S':
57 socket_client = 1;
58 break;
59 case '?':
60 return 1;
61 default:
62 return 0;
63 }
64 }
65
Colin Crossa3d386e2013-02-06 21:03:34 -080066 (void)argc;
67 (void)argv;
68
69 klog_init();
70 klog_set_level(6);
71
Szymon Starzycki2a656c32013-09-05 14:26:28 -070072 if (socket_client) {
73 run_socket_client();
74 }
75 else {
Szymon Starzycki4662a112013-10-02 17:21:41 -070076 cert_init_crypto();
Szymon Starzycki2a656c32013-09-05 14:26:28 -070077 config_init();
78 load_trigger();
79 commands_init();
80 usb_init();
81 if (!transport_socket_init())
82 exit(1);
Szymon Starzycki27ea99f2013-09-18 16:12:43 -070083 ssh_server_start();
Szymon Starzyckibc849f12013-09-13 15:37:08 -070084 network_discovery_init();
Szymon Starzycki2a656c32013-09-05 14:26:28 -070085 while (1) {
86 sleep(1);
87 }
Colin Crossa3d386e2013-02-06 21:03:34 -080088 }
89 return 0;
90}