fastbootd.c revision 55b61f4c9bac7f53289c79f22b4ad0ac80ecfb02
1/* 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> 19#include <cutils/klog.h> 20#include <getopt.h> 21#include <stdlib.h> 22 23#include "debug.h" 24#include "trigger.h" 25#include "socket_client.h" 26#include "secure.h" 27 28unsigned int debug_level = DEBUG; 29 30void commands_init(); 31void usb_init(); 32void config_init(); 33int transport_socket_init(); 34int network_discovery_init(); 35void ssh_server_start(); 36 37int main(int argc, char **argv) 38{ 39 int socket_client = 0; 40 int c; 41 int network = 1; 42 43 klog_init(); 44 klog_set_level(6); 45 46 const struct option longopts[] = { 47 {"socket", no_argument, 0, 'S'}, 48 {"nonetwork", no_argument, 0, 'n'}, 49 {0, 0, 0, 0} 50 }; 51 52 while (1) { 53 c = getopt_long(argc, argv, "Sn", longopts, NULL); 54 /* Alphabetical cases */ 55 if (c < 0) 56 break; 57 switch (c) { 58 case 'S': 59 socket_client = 1; 60 break; 61 case 'n': 62 network = 0; 63 break; 64 case '?': 65 return 1; 66 default: 67 return 0; 68 } 69 } 70 71 (void)argc; 72 (void)argv; 73 74 klog_init(); 75 klog_set_level(6); 76 77 if (socket_client) { 78 //TODO: Shouldn't we change current tty into raw mode? 79 run_socket_client(); 80 } 81 else { 82 cert_init_crypto(); 83 config_init(); 84 load_trigger(); 85 commands_init(); 86 usb_init(); 87 88 if (network) { 89 if (!transport_socket_init()) 90 exit(1); 91 ssh_server_start(); 92 network_discovery_init(); 93 } 94 95 while (1) { 96 sleep(1); 97 } 98 } 99 return 0; 100} 101