1 /* 2 * Copyright (C) 2008 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 <stdlib.h> 18 #include <errno.h> 19 #include <fcntl.h> 20 21 22 #include <netinet/in.h> 23 #include <arpa/inet.h> 24 25 #define LOG_TAG "UsbController" 26 #include <cutils/log.h> 27 28 #include "UsbController.h" 29 30 31 UsbController::UsbController() { 32 } 33 34 UsbController::~UsbController() { 35 } 36 37 int UsbController::startRNDIS() { 38 LOGD("Usb RNDIS start"); 39 return enableRNDIS(true); 40 } 41 42 int UsbController::stopRNDIS() { 43 LOGD("Usb RNDIS stop"); 44 return enableRNDIS(false); 45 } 46 47 int UsbController::enableRNDIS(bool enable) { 48 char value[20]; 49 int fd = open("/sys/class/usb_composite/rndis/enable", O_RDWR); 50 int count = snprintf(value, sizeof(value), "%d\n", (enable ? 1 : 0)); 51 write(fd, value, count); 52 close(fd); 53 return 0; 54 } 55 56 bool UsbController::isRNDISStarted() { 57 char value=0; 58 int fd = open("/sys/class/usb_composite/rndis/enable", O_RDWR); 59 read(fd, &value, 1); 60 close(fd); 61 return (value == '1' ? true : false); 62 } 63