2013-02-07 13:03:34 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2013 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <cutils/klog.h>
|
2013-09-06 05:26:28 +08:00
|
|
|
#include <getopt.h>
|
|
|
|
#include <stdlib.h>
|
2013-02-07 13:03:34 +08:00
|
|
|
|
|
|
|
#include "debug.h"
|
2013-07-25 08:08:04 +08:00
|
|
|
#include "trigger.h"
|
2013-09-06 05:26:28 +08:00
|
|
|
#include "socket_client.h"
|
2013-10-03 08:21:41 +08:00
|
|
|
#include "secure.h"
|
2013-02-07 13:03:34 +08:00
|
|
|
|
|
|
|
unsigned int debug_level = DEBUG;
|
|
|
|
|
|
|
|
void commands_init();
|
|
|
|
void usb_init();
|
|
|
|
void config_init();
|
2013-09-06 05:26:28 +08:00
|
|
|
int transport_socket_init();
|
2013-09-14 06:37:08 +08:00
|
|
|
int network_discovery_init();
|
2013-09-19 07:12:43 +08:00
|
|
|
void ssh_server_start();
|
2013-02-07 13:03:34 +08:00
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2013-09-06 05:26:28 +08:00
|
|
|
int socket_client = 0;
|
|
|
|
int c;
|
2013-10-04 02:06:45 +08:00
|
|
|
int network = 1;
|
2013-09-06 05:26:28 +08:00
|
|
|
|
|
|
|
klog_init();
|
|
|
|
klog_set_level(6);
|
|
|
|
|
|
|
|
const struct option longopts[] = {
|
|
|
|
{"socket", no_argument, 0, 'S'},
|
2013-10-04 02:06:45 +08:00
|
|
|
{"nonetwork", no_argument, 0, 'n'},
|
2013-09-06 05:26:28 +08:00
|
|
|
{0, 0, 0, 0}
|
|
|
|
};
|
|
|
|
|
|
|
|
while (1) {
|
2013-10-04 02:06:45 +08:00
|
|
|
c = getopt_long(argc, argv, "Sn", longopts, NULL);
|
2013-09-06 05:26:28 +08:00
|
|
|
/* Alphabetical cases */
|
|
|
|
if (c < 0)
|
|
|
|
break;
|
|
|
|
switch (c) {
|
|
|
|
case 'S':
|
|
|
|
socket_client = 1;
|
|
|
|
break;
|
2013-10-04 02:06:45 +08:00
|
|
|
case 'n':
|
|
|
|
network = 0;
|
|
|
|
break;
|
2013-09-06 05:26:28 +08:00
|
|
|
case '?':
|
|
|
|
return 1;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-07 13:03:34 +08:00
|
|
|
(void)argc;
|
|
|
|
(void)argv;
|
|
|
|
|
|
|
|
klog_init();
|
|
|
|
klog_set_level(6);
|
|
|
|
|
2013-09-06 05:26:28 +08:00
|
|
|
if (socket_client) {
|
2013-10-04 02:06:45 +08:00
|
|
|
//TODO: Shouldn't we change current tty into raw mode?
|
2013-09-06 05:26:28 +08:00
|
|
|
run_socket_client();
|
|
|
|
}
|
|
|
|
else {
|
2013-10-03 08:21:41 +08:00
|
|
|
cert_init_crypto();
|
2013-09-06 05:26:28 +08:00
|
|
|
config_init();
|
|
|
|
load_trigger();
|
|
|
|
commands_init();
|
|
|
|
usb_init();
|
2013-10-04 02:06:45 +08:00
|
|
|
|
|
|
|
if (network) {
|
|
|
|
if (!transport_socket_init())
|
|
|
|
exit(1);
|
|
|
|
ssh_server_start();
|
|
|
|
network_discovery_init();
|
|
|
|
}
|
|
|
|
|
2013-09-06 05:26:28 +08:00
|
|
|
while (1) {
|
|
|
|
sleep(1);
|
|
|
|
}
|
2013-02-07 13:03:34 +08:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|