blob: 085cbfa01899fb09579177347fb9968cca90d7e3 [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 Starzyckib015b162013-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 Starzyckie160f812013-07-24 17:08:04 -070024#include "trigger.h"
Szymon Starzyckib015b162013-09-05 14:26:28 -070025#include "socket_client.h"
Colin Crossa3d386e2013-02-06 21:03:34 -080026
27unsigned int debug_level = DEBUG;
28
29void commands_init();
30void usb_init();
31void config_init();
Szymon Starzyckib015b162013-09-05 14:26:28 -070032int transport_socket_init();
Szymon Starzycki65812282013-09-13 15:37:08 -070033int network_discovery_init();
Szymon Starzycki8c3263e2013-09-18 16:12:43 -070034void ssh_server_start();
Colin Crossa3d386e2013-02-06 21:03:34 -080035
36int main(int argc, char **argv)
37{
Szymon Starzyckib015b162013-09-05 14:26:28 -070038 int socket_client = 0;
39 int c;
40
41 klog_init();
42 klog_set_level(6);
43
44 const struct option longopts[] = {
45 {"socket", no_argument, 0, 'S'},
46 {0, 0, 0, 0}
47 };
48
49 while (1) {
50 c = getopt_long(argc, argv, "S", longopts, NULL);
51 /* Alphabetical cases */
52 if (c < 0)
53 break;
54 switch (c) {
55 case 'S':
56 socket_client = 1;
57 break;
58 case '?':
59 return 1;
60 default:
61 return 0;
62 }
63 }
64
Colin Crossa3d386e2013-02-06 21:03:34 -080065 (void)argc;
66 (void)argv;
67
68 klog_init();
69 klog_set_level(6);
70
Szymon Starzyckib015b162013-09-05 14:26:28 -070071 if (socket_client) {
72 run_socket_client();
73 }
74 else {
75 config_init();
76 load_trigger();
77 commands_init();
78 usb_init();
79 if (!transport_socket_init())
80 exit(1);
Szymon Starzycki8c3263e2013-09-18 16:12:43 -070081 ssh_server_start();
Szymon Starzycki65812282013-09-13 15:37:08 -070082 network_discovery_init();
Szymon Starzyckib015b162013-09-05 14:26:28 -070083 while (1) {
84 sleep(1);
85 }
Colin Crossa3d386e2013-02-06 21:03:34 -080086 }
87 return 0;
88}